【问题标题】:CKEditor 4 - replaceAll() with custom configCKEditor 4 - replaceAll() 与自定义配置
【发布时间】:2015-07-24 17:23:58
【问题描述】:

查看源代码后,CKEDITOR.replaceAll 函数似乎无法在调用时传递任何自定义配置。

是否有任何解决方法,以便我可以将不同的自定义配置传递给特定的文本区域?

例如我希望所有具有“高级”类的文本区域与具有“普通”类的文本区域具有不同的浏览图像路径

【问题讨论】:

    标签: javascript ckeditor config


    【解决方案1】:
    CKEDITOR.replaceAll(function(textarea,config) {
        if(textarea.className == "advanced")
        {
            config.removeButtons = 'About';
            return true;
        }
        else if(textarea.className == "basic")
        {
            config.removeButtons = 'Cut,Copy,Paste,About,Save,NewPage,DocProps,Preview,Templates,PasteFromWord,SelectAll,Scayt,SpellChecker,Form,Checkbox,Radio,TextField,Textarea,Select,Button,ImageButton,HiddenField,JustifyLeft,JustifyCenter,JustifyRight,JustifyBlock,Flash,Smiley,Styles,Font,FontSize,Blockquote,Format,Image,Table,Link';
            config.uiColor = '#AADC6E';
            return true;
        }
    });
    

    【讨论】:

    • 图片浏览器路径只是一个例子,我真正需要的是每个类的不同配置,比如要加载的插件、按钮设置等
    • 使用 return true 或 false 对我来说没有任何区别,如果此函数无法将 textarea 转换为 CKEditor,CKEditor 会自行使用默认配置执行此操作。我正在使用 CDN。
    【解决方案2】:

    对于在谷歌搜索后登陆这里的任何其他人,Anna Oleksiuk 的回答为我指明了我想要实现的正确方向。我在页面上有多个 textarea 字段,有些需要基本配置(即 cmets),有些需要标准配置,有些需要保留为标准 textarea,以下对我有用:

    CKEDITOR.replaceAll(function (textarea, config) {
      if (textarea.className === "ck-standard") {
        config.customConfig = "/theme/js/ckeditor/standard.js";
        return true;
      }
      else if (textarea.className === "ck-basic") {
        config.customConfig = "/theme/js/ckeditor/basic.js";
        return true;
      }
    
      return false;
    });
    

    就我而言,关键元素是 return false; 以阻止任何其他字段被转换。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多