Skip to content

Commit

Permalink
#1457: Improved detection of empty sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-m1 committed Mar 7, 2019
1 parent 92ce2af commit 7742067
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7742067

Please sign in to comment.