GithubHelp home page GithubHelp logo

ckeditor-wordcount-plugin's Introduction

Hi there 👋

w8tcha's GitHub stats

Top Langs

Readme Card

ckeditor-wordcount-plugin's People

Contributors

aldatsa avatar andreasen avatar anthropos9 avatar beltofte avatar bhamine avatar bigs21 avatar crisp-tweakers avatar cxrxexo avatar davidemontorio avatar dkltd avatar e404r avatar fodordavid avatar intropedro avatar joelposti avatar julesachiel avatar leobaillard avatar maxhou00 avatar mesutcakir avatar moshfeu avatar murashki avatar mushroom7 avatar nmpetkov avatar psyafter avatar roukmoute avatar sektor-sumy avatar sweoggy avatar vasiliyrepin avatar vstene avatar w8tcha avatar walteann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ckeditor-wordcount-plugin's Issues

Count characters but not spaces

I would like to NOT count spaces, but everything else in the character count.

How could I acheive this?

Thanks in advance.

Error if empty string

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.

Character counter ignoring new HTML tag character counts until subsequent edit

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.

CKEditor character count with table and list

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!

IE11, Chrome and Safari issue

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.

Installed WordCount plugin is not working

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?

Plugin doesn't appear to work with Autogrow plugin

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.

Avoid adding zero-width space between <p> on saving

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 ?

CKEditor-WordCount-Plugin does not with 4.2.2

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'
};

Conflict with Autogrow plugin

Apparently we have to choose between autogrow and wordcount plug-ins. They do not work toghether in 4.1.1 version.

Bugs found from WordCount Plugin, urgent help!

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!

  1. 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)

  2. 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)

  3. 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.

wordcount plugin not working for ckeEditor.

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.

How to set up lang to plugin?

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?

Word Limit is not working

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.

schermata 2013-10-11 alle 14 34 06

I tested it with Safari 6.0.5 and Firefox 24.0 on Mac Os X 10.8.5

How to set character limit

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 + '&nbsp;%charCount%';
    }

    if (config.showCharCount && config.showWordCount) {
        defaultFormat += ',&nbsp;';
    }

    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(/(&nbsp;)/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') + '"' + '>&nbsp;</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! ;))

prevent cleaning Text in WordCount Limited

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

Bug for word count plugin

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!

count fired on keypress occurs before changes

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.

IE 9 issue...or is it me?

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!

CKEditor word count with table and list

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.

Thanks!
ckeditor_wordcount_ul
ckeditor_wordcount_table

Brazilian Portuguese Translation

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'
     });

char/word limit not working

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

IE 9 Plug in does not count..

In IE 9 the plug in does not keep count of characters and words.

"Characters: 0 and Words: 0" shows up in the status bar but it does not change.

wordcount-count

Char count limit fail when type quickly

Hi

I have implement the wordcount plugin as defined in demo but it fails to limit character count or word count when i typed quickly in editor
For reference pls check attached image
charcount

ie9 Throws getdata is null or not an object. plugin.js line 36

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.

bug when enterMode : 2

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;
    }

Will not work in rails?

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"

Character counter seems to be one action behind

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.

Word limit only works if character count is on

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.

Small typo - bug

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.

Language translation pt-BR does not work in wordcount

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!

Word Counts on FireFox

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?

Wrong char/word count if config.fullPage is set to true

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;
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.