diff --git a/Sortable.js b/Sortable.js index 85f8cad15..c873e4ad8 100644 --- a/Sortable.js +++ b/Sortable.js @@ -162,7 +162,7 @@ define('sortable', [], function sortableFactory() { */ _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, @@ -1214,12 +1214,12 @@ define('sortable', [], function sortableFactory() { 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) { @@ -1976,10 +1976,8 @@ define('sortable', [], function sortableFactory() { 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;