首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >针对特定字段的Ckeditor Wordcount插件

问针对特定字段的Ckeditor Wordcount插件
EN

Stack Overflow用户
提问于 2019-11-26 02:22:30
回答 1查看 247关注 0票数 0

我使用的是CKEditor - WYSIWYG HTML编辑器Drupal7模块和wordcount插件。我已经在ckeditor plugins目录中添加了wordcount插件文件并使其正常工作,但是我的配置最大字数和字符数等对于所有字段都是相同的。我想为特定字段指定不同的最大字数和字符数。下面是我的配置:

ckeditor.config.js

使用CKEDITOR.replace,我做了以下事情:

代码语言:javascript
复制
  CKEDITOR.replace('edit-body-und-0-summary',
      {
          extraPlugins: 'wordcount',
          wordcount: {
              showCharCount: true,
              maxCharCount: 123
          }
      });

这是可行的,但在刷新页面后,它又回到了全局最大字数和字符数。Textrea ID是edit-body-und-0-summary,但此标记在页面中的其他位置重复。

如何将唯一ID添加到文本区域标记中,并对不同字段进行不同的字数统计,例如Summary and Body fields

EN

回答 1

Stack Overflow用户

发布于 2019-12-06 02:10:13

我想通了,希望这能对其他人有所帮助。

我将以下代码添加到Adminimal Sub主题中,以便在摘要文本区域中添加一个类:

代码语言:javascript
复制
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插件,并将其保存在插件目录(site/all/libraries/ckeditor/ plugins )中。

在Drupal UI中,我转到configuration > Javascript Filtered (编辑),在Custom Javascript configuration中的Advanced options下,我添加了一个到我的ckeditor.config.js的路径(config.customConfig = '/sites/all/themes/global/js/ckeditor.config.js';).

这是我的ckeditor.config.js:

代码语言:javascript
复制
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模块,该文件也不会受到影响。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59037958

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档