2016-12-13 22:01:05 -05:00
|
|
|
/* global DocumentTouch */
|
|
|
|
|
2022-05-17 08:08:06 -04:00
|
|
|
import { defaultSortableOptions, DRAG_CLASS } from './constants';
|
2018-02-19 14:06:16 -05:00
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
export function sortableStart() {
|
2022-05-17 08:08:06 -04:00
|
|
|
document.body.classList.add(DRAG_CLASS);
|
2018-10-10 13:08:43 -04:00
|
|
|
}
|
2016-08-19 05:09:22 -04:00
|
|
|
|
2018-10-10 13:08:43 -04:00
|
|
|
export function sortableEnd() {
|
2022-05-17 08:08:06 -04:00
|
|
|
document.body.classList.remove(DRAG_CLASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isDragging() {
|
|
|
|
return document.body.classList.contains(DRAG_CLASS);
|
2018-10-10 13:08:43 -04:00
|
|
|
}
|
2016-08-19 09:16:07 -04:00
|
|
|
|
2022-04-07 14:08:29 -04:00
|
|
|
export function getSortableDefaultOptions(options) {
|
2018-10-30 16:28:31 -04:00
|
|
|
const touchEnabled =
|
|
|
|
'ontouchstart' in window || (window.DocumentTouch && document instanceof DocumentTouch);
|
2016-08-11 04:51:52 -04:00
|
|
|
|
2020-05-07 17:09:26 -04:00
|
|
|
const defaultSortOptions = {
|
2022-04-07 14:08:29 -04:00
|
|
|
...defaultSortableOptions,
|
2019-06-28 17:20:05 -04:00
|
|
|
filter: '.no-drag',
|
2018-10-10 13:08:43 -04:00
|
|
|
delay: touchEnabled ? 100 : 0,
|
|
|
|
scrollSensitivity: touchEnabled ? 60 : 100,
|
2017-04-10 19:52:46 -04:00
|
|
|
scrollSpeed: 20,
|
2018-10-10 13:08:43 -04:00
|
|
|
onStart: sortableStart,
|
|
|
|
onEnd: sortableEnd,
|
2020-05-07 17:09:26 -04:00
|
|
|
};
|
2017-04-10 19:52:46 -04:00
|
|
|
|
2022-04-07 14:08:29 -04:00
|
|
|
return {
|
|
|
|
...defaultSortOptions,
|
|
|
|
...options,
|
|
|
|
};
|
2018-10-10 13:08:43 -04:00
|
|
|
}
|