w8tcha / ckeditor-wordcount-plugin Goto Github PK
View Code? Open in Web Editor NEWWordCount Plugin for CKEditor v4
License: MIT License
WordCount Plugin for CKEditor v4
License: MIT License
Dear,
we are using CKEditor 3.6.3 version and trying to include wordcount plugin for the same. when we try to open the control, we are encountered with below error
SCRIPT5007: Unable to get value of the property 'CharCount': object is null or undefined
plugin.js?t=C3HA5RM, line 35 character 13
Please let us know if the Ckeeditor version we are using (3.6.3 ) is compatible or not ?
From which versin we can succesfully implement word/char count plugin ?
if compatible please suggest the fix for this issue ?
Thanks in advance,
Sudheendra B.
If the data returned by the getData() method is an empty string, the word count is wrong.
Line 31, instead of :
if (editor.getData() != undefined)
You should probably do:
if (editor.getData())
That would prevent some JS errors (which I have) due to the fact that both tmp.textContent and tmp.innerText return "" or undefined.
When adding wordcount folder to plugins directory in assets folder and adding config lines to ckeditor/config.js, editor does not show on page and console shows "Uncaught TypeError: Cannot read property 'WordCount' of undefined"
when in this mode, and if no words are counted the plugin throws an error on line 68
wordCount = strip(editor.getData()).trim().split(/\s+/).length; is undefined when going into source mode.
Test case, html is a single image, click on source and the strip function returns undefined.
I fixed it by adding the following but i'm sure there's a more elegant way
function strip(html) {
var tmp = document.createElement("div");
tmp.innerHTML = html;
if (tmp.textContent == '' && typeof tmp.innerText == 'undefined'){
return '0';
}
return tmp.textContent || tmp.innerText;
}
Hi
I recently upgraded to CKEditor 4.0 and look forward to install the word count plugin. In the demo page for plugin, the count seems to work fine for paragraphs, however when I add a table or a list it increases the word count by 2. Please find the screen shots attached. I could not find any related issue and curious if this is the default behavior.
I'm trying to setup pt-BR lang to wordcount plugin but with no success. I don't found this info on the DOCs. How to do?
Hello ,
I am trying to make wordcount work but it does not start working with version 4.2.2.
I tried with version 4.1.1 , I can see wordcount but I need version 4.2.2 to work with as I have all config for my application inside it.
here is my config added to config.js of CKEditor
config.extraPlugins = 'wordcount,autosave';
config.wordcount = {
// Whether or not you want to show the Word Count
showWordCount: true,
// Whether or not you want to show the Char Count
showCharCount: true,
// Option to limit the characters in the Editor
charLimit: 'unlimited',
// Whether or not to include Html chars in the Char Count
countHTML: false,
// Option to limit the words in the Editor
wordLimit: 'unlimited'
};
Hi
I apologize but for issue no. 45 I forgot to mention about character count and that's why I am opening a new issue. The character count as well is incorrect in the demo page for table and list elements.
I figured from the plugin.js line no. 105, that all the occurrences of are not removed from the text.replace(" ", "")
. As for the fix, I have changed the code to text.replace(/ /g,"")
which works for me. Please verify.
Thanks!
I can't get the wordcount plugin to work with the autogrow plugin. With both plugins enabled the wordcount doesn't show up (don't appear to be any errors either). As soon as I disable autogrow the wordcount appears.
New ckEditor 4.1.1 (full) install with no plugins except for the above two.
Can this be used with the inline mode of CKEDITOR?
Hi,
I tested the demo page http://w8tcha.github.io/CKEditor-WordCount-Plugin/ and once it loads if I copy/paste text greater than 20 words it does not truncate the text. It works once you clear the text out and copy/paste it again.
It works fine in Firefox but this issue occurs in IE11, Chrome and Safari. Would appreciate it if you can confirm this issue and if it could be fixed.
Hi!
I have this configuration in my config.js:
CKEDITOR.editorConfig = function( config ) {
config.language = 'pt-br';
config.extraPlugins = 'wordcount';
config.toolbar = [
{ name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source', '-', 'Preview'] },
{ name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
{ name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll'] },
'/',
{ name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
{ name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl' ] },
{ name: 'links', items: [ 'Link', 'Unlink', 'Anchor' ] },
{ name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] },
{ name: 'colors', items: [ 'TextColor', 'BGColor' ] },
{ name: 'others', items: [ '-' ] }
];
config.wordcount = {
// Whether or not you want to show the Word Count
showWordCount: true,
// Whether or not you want to show the Char Count
showCharCount: true,
// Whether or not to include Html chars in the Char Count
countHTML: false
};
};
The import find both pt-br.js:
[200]: /statics/lib/ckeditor-releases/lang/pt-br.js
[200]: /statics/lib/ckeditor-releases/plugins/wordcount/lang/pt-BR.js
The first import is the translation of the ck-editor and the second is the wordcount plugin.
But the bar remains in English.
Can help? Thank you!
When you reach the limit, this still exceeding this limit characters
I would like to NOT count spaces, but everything else in the character count.
How could I acheive this?
Thanks in advance.
There seems to be a bug for this plug-in: when copying and pasting text directly into the text box, the word count would not work unless another key is pressed.
Would we be able to fix that? Thanks!
Hello
Thanks for this great Plugin but it is dont work with the BBCode PlugIn (http://ckeditor.com/addon/bbcode). It comes always HTML Output if both Plugins activate.
Can you please fix it or me say what i can do that it go.
I just tried this plugin both on my local and on the demo page.
If you type more words than the limit (which is 20), the plugin breaks up.
In firebug console appears a 'too much recursion' (ckeditor.js (row 315)) error message
It becomes slower and slower and you're not able to write anymore.
I tested it with Safari 6.0.5 and Firefox 24.0 on Mac Os X 10.8.5
How can I change charLimit in-page?
For example:
CKEDITOR.replace('ckeditor', {
toolbar: cktb
});
Subscript and Superscript adding an additional word to the count
The strip function in this plugin seems questionable to me... in particular the following:
if (tmp.textContent == '' && typeof tmp.innerText == 'undefined') {
return '0';
}
return tmp.textContent || tmp.innerText;
If the editor's content is empty then the if clause will be true and thus the string '0' will be returned which should have a wordcount of 1 despite the editor being empty and having 0 words in it. It seems to me this whole thing should be replaced by:
return tmp.textContent || tmp.innerText || '';
so FF returns '' if it's empty as other browsers do?
In a nutshell we're trying to deal with getting the right property, but have issues when '' is retrieved as it's falsy too just like undefined is so we need a 'default' return value of '' for when the first property is what we want, but is also falsy and the second is undefined.
Am I wrong?
It'd be nice to have an option to disable HTML stripping for those who wish to count the HTML characters in the character count.
Hi, we found 3 problems for the word count plugin. Would you please help to check whether it can be fixed or when it can be fixed? Thanks a lot for your kindly help!
After we set word limit, when users used "Ctrl + v" to paste text which will exceed the word limit, no error message will be prompt. (the text will not be pasted in editor finally and this result is fine)
We found that the word count is not worked sometimes. For example, we input the space but char count will not update his change. (it will work after some actions)
We try to paste words that will exceed word limit by right-click the mouse for selecting "paste". We found that it will success finally that means word limit cannot function. And we also cannot edit its content after this paste.
The additional html/head/body results in wrong count both for words and chars.
I've fixed it here by extracting the body content with search and substring, but there may be better ways of fixing it.
var i = text.search(new RegExp("<body>", "i"));
if (i != -1) {
var j = text.search(new RegExp("</body>", "i"));
text = text.substring(i+6, j);
}
...
if (normalizedText.trim().length) {
normalizedText = strip(normalizedText);
wordCount = normalizedText.split(/\s+/).length;
}
I have seen this bug listed before as resolved however I appear to be having the issue with Chrome and Firefox. My config is as follows:
config.js
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.extraPlugins = 'wordcount';
config.wordcount = {
// Whether or not you want to show the Word Count
showWordCount: true,
wordLimit: 5,
// Whether or not you want to show the Char Count
showCharCount: false,
countHTML: false
};
};
I am using an auto-build from the ckEditor website. (which didn't work) so I downloaded the latest from git, and still no go. Any help is greatly appreciated.
Thanks
Expected:
The CK Editor should not allow to type text more than the character count limit.
Environment:
Windows 7, Browser: IE 9
CK Editor 4.4 version.
Hello,
Recently I have downloaded WordCount-Plugin from http://download.ckeditor.com/wordcount/releases/wordcount_1.04.zip and installed CKEditor-WordCount-Plugin, but it is not working. My CKEditor installation is ok and it is working fine. In my drupal site "My CKEditor-WordCount-Plugin" directory structure is
sites/all/libraries/ckeditor/plugins/wordcount
and wordcount directory contains 2 dirs; named css & lang and 1 file named plugin.js
I have configured config.js as under
CKEDITOR.editorConfig = function( config ) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
config.extraPlugins = 'wordcount';
config.wordcount = {
// Whether or not you want to show the Word Count
showWordCount: true,
// Whether or not you want to show the Char Count
showCharCount: true
};
};
But nothing is showing in the editor. Any idea where is my mistake?
When saving the text from ckeditor, it seems that wordcount plugin add a zero-width space between p tags.
I pop up the content of this text with a javascript function which returns me a Unexpected token ILLEGAL since I installed wordcount, and the problem comes from the zero-width space.
My previous configuration was:
CKEDITOR.editorConfig = function( config ) {
config.forcePasteAsPlainText = true;
config.entities = false;
config.basicEntities = false;
config.entities_greek = false;
config.entities_latin = false;
config.allowedContent = true;
};
CKEDITOR.on( 'instanceReady', function( ev )
{
ev.editor.dataProcessor.writer.setRules( 'p',
{
indent : false,
breakBeforeOpen : false,
breakAfterOpen : false,
breakBeforeClose : false,
breakAfterClose : false
});
});
Which avoided the problem, but by adding the wordcount plugin, it seems that the setRules on p is not a priority in config.js anymore?
Is there any way to avoid this insertion of zero-width space ? to be able to send the text in a javascript function without raising an unexpected token illegal ?
Need to use the limit functionality, but noticed its commented out....
to replicate fill in "lol foo bar" which is 9 letters and 2 spaces, 11 chars total.
Counter will indicate 10
I thought you might like to add Brazilian Portuguese too:
CKEDITOR.plugins.setLang('wordcount', 'pt-BR', {
WordCount: 'Contagem de palavras:',
CharCount: 'Contagem de caracteres:',
limit: 'Limit:',
title: 'Estatísticas'
});
Getting this error in Chrome and unsure how to resolve?
Uncaught TypeError: Cannot read property 'langEntries' of null
Hi
I used wordCount Plugin for Ckeditor and I defined CharLimit:200 for it.
It worked correctly but problem is that when I type 200th character it clean all text that I typed, and I should start typing text from begining
is there any way that when I type 200th character it prevent typing more character not clean it Like when we define MaxLenght for TextBox in Asp.net
Best regards
Neda
Any idea where this might come from?
(Using latest chrome, editor 4.1 through the ckeditorr drupal module...)
Seems the character counter is counting based on the previous state of the content of the RTE, not the current state.
For example I'm typing in the word "testing" into an empty instance, one letter at a time. After the "t", it shows zero - after "te", one - up to six for the seven-letter word "testing". If I then select-all, the counter shows seven.
Deleting the selected text, the counter still shows seven, until typing again whereupon the counter returns to zero, despite there being a character present.
Paste option in CKEditor not working properly. Please check the history of this defect below link,
https://dev.ckeditor.com/ticket/12051
From the above ticket we came to know this issue is because of the word count plugin.
Please verify and update the solution for it.
I'm trying:
config.wordcount = {
showWordCount: true,
showCharCount: false,
wordLimit: 400
};
...but although the editor shows "(Limit: 400)", it doesn't actually stop you going over it. It also sometimes incorrectly shows in red.
The only way I've found to get it working is to put showChartCount: true.
In the update counter function i.e. function updateCounter(editor)
Shouldn't
if (editor.getData()) {
var text = editor.getData().replace(/(\r\n|\n|\r)/gm, "").replace(/( )/g, " ");
be
if (editor.getData()) {
var text = editor.getData().replace(/(\r\n|\n|\r)/gm, " ").replace(/( )/g, " ");
There should be a space in the first replace as this makes the word count inaccurate if there are new lines in the text as it joins two words together after the replace.
When pressing a key in the editor, the "key" event fires prior to the text being updated by the corresponding action. This means that the wordcount update is always based on the number of words/characters present before the key was pressed, rather than after.
In the case of simply typing in text, this manifests as a slightly jarring lag, where a new word is not counted until its second character is typed (or some other key event occurs).
However, if a large quantity of text is deleted, (e.g. by selecting with the mouse, and using the delete or backspace keys), the word count can be left drastically wrong, even after focus is lost by the editor.
Hi, I just downloaded CKEditor 4.3.2 yesterday and I am trying to use this CKEditor-WordCount-Plugin. When I browse my web application (from VisualStudio 2010) using IE 9 as my browser, I get a runtime error where plugin.js is attempting to use the .innerHTML property to display the word/character counts and/or limits. However, when I view your demo for this plugin in IE 9 ( http://w8tcha.github.io/CKEditor-WordCount-Plugin/ ), I do not get any such errors. So what am I doing wrong or what am I missing? Thanks!
When ckeditor loaded with wordcount plugin in IE9 and IE10 happening something wrong, and it loses focus of textarea window while typing: http://screencast.com/t/Sp5v2ipkPjN
Configured to show word and char count with limit.
f you have "countHTML" set to true, the character counter does not adjust when applying a style to highlighted text, until you make an normal edit to the total text in the editor.
i.e. if you have the text "testing" in there, you'll see 7 - highlight and bold it, it still says 7, where it should read 24 (17 extra for open/close "strong" tags). If you then type in a new character (or backspace over one) and the counter will jump to the total including the previously unaccounted-for open/close "strong" tags.
Apparently we have to choose between autogrow and wordcount plug-ins. They do not work toghether in 4.1.1 version.
When pressing backspace key the number of words in info increases instead of decrease.
http://screencast.com/t/AsYs1y04MhP
Is it possible to have a minimum required word count?
Hi!
in the config, file, you say that I can set a character limit, how can I? At the moment, I only have this:
/**
CKEDITOR.plugins.add('wordcount', {
lang: ['de', 'en'],
init: function (editor) {
//Here can set the char limit
var defaultLimit = '50';
var defaultFormat = '';
var limit = defaultLimit;
var intervalId;
var lastWordCount = 0;
var lastCharCount = 0;
var limitReachedNotified = true;
var limitRestoredNotified = false;
// Default Config
var defaultConfig = {
showWordCount: true,
showCharCount: true
};
// Get Config & Lang
var config = CKEDITOR.tools.extend(defaultConfig, editor.config.wordcount || {}, true);
if (config.showCharCount) {
defaultFormat += editor.lang.wordcount.CharCount + ' %charCount%';
}
if (config.showCharCount && config.showWordCount) {
defaultFormat += ', ';
}
if (config.showWordCount) {
defaultFormat += editor.lang.wordcount.WordCount + ' %wordCount%';
}
defaultFormat += '</span>';
var format = defaultFormat;
CKEDITOR.document.appendStyleSheet(this.path + 'css/wordcount.css');
function counterId(editor) {
return 'cke_wordcount_' + editor.name;
}
function counterElement(editor) {
return document.getElementById(counterId(editor));
}
function strip(html) {
var tmp = document.createElement("div");
tmp.innerHTML = html;
if (tmp.textContent == '' && typeof tmp.innerText == 'undefined') {
return '0';
}
return tmp.textContent || tmp.innerText;
}
function updateCounter(editor) {
var wordCount = 0;
var charCount = 0;
if (editor.getData()) {
var text = editor.getData().replace(/(\r\n|\n|\r)/gm, "").replace(/( )/g, " ");
if (config.showWordCount) {
wordCount = strip(text).trim().split(/\s+/).length;
}
if (config.showCharCount) {
charCount = strip(text).trim().length;
}
}
var html = format.replace('%wordCount%', wordCount).replace('%charCount%', charCount);
counterElement(editor).innerHTML = html;
if (charCount == lastCharCount) {
return true;
} else {
lastWordCount = wordCount;
lastCharCount = charCount;
}
if (wordCount > limit) {
limitReached(editor, limitReachedNotified);
} else if (!limitRestoredNotified && wordCount < limit) {
limitRestored(editor);
}
return true;
}
function limitReached(editor, notify) {
limitReachedNotified = true;
limitRestoredNotified = false;
editor.execCommand('undo');
if (!notify) {
editor.fire('limitReached', {}, editor);
}
// lock editor
editor.config.Locked = 1;
editor.fire("change");
}
function limitRestored(editor) {
limitRestoredNotified = true;
limitReachedNotified = false;
editor.config.Locked = 0;
}
editor.on('uiSpace', function(event) {
if (event.data.space == 'bottom') {
event.data.html += '<div id="' + counterId(event.editor) + '" class="cke_wordcount" style=""' + ' title="' + CKEDITOR.tools.htmlEncode('Words Counter') + '"' + '> </div>';
}
}, editor, null, 100);
editor.on('instanceReady', function() {
if (editor.config.wordcount_limit != undefined) {
limit = editor.config.wordcount_limit;
}
if (editor.config.wordcount_format != undefined) {
format = editor.config.wordcount_format;
}
}, editor, null, 100);
editor.on('dataReady', function(event) {
var count = event.editor.getData().length;
if (count > limit) {
limitReached(editor);
}
updateCounter(event.editor);
}, editor, null, 100);
editor.on('key', function (event) {
updateCounter(event.editor);
}, editor, null, 100);
editor.on('afterPaste', function (event) {
updateCounter(event.editor);
}, editor, null, 100);
/* editor.on('change', function (event) {
updateCounter(event.editor);
}, editor, null, 100);*/
editor.on('focus', function(event) {
editorHasFocus = true;
intervalId = window.setInterval(function(editor) {
updateCounter(editor);
}, 100, event.editor);
}, editor, null, 100);
editor.on('blur', function() {
editorHasFocus = false;
if (intervalId) clearInterval(intervalId);
}, editor, null, 100);
}
});
Please help me! ;))
ckeditor ver 4.0.1
wordcount 1.01
Limited to ie9 as far as I can tell.
This error ceases further operation of Wordcount and count stays at 0.
I noted the following regarding plugin.js
Lines 92-94 refer to a "change" event that never fires because it is not included in ckEditor. At least as far as I can tell. it certainly does not fire when the content changes which would be the desired function.
Lines 96-101 update the count on focus which is the call that is failing in ie. I'm not sure why, it just causes the error when it fires.
To resolve the issue I commented out lines 92-101 and added the following to capture the keypress event to update the count:
editor.on('key', function (event) {
updateCounter(event.editor)
}, editor, null, 100);
This fix appears to work in all browsers I tested.ie, Chrome, FF, Safari.
Question: how do you capture WordCount data outside CKEditor?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.