0

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

ckeditor.config.js

使用 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 并为不同字段(例如 摘要和正文字段)设置不同的字数

4

1 回答 1

0

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

我在我的管理子主题中添加了以下内容,以向摘要文本区域添加一个类:

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 Filtered HTML (edit) 并在高级选项下的自定义 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 模块得到更新,这个文件将不会受到影响。

于 2019-12-05T18:10:12.600 回答