Skip to content

Commit

Permalink
#1451: Detect grid direction
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-m1 committed Feb 16, 2019
1 parent 047f94e commit deefe8d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,34 @@

_detectDirection = function(el, options) {
var elCSS = _css(el),
elWidth = parseInt(elCSS.width),
elWidth = parseInt(elCSS.width)
- parseInt(elCSS.paddingLeft)
- parseInt(elCSS.paddingRight)
- parseInt(elCSS.borderLeftWidth)
- parseInt(elCSS.borderRightWidth),
child1 = _getChild(el, 0, options),
child2 = _getChild(el, 1, options),
firstChildCSS = child1 && _css(child1),
secondChildCSS = child2 && _css(child2),
firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + _getRect(child1).width,
secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + _getRect(child2).width;

if (elCSS.display === 'flex') {
return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse'
? 'vertical' : 'horizontal';
}

if (elCSS.display === 'grid') {
return elCSS.gridTemplateColumns.split(' ').length <= 1 ? '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 &&
(
firstChildCSS.display === 'block' ||
Expand Down

0 comments on commit deefe8d

Please sign in to comment.