summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/boards/mixins/sortable_default_options.js
blob: c9cde4effb99d42e01cde9a6a4208820a65f0402 (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 $ from 'jquery';
import sortableConfig from '../../sortable/sortable_config';

export function sortableStart() {
  $('.has-tooltip').tooltip('hide')
    .tooltip('disable');
  document.body.classList.add('is-dragging');
}

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

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

  const defaultSortOptions = Object.assign({}, sortableConfig, {
    filter: '.board-delete, .btn',
    delay: touchEnabled ? 100 : 0,
    scrollSensitivity: touchEnabled ? 60 : 100,
    scrollSpeed: 20,
    onStart: sortableStart,
    onEnd: sortableEnd,
  });

  Object.keys(obj).forEach((key) => { defaultSortOptions[key] = obj[key]; });
  return defaultSortOptions;
}