diff --git a/modules/library/dnd/plugins/dndck4/plugin.js b/modules/library/dnd/plugins/dndck4/plugin.js index c69be32..111444f 100644 --- a/modules/library/dnd/plugins/dndck4/plugin.js +++ b/modules/library/dnd/plugins/dndck4/plugin.js @@ -379,6 +379,7 @@ Drupal.dndck4 = { // On drop, insert the atom and stop the liner. listeners.push(editable.once('drop', function (evt) { evt.data.preventDefault(); + evt.data.stopPropagation(); // Insert the new widget if the liner has a valid target position. if (!CKEDITOR.tools.isEmpty(liner.visible)) { var range; @@ -390,17 +391,27 @@ Drupal.dndck4 = { range = editor.createRange(); range.selectNodeContents(editable); } - var data = Drupal.dndck4.getDefaultInsertData(editor, atomInfo); - var caption = atomInfo.meta.legend || ''; - Drupal.dndck4.insertNewWidget(editor, range, data, caption); + dropAtom(range); } stopLiner(); })); + // Prevent false drops (out of range) + listeners.push(editor.document.once('drop', function (evt) { + evt.data.preventDefault(); + var range = editor.createRange(); + range.moveToElementEditablePosition(editor.document.getBody(), true); + dropAtom(range); + stopLiner(); + })); // On dragend (without drop), stop the liner. listeners.push(editor.document.on('dragend', function (evt) { stopLiner(); })); + $(document).bind('dragend', function (evt) { + stopLiner(); + }); + // On dragleave, hide the liner. // @todo doesn't work, dragleave doesn't have a reliable implementation // across browsers... @@ -409,6 +420,12 @@ Drupal.dndck4 = { // console.log('dragleave'); // })); + function dropAtom(range) { + var data = Drupal.dndck4.getDefaultInsertData(editor, atomInfo); + var caption = atomInfo.meta.legend || ''; + Drupal.dndck4.insertNewWidget(editor, range, data, caption); + } + function stopLiner() { // Stop observing events. eventBuffer.reset();