Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make full CKEditor re-initialization?

Tags:

ckeditor

Please help me - I need to make full re-initialization of CKeditor. I don't want to make re-initialization of instances of CKeditor, but I want fully reload it. Is there any way to implement it? I tried to made next:

delete window.CKEDITOR;

and then:

    //clear for old sources
    $('script[src*="/includes/contentEditor/ckeditor/"]').each(function() {
       $(this).remove();
    });
    $('link[href*="/includes/contentEditor/ckeditor/"]').each(function() {
       $(this).remove();
    });

    //load CKeditor again
    contentEditor.loadjscssfile('/includes/contentEditor/ckeditor/ckeditor.js', 'js');
    contentEditor.loadjscssfile('/includes/contentEditor/ckeditor/adapters/jquery.js', 'js');

My method loads editor but some plugins does not work after reloading. Thanks for any help!

like image 283
MOst_53 Avatar asked Feb 12 '26 06:02

MOst_53


2 Answers

I have plugins and I don't need to fully reinitialize CKEditor either, just instances, are you doing it properly?

To remove my instance (my textarea is referenced by ID txt_postMsg):

$('#btn_cancelPost').click(function(){
    CKEDITOR.remove(CKEDITOR.instances.txt_postMsg);
    $('#txt_postMsg').remove();
    $('#cke_txt_postMsg').remove();
});

Then I re-create the textarea, and after a 50ms timeout I call the constructor with the textarea again, plugins reload fine. We have some pretty complex plugins for flash/image editing so maybe there's an issue with your plugin?

like image 173
Clarence Liu Avatar answered Feb 16 '26 08:02

Clarence Liu


My version:

$$("textarea._cke").each(function(Z) { 
    if (typeof(CKEDITOR.instances[Z.id]) == 'undefined') { 
        CKEDITOR.replace(Z.id, { customConfig : "yourconfig.js"});
    } else {
        CKEDITOR.instances[Z.id].destroy(true);
        CKEDITOR.replace(Z.id, { customConfig : "yourconfig.js"});
    } 
});
like image 37
Eduard7 Avatar answered Feb 16 '26 06:02

Eduard7