我正在使用CKEditor-WYSIWYG HTML编辑器Drupal 7模块和wordcount插件。我已经在ckeditor plugins目录中添加了wordcount插件文件,并使其正常工作,但是我的config max单词和字符数等对于所有字段都是相同的。我想为特定字段指定不同的最大单词和字符数。这是我的配置:
使用CKEDITOR.replace,我做了以下工作:
CKEDITOR.replace('edit-body-und-0-summary',
{
extraPlugins: 'wordcount',
wordcount: {
showCharCount: true,
maxCharCount: 123
}
});
这有效,但是刷新页面后,它返回到全局最大单词和字符数。 Textrea ID为edit-body-und-0-summary
,但此标签在页面其他位置重复。
[我该如何向textarea标签添加唯一ID,并为不同的字段设置不同的字数,例如Summary and Body fields
我知道了,希望这对外面的人有帮助。
我在Adminimal Sub主题中添加了以下内容,以将类添加到摘要文本区域:
function adminimal_sub_form_alter(&$form, &$form_state, $form_id) {
if (isset($form['#node']) && $form['#node']->type == 'article') {
// Add class to body textarea for various content types. This is used for the Ckeditor wordcount plugin to target summary textarea.
$form['body']['und']['0']['summary']['#attributes']['class']['0'] = 'article-summary';
}
}
然后下载了Ckeditor 4 Wordcount插件并将其保存在插件目录(sites / all / libraries / ckeditor / plugins)。
在Drupal UI中,我转到配置> CKEditor过滤的HTML(编辑),在“高级”选项下的“自定义Javascript”配置中,我向ckeditor.config.js添加了路径(config.customConfig ='/ sites / all / themes / global / js / ckeditor.config.js';)。
这是我的ckeditor.config.js:
CKEDITOR.editorConfig = function(config) {
if (this.element.hasClass('article-summary')) {
config.wordcount = {
showCharCount: true,
maxCharCount: 170
}
}
// Make CKEditor's edit area as high as the textarea would be.
if (this.element.$.rows > 0) {
config.height = this.element.$.rows * 20 + 'px';
}
}
这里我可以设置maxwordcount并加载更多内容,但是对于此项目,只需要maxwordcount。这样,如果Drupal Ckeditor模块得到更新,此文件将不会受到影响。