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

Function _getSwapDirection

modular/sortable.esm.js:2257–2296  ·  view source on GitHub ↗
(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget)

Source from the content-addressed store, hash-verified

2255 return vertical ? evt.clientX > childContainingRect.right + spacer || evt.clientY > lastElRect.bottom && evt.clientX > lastElRect.left : evt.clientY > childContainingRect.bottom + spacer || evt.clientX > lastElRect.right && evt.clientY > lastElRect.top;
2256}
2257function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
2258 var mouseOnAxis = vertical ? evt.clientY : evt.clientX,
2259 targetLength = vertical ? targetRect.height : targetRect.width,
2260 targetS1 = vertical ? targetRect.top : targetRect.left,
2261 targetS2 = vertical ? targetRect.bottom : targetRect.right,
2262 invert = false;
2263 if (!invertSwap) {
2264 // Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
2265 if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) {
2266 // multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
2267 // check if past first invert threshold on side opposite of lastDirection
2268 if (!pastFirstInvertThresh && (lastDirection === 1 ? mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2 : mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2)) {
2269 // past first invert threshold, do not restrict inverted threshold to dragEl shadow
2270 pastFirstInvertThresh = true;
2271 }
2272 if (!pastFirstInvertThresh) {
2273 // dragEl shadow (target move distance shadow)
2274 if (lastDirection === 1 ? mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
2275 : mouseOnAxis > targetS2 - targetMoveDistance) {
2276 return -lastDirection;
2277 }
2278 } else {
2279 invert = true;
2280 }
2281 } else {
2282 // Regular
2283 if (mouseOnAxis > targetS1 + targetLength * (1 - swapThreshold) / 2 && mouseOnAxis < targetS2 - targetLength * (1 - swapThreshold) / 2) {
2284 return _getInsertDirection(target);
2285 }
2286 }
2287 }
2288 invert = invert || invertSwap;
2289 if (invert) {
2290 // Invert of regular
2291 if (mouseOnAxis < targetS1 + targetLength * invertedSwapThreshold / 2 || mouseOnAxis > targetS2 - targetLength * invertedSwapThreshold / 2) {
2292 return mouseOnAxis > targetS1 + targetLength / 2 ? 1 : -1;
2293 }
2294 }
2295 return 0;
2296}
2297
2298/**
2299 * Gets the direction dragEl must be swapped relative to target in order to make it

Callers 1

sortable.esm.jsFile · 0.70

Calls 1

_getInsertDirectionFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…