I have a ckeditor plugin that depends on some custom parameters. These parameters may change value over the course of operation. The way I ended up implementing this was to keep the current value in a local variable inside the plugin which is initialized at the beginning and can be changed through a custom command. Like so
var somethingId = editor.config.myplugin_Something;
editor.addCommand('changeSomething', {
exec: function(_editor, data) {
somethingId = data.something;
}
});
This works ok, but I’m having an issue where (from what I can tell) I’m reaching the situatino where I need to change the data, but the editor has not been initialized yet, so calling
$.each(CKEDITOR.instances, function (index, editor) {
editor.execCommand('changeSomething', {
something: newValue
});
});
has no effect and the plugin ends up with the value that was passed in the initial config.
I can’t think of a good way out of this short of using a global variable. Is there a better way to manage mutable config parameters for ckeditor plugins?
I came up with a solution that’s simple enough. Use the
configobject itself, and also make sure the initialization callback sets the correct value as well.So the initialization looks more like:
And when it needs to be modified later I do,