Skip to content

Commit

Permalink
SortableJS#1457: Improved detection of empty sortable
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-m1 authored and elo7-developer committed Nov 18, 2019
1 parent 368e4d5 commit 7ede1ab
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 @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 7ede1ab

Please sign in to comment.