Skip to content

Commit 7742067

Browse files
committed
#1457: Improved detection of empty sortable
1 parent 92ce2af commit 7742067

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

Sortable.js

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
*/
176176
_detectNearestEmptySortable = function(x, y) {
177177
for (var i = 0; i < sortables.length; i++) {
178-
if (sortables[i].children.length) continue;
178+
if (_lastChild(sortables[i])) continue;
179179

180180
var rect = _getRect(sortables[i]),
181181
threshold = sortables[i][expando].options.emptyInsertThreshold,
@@ -1224,12 +1224,12 @@
12241224
return completed();
12251225
}
12261226

1227-
if ((el.children.length === 0) || (el.children[0] === ghostEl) ||
1228-
_ghostIsLast(evt, axis, el) && !dragEl.animated
1229-
) {
1230-
//assign target only if condition is true
1231-
if (el.children.length !== 0 && el.children[0] !== ghostEl && el === evt.target) {
1232-
target = _lastChild(el);
1227+
var elLastChild = _lastChild(el);
1228+
1229+
if (!elLastChild || _ghostIsLast(evt, axis, el) && !elLastChild.animated) {
1230+
// assign target only if condition is true
1231+
if (elLastChild && el === evt.target) {
1232+
target = elLastChild;
12331233
}
12341234

12351235
if (target) {
@@ -1986,10 +1986,8 @@
19861986
function _lastChild(el) {
19871987
var last = el.lastElementChild;
19881988

1989-
while (last === ghostEl || last.style.display === 'none') {
1989+
while (last && (last === ghostEl || last.style.display === 'none')) {
19901990
last = last.previousElementSibling;
1991-
1992-
if (!last) break;
19931991
}
19941992

19951993
return last || null;

0 commit comments

Comments
 (0)