summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sortable/utils.js
blob: c2c8fb03b586bd2687b2ec88de81bef51a7fe499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* global DocumentTouch */

import { defaultSortableOptions } from './constants';

export function sortableStart() {
  document.body.classList.add('is-dragging');
}

export function sortableEnd() {
  document.body.classList.remove('is-dragging');
}

export function getSortableDefaultOptions(options) {
  const touchEnabled =
    'ontouchstart' in window || (window.DocumentTouch && document instanceof DocumentTouch);

  const defaultSortOptions = {
    ...defaultSortableOptions,
    filter: '.no-drag',
    delay: touchEnabled ? 100 : 0,
    scrollSensitivity: touchEnabled ? 60 : 100,
    scrollSpeed: 20,
    onStart: sortableStart,
    onEnd: sortableEnd,
  };

  return {
    ...defaultSortOptions,
    ...options,
  };
}