Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set CKEditor config dynamically

I need to change one config setting in CKEditor config dynamically.

I'm writing a plugin which adds checkbox to CKEditor toolbar and upon checking/unchecking it - a forcePasteAsPlainText is being changed as true/false.

Issue is that config is being read on initiating CKEditor component and all changes later are being ignored. Is there a possible way to change value 'on the fly'?

like image 622
Vax Avatar asked Sep 20 '25 02:09

Vax


1 Answers

  1. You can specif settings in config file that are default initializations for any editor created.

    CKEDITOR.editorConfig = function(config) {
    config.forcePasteAsPlainText = false;
    ...
    }
    
  2. You can override the config settings in this way so only the editor initialized will get these changes.

    CKEDITOR.replace('myEditor', { forcePasteAsPlainText: ture });
    
  3. You can also use editor destroy and recreate with custom configs.

    var editor = CKEDITOR.instances.myEditor;
    if (editor) { editor.destroy(true); }
    CKEDITOR.config.forcePasteAsPlainText = false;
    CKEDITOR.config.width = 400;
    CKEDITOR.config.height = 300;
    
    CKEDITOR.replace('myEditor', CKEDITOR.config);
    
like image 78
Wasif.Butt Avatar answered Sep 23 '25 10:09

Wasif.Butt