2016-02-07 34 views
0

添加wordcount插件后,它只是恢复到我的原始文本区域。CKEditor CDN使用本地插件还原为原始文本区域

这里是我的代码(JS是不是我的事,任何方式):

<textarea id="editor1" name="editor1" maxlength="10" placeholder="5000 Characters Max.(with HTML)"></textarea> 
<script> 
    CKEDITOR.plugins.addExternal('wordcount', '/ckeditor/plugins/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: false, 

      // Maximum allowed Word Count 
      maxWordCount: 4, 

      // Maximum allowed Char Count 
      maxCharCount: 10 
     }; 

CKEDITOR.replace('editor1', { 
    extraPlugins: 'colorbutton,colordialog,font,wordcount', 
    toolbar: [ 
     { name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] }, 
     { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] }, 
     { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language' ] }, 
     { name: 'colors', items: [ 'TextColor', 'BGColor' ] }, 
     '/', 
     { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] }, 
     { name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] }, 
     ] 
    }); 
</script> 
+1

你打破的JavaScript,因为'config'是不确定的。 –

回答

1

config变量(未定义)不会做任何事情。您需要将对象设置为传递到CKEDITOR.replace的对象或您的config.js文件中。欲了解更多详情,请参阅Setting CKEditor Configuration指南。

这里最简单的方法是将单词计数插件配置添加到CKEDITOR.replace调用,就像这样:

<textarea id="editor1" name="editor1" maxlength="10" placeholder="5000 Characters Max.(with HTML)"></textarea> 
<script> 
CKEDITOR.plugins.addExternal('wordcount', '../../plug/wordcount/'); 

CKEDITOR.replace('editor1', { 
    extraPlugins: 'colorbutton,colordialog,font,wordcount', 
    toolbar: [ 
     { name: 'clipboard', groups: [ 'clipboard', 'undo' ], items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] }, 
     { name: 'editing', groups: [ 'find', 'selection', 'spellchecker' ], items: [ 'Find', 'Replace', '-', 'SelectAll', '-', 'Scayt' ] }, 
     { name: 'paragraph', groups: [ 'list', 'indent', 'blocks', 'align', 'bidi' ], items: [ 'NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock', '-', 'BidiLtr', 'BidiRtl', 'Language' ] }, 
     { name: 'colors', items: [ 'TextColor', 'BGColor' ] }, 
     '/', 
     { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] }, 
     { name: 'styles', items: [ 'Styles', 'Format', 'Font', 'FontSize' ] }, 
    ], 
    wordcount: { 
     // Whether or not you want to show the Word Count 
     showWordCount: true, 

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

     // Maximum allowed Word Count 
     maxWordCount: 4, 

     // Maximum allowed Char Count 
     maxCharCount: 10 
    } 
}); 
</script> 
+0

如果您使用的是本地版本,但是我使用的是CDN,除非定义,否则不会使用本地配置文件,但如何实现该功能并没有真正的明确文档。仅限于零件和零件。无论如何,我已经放弃了CKeditor。缺少CDN的文档是令人震惊的,并且在版本文档之间没有明显的中断...... – user3154948

+0

我没有看到任何上述代码不能用于CDN的原因。它是内联配置,它[在文档中明确解释](http://docs.ckeditor.com/#!/guide/dev_configuration-section-defining-configuration-in-page)。您的唯一要求是在'../../ plug/wordcount /'目录中添加'wordcount'插件。没有这个,那么,你不能添加没有插件代码的插件。 –

+0

你看不出有什么理由不起作用,但它没有。 CK非常麻烦,没有足够的真实世界(非JS开发人员)用户友好。 – user3154948