CKEditor - 在一个页面中限制更多编辑器上的字符

时间:2015-12-26 17:05:23

标签: javascript ckeditor ckeditor4.x ckeditor-wordcount

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

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

我已经添加了一个插件名称" wordcount",它会对单词或字符进行计数并设置限制。

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

enter image description here

参数通过config.js传递:

$qry = "SELECT COUNT(*) cnt,
                        AVG(level) avg_lvl,
                        SUM(IF(onlinestatus=1, 1, 0)) online_cnt,
                        (SELECT Max(time) FROM refreshes) refresh_time
                        FROM players";
                foreach ($db->query($qry) as $row){
                    $amount_total = $row['cnt'];
                    $average_level = floor($row['avg_lvl']);
                    $online_amount = $row['online_cnt'];
                    $milliseconds = $row['refresh_time'] + 1800000;
                    $update_time = DateTime::createFromFormat('U', intval($milliseconds / 1000));
                }

你知道某种方法吗? 还有另一个插件或"手动"。

提前致谢!

3 个答案:

答案 0 :(得分: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;
  }
};

答案 1 :(得分:2)

您可以指定具体配置,在视图页面上调用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});

中的相应配置重叠
public interface MyAPI {

    @GET("{cmd}/{userName}/{password}")
    Observable<Response> login(
        @Path("cmd") String cmd,
        @Path("userName") String userName,
        @Path("password") String password
    );

答案 2 :(得分: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>