As the Zuul response , the problem occurs when you remove the iframe
from the DOM. For this reason, my suggestion is to destroy the editor before ordering (making it revert to a simple textarea
) and re-create it after it.
First, the option clone
is used so that the element being dragged is not the div
itself, but a clone of it (this prevents the element from being removed from the DOM when starting the sorting, but only hidden):
$("#e").sortable({
helper:"clone",
In this way, the helper will still look like the editor being moved - only empty. The original element will still be in the DOM, intact, but invisible.
As the helper is an exact copy of the element to be moved, it also has a iframe
. It can be popular with a copy of the editor's own data so that it looks more like the original element. The code below is just an example, you can probably improve it more (the look looks pretty good except for some details in the drawing):
start:function(event, ui) {
// Encontra o id do textarea original (melhor usar classes...)
while ( event.originalEvent )
event = event.originalEvent;
var id = $(event.target).closest("#e1, #e2").find("textarea")[0].id;
// Acha os dados do editor e os copia pro helper
var copia = CKEDITOR.instances[id].getData();
ui.helper.find("iframe").contents().find("body").html(copia);
Then, the editor is destroyed at the beginning of the sorting process. As it is hidden, no visual change is perceived:
CKEDITOR.instances[id].destroy(false);
},
Finally, when you release, you recreate the editor:
stop:function(event) {
while ( event.originalEvent )
event = event.originalEvent;
var id = $(event.target).closest("#e1, #e2").find("textarea")[0].id;
CKEDITOR.replace(id);
}
});
Example in jsFiddle . A problem with this method is that after destroying and re-creating the editor, you lose all revision history (ie undo and redo ) as well as any "state" that the editor before the destruction. Unfortunately I have nothing to suggest in this regard ...
Another small drawback is the helper , which ideally should be an identical copy of the content being moved. I do not think it is simple to do this with the editor that uses iframe
( iframe
s are a bit "boring" to work due to security issues), but it may be possible to improve the cloning method.
Warning: It should be noted that using iframe
in this way is subject to a UX problem: if you click the blue / red area and drag, everything is OK, but if you click for example on one of the editor buttons and accidentally move the mouse, it starts an ordering (which can be annoying to the user).
One way to avoid this would be to use a sortable
to restrict which part (s) of handle
you can drag the element - instead of the entire div
. Example . Or maybe you get something by intercepting the capturing phase and preventing < in> drag if it starts when it occurs inside div
(I do not know how to do this using iframe
, there is no "beforeStart" method or something like that ...).