CKEditor Word Count Plugin
Finally – a Word Count plugin for CKEditor. After much searching, and finding nothing, I developed a quick and basic word count plugin for CKEditor.
Tested in Internet Explorer 8, Firefox 3.5, Google Chrome 4, Safari 4
Installation:
- Download the CKEditor Word Count Plugin
- Upload the /wordcount folder to your /ckeditor/plugins folder
- Edit your CKEditor configuration file (usually /ckeditor/config.js):
-
CKEDITOR.editorConfig = function(config) {
-
config.extraPlugins = ‘wordcount’;
-
};
-
- For your CKEditor instance, use the following HTML markup (‘content’ can be any element name you wish, so long as the hidden field has its element name in the format ‘elementWordCount’)
-
<label for="content">Content</label>
-
<textarea class="ckeditor" name="content"></textarea>
-
<input name="contentWordCount" type="hidden" value="250" />
Word Limit: If you don’t want to display a word limit, don’t include the hidden input tag, or set its value to zero.
-
- Download jQuery and include it on your web page, between the head tags:
-
<script src="jquery/jquery.1.4.min.js" type="text/javascript"><!–mce:0–></script>
-
Known Bugs / Issues:
- The word count can be a few words out – this appears to happen between paragraph tags.
- Pasting large chunks of copy that exceeds the word limit sometimes causes issues, whereby the additional content isn’t always removed.
- I’ve only tested this using the HTML markup specified above (it should work in other methods – please let me know if it does / doesn’t)
- Multiple instances of the CKEditor on a single page may cause issues with word counts.
I’m hoping to keep this plugin updated and publish some fixes within the next few weeks – so if there are any other issues, please leave a comment to let me know.
Comment #1
I had an issue with destroying CKEdtitor instances — sometimes it would raise an error:
i.contentWindow is null
which, corresponds to ckeditor/_source/core/dom/element.js:1331:
return $ && new CKEDITOR.dom.document( $.contentWindow.document );
It turned out to be triggered by the Word Count plugin’s use of “setTimeout” and “getData”. The editor had been destroyed before the timeout triggered to run getData.
I hope this helps someone else!