From 885f07c03136cb070943196baf832cdd19e8b0a8 Mon Sep 17 00:00:00 2001 From: Oria Date: Thu, 20 Jul 2017 12:38:11 +0300 Subject: [PATCH] Fix bugs when dragged element has iframes When the dragged element has iframes, it is undraggable, gets stuck, and other weird behaviors. To fix it, on drag-start I take iframes out of the dragged element and out of DOM, and return them to place on drop. --- Sortable.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Sortable.js b/Sortable.js index 9dccffa..62c101a 100644 --- a/Sortable.js +++ b/Sortable.js @@ -54,6 +54,7 @@ touchEvt, moved, + iframe_stash, /** @const */ R_SPACE = /\s+/g, @@ -397,6 +398,20 @@ dragEl.style['will-change'] = 'transform'; dragStartFn = function () { + // stash iframes because they prevent dragging + iframe_stash = null; + var iframes = dragEl.querySelectorAll('iframe'); + if (iframes && iframes.length) + { + iframe_stash = document.createElement('x'); // intentionally not adding it to DOM + for (var i = 0; i < iframes.length; i++) + { + iframes[i].sortable_parentElement = iframes[i].parentElement; + iframes[i].sortable_nextElementSibling = iframes[i].nextElementSibling; + iframe_stash.appendChild(iframes[i]); + } + } + // Delayed drag has been triggered // we can re-enable the events: touchmove/mousemove _this._disableDelayedDrag(); @@ -888,6 +903,20 @@ } this._offUpEvents(); + + // unstash iframes + if (iframe_stash) + { + for (var i = 0; i < iframe_stash.children.length; i++) + { + var iframe = iframe_stash.children[i]; + if (iframe.sortable_nextElementSibling) + iframe.sortable_parentElement.insertBefore(iframe, iframe.sortable_nextElementSibling) + else + iframe.sortable_parentElement.appendChild(iframe); + } + iframe_stash = null; + } if (evt) { if (moved) {