Примените CKEditor Wordcount только к определенному полю - PullRequest
0 голосов
/ 11 января 2019

Как применить настройку 'maxWordCount: 50' только к полю textarea с "простым" классом? Это возможно? Если нет, можно ли его применить ко всем полям текстовой области с полями имен [141]? В настоящее время ко всем полям автоматически применяется параметр maxWordCount. Спасибо!

CKEDITOR.config.extraPlugins = 'media,autolink,wordcount,notification';
CKEDITOR.config.allowedContent = true;
CKEDITOR.config.skin = 'moonocolor';
CKEDITOR.config.scayt_autoStartup = true;
CKEDITOR.config.wordcount = {
  maxWordCount: 50
};

function ckeditor(elems) {
  $(elems).each(function(i, elem) {
    var height = '200px';
    if ($(elem).hasClass('short')) {
      height = '75px';
    }

    if ($(elem).hasClass('simple')) {
      CKEDITOR.replace(elem, {
        toolbar: [
          { name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'Undo', 'Redo' ] },
          { name: 'editing', items: [ 'Scayt' ] },
          { name: 'links', items: [ 'Link', 'Unlink', 'Autolink', 'Media', 'Source'] },
          { name: 'insert', items: [ 'Table', 'SpecialChar', 'Templates', 'Maximize'] },
          { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Strike', 'Underline', 'RemoveFormat' ] },
          { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent' ] }
        ],
        height: height
      });

    }
    else if($(elem).hasClass('nofontstyling')) {

      CKEDITOR.replace(elem, {
        toolbar: [
          { name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
          { name: 'editing', items: [ 'Scayt' ] },
          { name: 'links', items: [ 'Link', 'Unlink', 'Autolink' ] },
          { name: 'insert', items: [ 'Media', 'Table', 'Anchor', 'SpecialChar', 'Templates', 'Maximize', 'Source' ] },
          '/',
          { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Strike', 'Underline', '-', 'CopyFormatting', 'RemoveFormat' ] },
          { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] }
        ],
        height: height
      });

    }
    else {
      CKEDITOR.replace(elem, {
        height: height
      });
    }
  });
}



$(document).ready(function() {
  ckeditor($('textarea.editor'));
});
<textarea name="fields[141]" id="fields[141]" class="simple editor">&lt;p&gt; content goes here  &lt;/p&gt;</textarea>
<textarea name="fields[30]" id="fields[30]" class=" editor"></textarea>

1 Ответ

0 голосов
/ 16 января 2019

это должно работать ...

 CKEDITOR.config.extraPlugins = 'media,autolink,wordcount,notification';
CKEDITOR.config.allowedContent = true;
CKEDITOR.config.skin = 'moonocolor';
CKEDITOR.config.scayt_autoStartup = true;

function ckeditor(elems) {
  $(elems).each(function(i, elem) {
    var height = '200px';
    if ($(elem).hasClass('short')) {
      height = '75px';
    }

    if ($(elem).hasClass('simple')) {
      CKEDITOR.replace(elem, {
        toolbar: [
          { name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', 'Undo', 'Redo' ] },
          { name: 'editing', items: [ 'Scayt' ] },
          { name: 'links', items: [ 'Link', 'Unlink', 'Autolink', 'Media', 'Source'] },
          { name: 'insert', items: [ 'Table', 'SpecialChar', 'Templates', 'Maximize'] },
          { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Strike', 'Underline', 'RemoveFormat' ] },
          { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent' ] }
        ],
        height: height,
         wordcount:
                    { maxWordCount: 50}
      });

    }
    else if($(elem).hasClass('nofontstyling')) {

      CKEDITOR.replace(elem, {
        toolbar: [
          { name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
          { name: 'editing', items: [ 'Scayt' ] },
          { name: 'links', items: [ 'Link', 'Unlink', 'Autolink' ] },
          { name: 'insert', items: [ 'Media', 'Table', 'Anchor', 'SpecialChar', 'Templates', 'Maximize', 'Source' ] },
          '/',
          { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Strike', 'Underline', '-', 'CopyFormatting', 'RemoveFormat' ] },
          { name: 'paragraph', items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] }
        ],
        height: height
      });

    }
    else {
      CKEDITOR.replace(elem, {
        height: height
      });
    }
  });
}



$(document).ready(function() {
  ckeditor($('textarea.editor'));
});
...