5

我正在开发一个基于网络的 ERP,我需要一些帮助。

作为文本编辑器,我选择 CKEditor,效果很好,可以做我需要的一切。嗯……不完全是……

我添加了一个插件名称“wordcount”,用于计算单词或字符并设置限制。

问题是我在一页上有更多的 CKeditor,我需要为每个页面设置不同的限制。如您所见,插件为两个编辑器设置了相同的限制:

在此处输入图像描述

参数通过 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};

你知道有什么方法可以做到这一点吗?也可以使用另一个插件或“手动”。

提前致谢!

4

3 回答 3

4

我实现如下:需要用maxWord和maxChar将attrs数据添加到textArea标签,初始化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;
  }
};
于 2017-04-21T12:51:01.670 回答
3

您可以指定具体的配置,当CKEDITOR.replace()在您的视图页面调用时,您指定的配置会与中的相应配置重叠CKEDITOR config.js

var wordCountConf1 = {
    showParagraphs: false,
    showWordCount: true,
    showCharCount: true,
    countSpacesAsChars: false,
    countHTML: false,
    maxWordCount: -1,
    maxCharCount: 2000}
}

var wordCountConf2 = {
    showParagraphs: false,
    showWordCount: true,
    showCharCount: true,
    countSpacesAsChars: false,
    countHTML: false,
    maxWordCount: -1,
    maxCharCount: 5000}
}

CKEDITOR.replace('editor1', {wordcount: wordCountConf1});
CKEDITOR.replace('editor2', {wordcount: wordCountConf2});
于 2016-05-20T03:31:23.830 回答
0
        <script>
        CKEDITOR.replace('comments',
        {toolbar:[
            { name: 'document', groups: [ 'mode', 'document', 'doctools' ], items: [ 'Source' ] },
            { name: 'clipboard', items: [ 'Undo', 'Redo', '-', 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord' ] },
            { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Strike', '-', 'TextColor' ] },
            { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blocks' ] },
            { name: 'links', items: [ 'Link', 'Unlink' ] },
            { name: 'insert', items: [ 'Image', 'Table', 'SpecialChar' ] },
            { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Scayt' ] }
        ],
        height:400,
        resize_enabled:true,
        wordcount: {
            showParagraphs: false,
            showWordCount: true,
            showCharCount: true,
            countSpacesAsChars: false,
            countHTML: false,
            maxWordCount: -1,
            maxCharCount: 4000}
        });
        </script>
于 2016-05-20T03:13:48.457 回答