Skip to content

Commit

Permalink
fixed detect direction for floats; revamped _ghostIsLast
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 9e6e134 commit 8f74d27
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ||
Expand Down Expand Up @@ -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;
Expand All @@ -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)
);
}

Expand Down

0 comments on commit 8f74d27

Please sign in to comment.