2017-08-17 22:00:37 +05:30
|
|
|
/* global DocumentTouch */
|
|
|
|
|
2022-07-16 23:28:13 +05:30
|
|
|
import { defaultSortableOptions, DRAG_CLASS } from './constants';
|
2018-03-27 19:54:05 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
export function sortableStart() {
|
2022-07-16 23:28:13 +05:30
|
|
|
document.body.classList.add(DRAG_CLASS);
|
2018-12-13 13:39:08 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
export function sortableEnd() {
|
2022-07-16 23:28:13 +05:30
|
|
|
document.body.classList.remove(DRAG_CLASS);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isDragging() {
|
|
|
|
return document.body.classList.contains(DRAG_CLASS);
|
2018-12-13 13:39:08 +05:30
|
|
|
}
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
export function getSortableDefaultOptions(options) {
|
2018-12-13 13:39:08 +05:30
|
|
|
const touchEnabled =
|
|
|
|
'ontouchstart' in window || (window.DocumentTouch && document instanceof DocumentTouch);
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2020-05-24 23:13:21 +05:30
|
|
|
const defaultSortOptions = {
|
2022-06-21 17:19:12 +05:30
|
|
|
...defaultSortableOptions,
|
2019-09-30 21:07:59 +05:30
|
|
|
filter: '.no-drag',
|
2018-12-13 13:39:08 +05:30
|
|
|
delay: touchEnabled ? 100 : 0,
|
|
|
|
scrollSensitivity: touchEnabled ? 60 : 100,
|
2017-08-17 22:00:37 +05:30
|
|
|
scrollSpeed: 20,
|
2018-12-13 13:39:08 +05:30
|
|
|
onStart: sortableStart,
|
|
|
|
onEnd: sortableEnd,
|
2020-05-24 23:13:21 +05:30
|
|
|
};
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
return {
|
|
|
|
...defaultSortOptions,
|
|
|
|
...options,
|
|
|
|
};
|
2018-12-13 13:39:08 +05:30
|
|
|
}
|