MCPcopy Index your code
hub / github.com/SortableJS/Sortable / _detectDirection

Function _detectDirection

src/Sortable.js:163–207  ·  view source on GitHub ↗
(el, options)

Source from the content-addressed store, hash-verified

161 })(),
162
163 _detectDirection = function(el, options) {
164 let elCSS = css(el),
165 elWidth = parseInt(elCSS.width)
166 - parseInt(elCSS.paddingLeft)
167 - parseInt(elCSS.paddingRight)
168 - parseInt(elCSS.borderLeftWidth)
169 - parseInt(elCSS.borderRightWidth),
170 child1 = getChild(el, 0, options),
171 child2 = getChild(el, 1, options),
172 firstChildCSS = child1 && css(child1),
173 secondChildCSS = child2 && css(child2),
174 firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width,
175 secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + getRect(child2).width;
176
177 if (elCSS.display === 'flex') {
178 return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse'
179 ? 'vertical' : 'horizontal';
180 }
181
182 if (elCSS.display === 'grid') {
183 return elCSS.gridTemplateColumns.split(' ').length <= 1 ? 'vertical' : 'horizontal';
184 }
185
186 if (child1 && firstChildCSS.float && firstChildCSS.float !== 'none') {
187 let touchingSideChild2 = firstChildCSS.float === 'left' ? 'left' : 'right';
188
189 return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ?
190 'vertical' : 'horizontal';
191 }
192
193 return (child1 &&
194 (
195 firstChildCSS.display === 'block' ||
196 firstChildCSS.display === 'flex' ||
197 firstChildCSS.display === 'table' ||
198 firstChildCSS.display === 'grid' ||
199 firstChildWidth >= elWidth &&
200 elCSS[CSSFloatProperty] === 'none' ||
201 child2 &&
202 elCSS[CSSFloatProperty] === 'none' &&
203 firstChildWidth + secondChildWidth > elWidth
204 ) ?
205 'vertical' : 'horizontal'
206 );
207 },
208
209 _dragElInRowColumn = function(dragRect, targetRect, vertical) {
210 let dragElS1Opp = vertical ? dragRect.left : dragRect.top,

Callers 1

SortableFunction · 0.70

Calls 3

cssFunction · 0.90
getChildFunction · 0.90
getRectFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…