Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CKEditor - Limit characters on more editors in one page

I'm developing a web based ERP and I need some help.

As text editor, I choose CKEditor, works great and do everything I need. Well...not exactly everything...

I've added a plugin name "wordcount", that count words or characters and sets the limit.

The problem is that I've more CKeditors on one page, and I need to set different limits for each one. As you see, the plugin is setting the same limit for both editors:

enter image description here

Parameters are passed through config.js:

config.wordcount = {

// Whether or not you want to show the Paragraphs Count
showParagraphs: false,

// Whether or not you want to show the Word Count
showWordCount: false,

// Whether or not you want to show the Char Count
showCharCount: true,

// Whether or not you want to count Spaces as Chars
countSpacesAsChars: true,

// Whether or not to include Html chars in the Char Count
countHTML: false,

// Maximum allowed Word Count, -1 is default for unlimited
maxWordCount: 400,

// Maximum allowed Char Count, -1 is default for unlimited
maxCharCount: 400};

Do you know some way to do this? Also with another plugin or "manually".

Thanks in advance!

like image 297
abarts_original Avatar asked Dec 26 '15 17:12

abarts_original


1 Answers

I realized this as follows: need to add attrs data to textArea tags with maxWord and maxChar, initialize CKeditor

window.InitializeCkeditor = {
  init: function() {
    var element, elements, i, results;
    elements = CKEDITOR.document.find('.js-ckeditor'); // your textArea
    i = 0;
    results = [];
     while (element = elements.getItem(i++)) {
       CKEDITOR.replace(element, {
         toolbar: 'mini', // your toolbar 
         height: 200
       });
       results.push(CKEDITOR.on('instanceCreated', function(event) {
         var editor, element;
         editor = event.editor;
         element = editor.element;
         return editor.on('configLoaded', function() {
           return editor.config.wordcount = {
             showWordCount: true,
             maxWordCount: element.data('word-max')
           };
        });
      }));
    }
    return results;
  }
};
like image 191
Vladimir Avatar answered Sep 27 '22 21:09

Vladimir