如何使CKEditor完全重新初始化?

发布于 2024-11-01 07:09:34 字数 668 浏览 1 评论 0原文

请帮助我 - 我需要完全重新初始化 CKeditor。我不想重新初始化 CKeditor 实例,但我想完全重新加载它。有没有办法实现呢? 我尝试制作下一步:

delete window.CKEDITOR;

然后:

    //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');

我的方法加载编辑器,但某些插件在重新加载后不起作用。感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

破晓 2024-11-08 07:09:34

我有插件,我也不需要完全重新初始化 CKEditor,只是实例,你做得正确吗?

要删除我的实例(我的文本区域由 ID txt_postMsg 引用):

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

然后我重新创建文本区域,并在 50 毫秒超时后再次使用文本区域调用构造函数,插件重新加载正常。我们有一些非常复杂的 Flash/图像编辑插件,所以也许您的插件有问题?

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?

空袭的梦i 2024-11-08 07:09:34

我的版本:

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

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"});
    } 
});
哽咽笑 2024-11-08 07:09:34

尝试类似的东西

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

try something like

for(var instanceName in CKEDITOR.instances)
    CKEDITOR.remove(CKEDITOR.instances[instanceName]);        
CKEDITOR.replaceAll();
骑趴 2024-11-08 07:09:34

阿方索ML
我使用 CKeditor 动态编辑网站的不同部分。当我单击网站的某些区域时,它会显示带有 CKeditor 的弹出窗口,该区域的内容位于该区域上方。当我保存它时,我会销毁该编辑器的实例,但是如果在编辑时使用链接插件 CKeditor 则无法在不刷新页面的情况下显示编辑器。 Chrome 说 - 未捕获类型错误:无法调用未定义的方法“分割”,Mozilla - x.config.skin 未定义(我尝试设置 config.skin,它显示另一个错误 - z 未定义)。

我希望完整的重新初始化能有所帮助。

PS 抱歉,我可以找到如何回答您的评论......

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...

踏雪无痕 2024-11-08 07:09:34

我一直在寻找一种重新初始化编辑器的方法,最终得到的唯一解决方案是删除实例并创建一个新 ID。

这是我的代码。

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, 
{
}

它并不完美,但它有效。

希望这有帮助。

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.

薄荷梦 2024-11-08 07:09:34

这是我的解决方案:

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

或者

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

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());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文