Javascript CKEditor-在一个页面中限制多个编辑器上的字符
我正在开发一个基于网络的ERP,我需要一些帮助 作为文本编辑器,我选择了CKEditor,它工作得很好,可以做我需要的一切。 嗯…不完全是所有的 我添加了一个插件名“wordcount”,可以计算单词或字符数并设置限制 问题是,我在一个页面上有多个ckeditor,我需要为每个ckeditor设置不同的限制。如您所见,插件为两个编辑器设置了相同的限制: 参数通过config.js传递:Javascript CKEditor-在一个页面中限制多个编辑器上的字符,javascript,ckeditor,ckeditor4.x,ckeditor-wordcount,Javascript,Ckeditor,Ckeditor4.x,Ckeditor Wordcount,我正在开发一个基于网络的ERP,我需要一些帮助 作为文本编辑器,我选择了CKEditor,它工作得很好,可以做我需要的一切。 嗯…不完全是所有的 我添加了一个插件名“wordcount”,可以计算单词或字符数并设置限制 问题是,我在一个页面上有多个ckeditor,我需要为每个ckeditor设置不同的限制。如您所见,插件为两个编辑器设置了相同的限制: 参数通过config.js传递: config.wordcount = { // Whether or not you want to sh
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};
你知道怎么做吗?
也可以使用其他插件或“手动”
提前谢谢
<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>
CKEDITOR.replace('comments',
{工具栏:[
{name:'document',组:['mode','document','doctools'],项:['Source']},
{name:'clipboard',项:['Undo','Redo','-','Cut','Copy','Paste','PasteText','PasteFromWord']},
{name:'basicstyles',组:['basicstyles','cleanup'],项:['Bold','Italic','Strike','-','TextColor']},
{name:'段落',组:['list','indent','blocks','align'],项:['NumberedList','BulletedList','-','Outdent','indent','blocks'],
{name:'links',项:['Link','Unlink']},
{name:'insert',项:['Image','Table','SpecialChar']},
{name:'editing',组:['find','selection','spellchecker'],项:['Scayt']}
],
身高:400,
已启用调整大小:true,
字数:{
显示段落:错误,
showWordCount:没错,
showCharCount:是的,
萨沙:错,
countHTML:false,
maxWordCount:-1,
maxCharCount:4000}
});
您可以指定特定的配置,当在查看页面上调用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});
我实现如下:需要将attrs数据添加到带有maxWord和maxChar的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;
}
};
你是如何在CKeditor 4.x中添加wordcount插件的?你能详细说明一下吗?它不存在于default插件中