【问题标题】:ckeditor - how to manage config changesckeditor - 如何管理配置更改
【发布时间】:2012-05-18 19:24:28
【问题描述】:

我有一个依赖于一些自定义参数的 ckeditor 插件。这些参数可能会在操作过程中改变值。我最终实现这一点的方式是将当前值保存在插件内的局部变量中,该变量在开始时初始化并且可以通过自定义命令进行更改。像这样

var somethingId = editor.config.myplugin_Something;
editor.addCommand('changeSomething',  {
    exec: function(_editor, data) {
        somethingId = data.something;
    }
});

这工作正常,但我有一个问题(据我所知)我到达了需要更改数据的位置,但编辑器尚未初始化,所以调用

$.each(CKEDITOR.instances, function (index, editor) {
    editor.execCommand('changeSomething', {
        something: newValue
        });
});

没有任何效果,插件以初始配置中传递的值结束。

我想不出使用全局变量的好方法。有没有更好的方法来管理 ckeditor 插件的可变配置参数?

【问题讨论】:

    标签: javascript ckeditor


    【解决方案1】:

    我想出了一个足够简单的解决方案。使用config 对象本身,并确保初始化回调 也设置了正确的值。

    所以初始化看起来更像:

    var config = { width: xxx, height: xxx}; // do not include "something" value
    $('#mytextbox').ckeditor(function(){
        this.config.myplugin_somethingId = currentSomethingValue;
    });
    

    以后需要修改的时候我会做,

    $.each(CKEDITOR.instances, function (index, editor) {
         editor.config.myplugin_somethingId = newSomethingValue;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-22
      • 2021-06-24
      • 2013-03-06
      相关资源
      最近更新 更多