Changing configuration options of a CKEditor instance

时光总嘲笑我的痴心妄想 提交于 2021-02-11 15:02:27

问题


I have a CKEditor instance attached to a textarea. I would like to be able change some configuration options of this instance after its creation, depending on the value of another form field.

Is it possible to do this, or else it's necessary to destroy the instance and attach another one, with the new options? I've checked in the CKEditor docs, but found nothing about this subject.

Thanks in advance,


回答1:


Usually the configuration options will work only upon creation. You might be able to perform some tricks and so get some of the options to work at a later time, but that's usually more difficult.




回答2:


I know I am late. But I would like to share this.

If you decide on a config before the creation of a ckeditor instance and plan on overriding those configurations, it's not possible. You can definitely add more config options but cannot change any existing option.

Say you pass a config object while creation of an instance.

CKEDITOR will internally call replace function to create the instance. Which will, in turn, check if anything is present in config.js.

You provide some extra config option and also, you try to override any existing option, for eg., toolbar.

Internally, CKEDITOR will do an extend and will try to merge already existing config object and the new config object provided by config.js and finally create a new config object which it will use to create the instance.

When it extends, i.e tries to merge both the config object, it will take all the new config options and assign to final new config object. But, for existing config options which you tried to override in config.js, it will take the original option and assign to this new config object.

Hence, whatever you had provided to override existing config object is lost.

One option which you have is to destroy the current instance and use your new config object to create the instance.

I hope I was able to explain.



来源:https://stackoverflow.com/questions/7636277/changing-configuration-options-of-a-ckeditor-instance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!