trsteel88 / TrsteelCkeditorBundle

Symfony2 bundle for easy integration of the CKEditor WYSIWYG
97 stars 58 forks source link

Plugin breaks when dragged&dropped by Jquery UI Sortable #53

Closed ioleo closed 11 years ago

ioleo commented 11 years ago

After dragging & dropping with Jquery UI Sortable the plugin goes dead. The content disappears only an empty ckeditor shell (not working buttons, white content space).

Does anyone have an idea how to fix it? Is it CKEditor issue, or the way TrsteelCkeditorBundle initiates Ckeditor could affect this?

ioleo commented 11 years ago

Okay, it seems it's a CKEditor vs JqueryUI issue. I solved my problem with this code

var ckeConfigs = [];
$('#sortable-container').sortable({
    start:function (event,ui) {
        // save each ckeditor config, create ckeditor html's clone
        // destroy ckeditor, hide the textarea and insert the clone to create an illusion that cke is still there
        $('textarea', ui.item).each(function(){
            var tagId = $(this).attr('id');
            var ckeClone = $(this).next('.cke').clone().addClass('cloned');
            ckeConfigs[tagId] = CKEDITOR.instances[tagId].config;
            CKEDITOR.instances[tagId].destroy();
            $(this).hide().after(ckeClone);
        });
    },
    stop: function(event, ui) {
        // for each textarea init ckeditor anew and remove the clone
        $('textarea', ui.item).each(function(){
            var tagId = $(this).attr('id');
            CKEDITOR.replace(tagId, ckeConfigs[tagId]);
            $(this).next('.cloned').remove();
        });
    }
});
coorasse commented 11 years ago

doesn't work for me. it gives an error on stop at line CKEDITOR.replace(tagId, ckeConfigs[tagId]); saying Uncaught TypeError: Cannot call method 'push' of undefined

trsteel88 commented 11 years ago

Please ensure all your javascript files are loaded correctly.

arpita-hunka commented 3 years ago

I have another type of element along with CKEditor, I used the above code and that is working when I move the CKEditor but when i move other elements at that time CKEditor content lost. @ioleo Can you please help to fix this?