Skip to content

Commit 74be32e

Browse files
committed
fixed detect direction for floats; revamped _ghostIsLast
1 parent 071f190 commit 74be32e

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

Sortable.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,15 @@
132132
return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse'
133133
? 'vertical' : 'horizontal';
134134
}
135+
if (child1 && firstChildCSS.float !== 'none') {
136+
var touchingSideChild2 = firstChildCSS.float === 'left' ? 'left' : 'right';
137+
138+
return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ?
139+
'vertical' : 'horizontal';
140+
}
135141
return (child1 &&
136142
(
137-
child1.style.display === 'block' || // getComputedStyle() gives 'block' when 'inline-block'
143+
firstChildCSS.display === 'block' ||
138144
firstChildCSS.display === 'flex' ||
139145
firstChildCSS.display === 'table' ||
140146
firstChildCSS.display === 'grid' ||
@@ -1923,15 +1929,17 @@
19231929
}
19241930

19251931
/**
1926-
* Gets the last child in the el, ignoring ghostEl
1932+
* Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
19271933
* @param {HTMLElement} el Parent element
19281934
* @return {HTMLElement} The last child, ignoring ghostEl
19291935
*/
19301936
function _lastChild(el) {
19311937
var last = el.lastElementChild;
19321938

1933-
if (last === ghostEl) {
1934-
last = el.children[el.childElementCount - 2];
1939+
while (last === ghostEl || last.style.display === 'none') {
1940+
last = last.previousElementSibling;
1941+
1942+
if (!last) break;
19351943
}
19361944

19371945
return last || null;
@@ -1943,12 +1951,13 @@
19431951
mouseOnOppAxis = axis === 'vertical' ? evt.clientX : evt.clientY,
19441952
targetS2 = axis === 'vertical' ? elRect.bottom : elRect.right,
19451953
targetS1Opp = axis === 'vertical' ? elRect.left : elRect.top,
1946-
targetS2Opp = axis === 'vertical' ? elRect.right : elRect.bottom;
1954+
targetS2Opp = axis === 'vertical' ? elRect.right : elRect.bottom,
1955+
spacer = 10;
19471956

19481957
return (
1949-
mouseOnOppAxis > targetS1Opp &&
1950-
mouseOnOppAxis < targetS2Opp &&
1951-
mouseOnAxis > targetS2
1958+
axis === 'vertical' ?
1959+
(mouseOnOppAxis > targetS2Opp + spacer || mouseOnOppAxis <= targetS2Opp && mouseOnAxis > targetS2 && mouseOnOppAxis >= targetS1Opp) :
1960+
(mouseOnAxis > targetS2 && mouseOnOppAxis > targetS1Opp || mouseOnAxis <= targetS2 && mouseOnOppAxis > targetS2Opp + spacer)
19521961
);
19531962
}
19541963

0 commit comments

Comments
 (0)