【问题标题】:Ckeditor Wordcount plugin to target specific fieldsCKeditor Wordcount 插件以针对特定字段
【发布时间】:2019-11-25 18:22:29
【问题描述】:

我正在使用 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 并为不同字段设置不同的字数,例如 Summary and Body fields

【问题讨论】:

    标签: javascript php drupal-7 ckeditor ckeditor-wordcount


    【解决方案1】:

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

    我在我的 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 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 模块得到更新,这个文件就不会受到影响。

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 1970-01-01
      • 2022-11-17
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多