From 7742067365624885dd9823d573bc666677e3962c Mon Sep 17 00:00:00 2001 From: Owen Mills Date: Thu, 7 Mar 2019 12:18:57 -0500 Subject: [PATCH] #1457: Improved detection of empty sortable --- Sortable.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Sortable.js b/Sortable.js index 30cb0b318..45995ad59 100644 --- a/Sortable.js +++ b/Sortable.js @@ -175,7 +175,7 @@ */ _detectNearestEmptySortable = function(x, y) { for (var i = 0; i < sortables.length; i++) { - if (sortables[i].children.length) continue; + if (_lastChild(sortables[i])) continue; var rect = _getRect(sortables[i]), threshold = sortables[i][expando].options.emptyInsertThreshold, @@ -1224,12 +1224,12 @@ return completed(); } - if ((el.children.length === 0) || (el.children[0] === ghostEl) || - _ghostIsLast(evt, axis, el) && !dragEl.animated - ) { - //assign target only if condition is true - if (el.children.length !== 0 && el.children[0] !== ghostEl && el === evt.target) { - target = _lastChild(el); + var elLastChild = _lastChild(el); + + if (!elLastChild || _ghostIsLast(evt, axis, el) && !elLastChild.animated) { + // assign target only if condition is true + if (elLastChild && el === evt.target) { + target = elLastChild; } if (target) { @@ -1986,10 +1986,8 @@ function _lastChild(el) { var last = el.lastElementChild; - while (last === ghostEl || last.style.display === 'none') { + while (last && (last === ghostEl || last.style.display === 'none')) { last = last.previousElementSibling; - - if (!last) break; } return last || null;