Multiple instances of CKEditor (in Safari) [duplicate]

时光毁灭记忆、已成空白 提交于 2019-12-22 17:55:57

问题


I'm having a problem creating multiple instances of a CKEditor in a JQuery UI dialog. The dialog loads a remote form via AJAX, so the goal is to be able to close and reopen the dialog and have a new instance of the editor. With the default options, when reopening the dialog it gives an error saying that an editor with that name already exists. So I have tried several methods of destroying the editor instance and they all result in the same problem. When the editor is reloaded, the text area says null and the buttons don't function.

Currently I'm using this method of destroying the instance:

var instance = CKEDITOR.instances['test'];
if (instance) { CKEDITOR.remove(CKEDITOR.instances['test']); }

I recreated the issue with a couple of simple html files available for download here.

EDIT: I just tried using two remote files with a text area that has a different name and I have the same problem. When one dialog is opened and then closed, the other dialog has a "null" CKEditor when it is opened.

Also, apparently this is only a problem in Safari.


回答1:


this is what i've done:

var CKeditors = {};
function loadEditors() {
    var $editors = $("textarea.ckeditor");
    if ($editors.length) {
        $editors.each(function() {
            var editorID = $(this).attr("id");
            if(CKeditors[editorID]){
                CKeditors[editorID].destroy();
                CKeditors[editorID] = null;
            }

            var dst = editorID+'-element';
            var html = '';
            if( $(this).val() ){
                html = $(this).val();
            }
            CKeditors[editorID] = CKEDITOR.appendTo(dst, {}, html);
        });
        $("textarea.ckeditor").hide();
    }
}

function updateCKEditors() {
    for(x in CKeditors){
        $("#"+x).val(CKeditors[x].getData());
    }
}

then after ajax succes im doing

loadEditors()

and before form submitting (for example using ajax):

updateCKEditors()

you need jQuery to have that working. this is for zend_forms, but after few corrections should work in normal forms too. play with 'dst' to do that.




回答2:


Bit of an old topic, but i had a similar problem.

I used activ's solution above, which worked out great! CKEDITOR.appendTo did't work out for me, but with the next slight modification to the loadEditors function it did:

function loadEditors() {
    var $editors = $("textarea.ckeditor");
    if ($editors.length) {
        $editors.each(function() {
            var editorID = $(this).attr("id");
            if(CKeditors[editorID]){
                CKeditors[editorID].destroy();
                CKeditors[editorID] = null;
            }

            var dst = editorID+'-element';
            CKeditors[editorID] = CKEDITOR.replace(dst, {});
        });
    }
}



回答3:


what I do:

var instance = CKEDITOR.instances['test'];
instance.destroy();
instance = null;


来源:https://stackoverflow.com/questions/1835940/multiple-instances-of-ckeditor-in-safari

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