From 8f74d27b23145ec633b91fc831558e58b65c3264 Mon Sep 17 00:00:00 2001 From: owen-m1 Date: Sun, 10 Feb 2019 12:41:12 -0500 Subject: [PATCH] fixed detect direction for floats; revamped _ghostIsLast --- Sortable.js | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/Sortable.js b/Sortable.js index 953f30696..e766e7c4c 100644 --- a/Sortable.js +++ b/Sortable.js @@ -119,9 +119,15 @@ define('sortable', [], function sortableFactory() { return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse' ? 'vertical' : 'horizontal'; } + if (child1 && firstChildCSS.float !== 'none') { + var touchingSideChild2 = firstChildCSS.float === 'left' ? 'left' : 'right'; + + return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ? + 'vertical' : 'horizontal'; + } return (child1 && ( - child1.style.display === 'block' || // getComputedStyle() gives 'block' when 'inline-block' + firstChildCSS.display === 'block' || firstChildCSS.display === 'flex' || firstChildCSS.display === 'table' || firstChildCSS.display === 'grid' || @@ -1910,15 +1916,17 @@ define('sortable', [], function sortableFactory() { } /** - * Gets the last child in the el, ignoring ghostEl + * Gets the last child in the el, ignoring ghostEl or invisible elements (clones) * @param {HTMLElement} el Parent element * @return {HTMLElement} The last child, ignoring ghostEl */ function _lastChild(el) { var last = el.lastElementChild; - if (last === ghostEl) { - last = el.children[el.childElementCount - 2]; + while (last === ghostEl || last.style.display === 'none') { + last = last.previousElementSibling; + + if (!last) break; } return last || null; @@ -1930,12 +1938,13 @@ define('sortable', [], function sortableFactory() { mouseOnOppAxis = axis === 'vertical' ? evt.clientX : evt.clientY, targetS2 = axis === 'vertical' ? elRect.bottom : elRect.right, targetS1Opp = axis === 'vertical' ? elRect.left : elRect.top, - targetS2Opp = axis === 'vertical' ? elRect.right : elRect.bottom; + targetS2Opp = axis === 'vertical' ? elRect.right : elRect.bottom, + spacer = 10; return ( - mouseOnOppAxis > targetS1Opp && - mouseOnOppAxis < targetS2Opp && - mouseOnAxis > targetS2 + axis === 'vertical' ? + (mouseOnOppAxis > targetS2Opp + spacer || mouseOnOppAxis <= targetS2Opp && mouseOnAxis > targetS2 && mouseOnOppAxis >= targetS1Opp) : + (mouseOnAxis > targetS2 && mouseOnOppAxis > targetS1Opp || mouseOnAxis <= targetS2 && mouseOnOppAxis > targetS2Opp + spacer) ); }