开发者

How to make full CKEditor re-initialization?

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!


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?


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"});
    } 
});


try something like

for(var instanceName in CKEDITOR.instances)
    CKEDITOR.remove(CKEDITOR.instances[instanceName]);        
CKEDITOR.replaceAll();


AlfonsoML I use CKeditor for dynamically edit different part of site. When I click on some area of the site it shows popup with CKeditor with content of this area above this area. When I save it I destroy instance of this editor, but if while editing I use link plugin CKeditor can't show editor without page refreshing. Chrome says - Uncaught TypeError: Cannot call method 'split' of undefined, Mozilla - x.config.skin is undefined(I try to set config.skin and it show another error - z is undefined).

I hope the full re-init can help.

P.S. Sorry I can find how to answer on your comment...


I've been looking for a way to re-initialize the editor and the only solution that I end up is to delete the instance and create a new ID.

Here's my code.

var editor = 'myeditor'
var instance = CKEDITOR.instances[editor];

if(typeof instance != 'undefined')
{
    instance.destroy();
    $(".cke_editor_" + editor).remove();

    //make a new id
    editor = (Math.random().toString(36).substr(2, 10););
}

CKEDITOR.replace(editor, 
{
}

It's not perfect but it works.

Hope this helps.


This is my solution:

var editor = CKEDITOR.instances[your_ckeditor_id];
editor.mode = 'source';
editor.setMode('wysiwyg');

OR

var editor = CKEDITOR.instances[your_ckeditor_id];
editor.setData(editor.getData());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜