I'm using the latest version of Telerik Editor in my website and there is a problem with Editor word count.
I wrote a document in MS word and did a word count and it shows
words 280,
Characters ( no spaces) 1950
Characters ( with spaces) 2229
I did a select all and copied the text as plain text in Telerik Editor and it gave me
Words: 280 Characters: 2237 .
I have attached some screen shots also.
One of the screen shot is from the demo on the website ( just trying to make it sure that it's not the version problem )
Really appreciate your help.
Roomi
I wrote a document in MS word and did a word count and it shows
words 280,
Characters ( no spaces) 1950
Characters ( with spaces) 2229
I did a select all and copied the text as plain text in Telerik Editor and it gave me
Words: 280 Characters: 2237 .
I have attached some screen shots also.
One of the screen shot is from the demo on the website ( just trying to make it sure that it's not the version problem )
var editorList = new Object();
var editorLengthArray = [20, 30];
var counter = 0;
AlreadyAlerted = false;
function isAlphaNumericKey(keyCode) {
if ((keyCode > 47 && keyCode <
58
) || (keyCode > 64 && keyCode <
91
)) {
return true;
}
return false;
}
function LimitCharacters(editor) {
var
style
=
editor
.get_contentArea().style;
style.backgroundImage
=
"none"
;
style.backgroundColor
=
"white"
;
editorList[editor.get_id()] = editorLengthArray[counter];
counter++;
editor.attachEventHandler("onkeydown", function(e) {
var
content
=
editor
.get_text().trim(); //returns the editor's content as plain text
var
words
=
0
;
if (content) {
var punctRegX = /[!\.?;,:&_\-\-\{\}\[\]\(\)~#'"]/g;
var
contentcontent
= content.replace(punctRegX, "");
var trimRegX = /(^\s+)|(\s+$)/g;
contentcontent
= content.replace(trimRegX, "");
if (content) {
splitRegX = /\s+/;
var
array
=
content
.split(splitRegX);
words
=
array
.length;
}
}
var counter = $get("counter");
counter.innerHTML
=
"Words: "
+ words + " Characters: " + content.length + " <b>(Maximum character length is 2500)</
b
>";
e = (e == null) ? window.event : e;
if (isAlphaNumericKey(e.keyCode)) {
var maxTextLength = 2500;
textLength = editor.get_text().length;
if (textLength >= maxTextLength) {
alert('You have exceeded the maximun character count of 2500.');
//alert('1');
AlreadyAlerted = true;
e.returnValue = false;
}
}
});
}
function CalculateLength(editor, value) {
var textLength = editor.get_text().length;
var clipboardLength = value.length;
textLength += clipboardLength;
return textLength;
}
function ClientExecuteCommand(editor, args) {
var commandName = args.get_commandName();
var value = args.get_value();
if (commandName == "PastePlainText" || commandName == "Paste") {
var textLength = CalculateLength(editor, value);
if (textLength >= 2500) {
if (!AlreadyAlerted) {
alert("You have exceeded the maximun character count of 2500.");
}
AlreadyAlerted = false;
args.set_cancel(true);
}
}
}
<
telerik:RadEditor
ID
=
"RadEditor1"
runat
=
"server"
SkinID
=
""
Width
=
"100%"
SpellCheckSettings-AllowAddCustom
=
"false"
ToolsFile
=
"../TelerikRichEditControl/ToolsFile.xml"
OnClientPasteHtml
=
"ClientExecuteCommand"
Skin
=
"Office2007"
Height
=
"300"
EditModes
=
"Design"
OnClientLoad
=
"LimitCharacters"
>
</
telerik:RadEditor
><
span
id
=
"counter"
>
Really appreciate your help.
Roomi