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

Function _getSwapDirection

src/Sortable.js:1832–1901  ·  view source on GitHub ↗
(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget)

Source from the content-addressed store, hash-verified

1830}
1831
1832function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
1833 let mouseOnAxis = vertical ? evt.clientY : evt.clientX,
1834 targetLength = vertical ? targetRect.height : targetRect.width,
1835 targetS1 = vertical ? targetRect.top : targetRect.left,
1836 targetS2 = vertical ? targetRect.bottom : targetRect.right,
1837 invert = false;
1838
1839
1840 if (!invertSwap) {
1841 // Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
1842 if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) { // multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
1843 // check if past first invert threshold on side opposite of lastDirection
1844 if (!pastFirstInvertThresh &&
1845 (lastDirection === 1 ?
1846 (
1847 mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2
1848 ) :
1849 (
1850 mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2
1851 )
1852 )
1853 )
1854 {
1855 // past first invert threshold, do not restrict inverted threshold to dragEl shadow
1856 pastFirstInvertThresh = true;
1857 }
1858
1859 if (!pastFirstInvertThresh) {
1860 // dragEl shadow (target move distance shadow)
1861 if (
1862 lastDirection === 1 ?
1863 (
1864 mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
1865 ) :
1866 (
1867 mouseOnAxis > targetS2 - targetMoveDistance
1868 )
1869 )
1870 {
1871 return -lastDirection;
1872 }
1873 } else {
1874 invert = true;
1875 }
1876 } else {
1877 // Regular
1878 if (
1879 mouseOnAxis > targetS1 + (targetLength * (1 - swapThreshold) / 2) &&
1880 mouseOnAxis < targetS2 - (targetLength * (1 - swapThreshold) / 2)
1881 ) {
1882 return _getInsertDirection(target);
1883 }
1884 }
1885 }
1886
1887 invert = invert || invertSwap;
1888
1889 if (invert) {

Callers 1

Sortable.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…