![](/img/trans.png)
[英]ckeditor character count on multiple textareas with wordcount plugin
[英]Ckeditor Wordcount plugin to target specific fields
我正在使用 CKEditor - WYSIWYG HTML 編輯器 Drupal 7 模塊和 wordcount 插件。 我已經在 ckeditor plugins 目錄中添加了 wordcount 插件文件並使其正常工作,但是我的配置最大字數和字符數等對於所有字段都是相同的。 我想為特定字段指定不同的最大字數和字符數。 這是我的配置:
使用 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 並為不同字段(例如摘要和正文字段)設置不同的字數
我想通了,希望這可以幫助其他人。
我在我的 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 中,我轉到 configuration > CKEditor Filtered HTML (edit) 並在 Advanced options 下的 Custom Javascript configuration 中我添加了一個路徑到我的 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 模塊更新,此文件將不會受到影響。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.