effective_bootstrap 0.9.26 → 0.9.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e42c10612075097b95b71535673810ecdb5b56acd8e75a81c338085387979d72
4
- data.tar.gz: 2a95a8dde9b9adf39323776422ac2e6f5c5cd9bbb7873f42b9c6ea964c619273
3
+ metadata.gz: e0eb3c57699c01f64fa4ea1f07fd6bca82b2e45a162990acec7d039deede2c71
4
+ data.tar.gz: 95c371e51aa14ee0835a723f6382f4d10cf560fc19047b07e7edd68fec175e95
5
5
  SHA512:
6
- metadata.gz: a9decc8c9546fe8e0b619ced1ae5b9d6ebcd255ab457b027eb45e8121fd00989c67ed53827c066a969b4db4ccf6f4d54553aaffdfc209ed4ee71d8e5af7dd07f
7
- data.tar.gz: 773daa93f0f5fb230ad731bad85b561c948ac8b2c3b48335706f334dc4d3f227a42aff19292a1da2fd761537761f50479fd9a94ff1b1868fe9dc6d7acb46e92a
6
+ metadata.gz: 2cd4b274850c2ea38bf4a2a2ec258ff1cc6237a05a3b654e5932803dc7ccc835bad49dcb9f775b2484a8bfa7f16e813f5949241a511080c94afc0eba3fa9c4a1
7
+ data.tar.gz: 3287932f062dff615f80b3e1ab821b10f726975cf57df3bd16df338c70233ddbeb8ff9133051e152e125f0fa2dc78ef30af35a28f38e039ef0871853d5f0576d
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M496 288H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16zm0-128H16c-8.8 0-16 7.2-16 16v32c0 8.8 7.2 16 16 16h480c8.8 0 16-7.2 16-16v-32c0-8.8-7.2-16-16-16z"/></svg>
@@ -17,15 +17,13 @@ assignPositions = (target) ->
17
17
 
18
18
  (this.EffectiveBootstrap || {}).effective_has_many = ($element, options) ->
19
19
  if options.sortable
20
- $element.sortable(
21
- containerSelector: '.form-has-many',
22
- itemSelector: '.has-many-fields',
23
- handle: '.has-many-move'
24
- placeholder: "<div class='has-many-placeholder' />",
25
- onDrop: ($item, container, _super) =>
26
- assignPositions(container.target)
27
- _super($item, container)
28
- )
20
+ # https://github.com/SortableJS/Sortable
21
+ $element.sortable({
22
+ animation: 150,
23
+ draggable: '.has-many-fields',
24
+ handle: '.has-many-move',
25
+ onEnd: (event) => assignPositions(event.to)
26
+ })
29
27
 
30
28
  $(document).on 'click', '[data-effective-form-has-many-add]', (event) ->
31
29
  event.preventDefault()
@@ -44,6 +42,9 @@ $(document).on 'click', '[data-effective-form-has-many-add]', (event) ->
44
42
  assignPositions($hasMany)
45
43
  true
46
44
 
45
+ $(document).on 'click', '[data-effective-form-has-many-remove-disabled]', (event) ->
46
+ event.preventDefault()
47
+
47
48
  $(document).on 'click', '[data-effective-form-has-many-remove]', (event) ->
48
49
  event.preventDefault()
49
50
 
@@ -1,2 +1,3 @@
1
- //= require ./jquery.sortable
1
+ //= require ./sortable
2
+ //= require ./sortable-jquery
2
3
  //= require ./initialize
@@ -0,0 +1,76 @@
1
+ (function (factory) {
2
+ "use strict";
3
+ var sortable,
4
+ jq,
5
+ _this = this
6
+ ;
7
+
8
+ if (typeof define === "function" && define.amd) {
9
+ try {
10
+ define(["sortablejs", "jquery"], function(Sortable, $) {
11
+ sortable = Sortable;
12
+ jq = $;
13
+ checkErrors();
14
+ factory(Sortable, $);
15
+ });
16
+ } catch(err) {
17
+ checkErrors();
18
+ }
19
+ return;
20
+ } else if (typeof exports === 'object') {
21
+ try {
22
+ sortable = require('sortablejs');
23
+ jq = require('jquery');
24
+ } catch(err) { }
25
+ }
26
+
27
+ if (typeof jQuery === 'function' || typeof $ === 'function') {
28
+ jq = jQuery || $;
29
+ }
30
+
31
+ if (typeof Sortable !== 'undefined') {
32
+ sortable = Sortable;
33
+ }
34
+
35
+ function checkErrors() {
36
+ if (!jq) {
37
+ throw new Error('jQuery is required for jquery-sortablejs');
38
+ }
39
+
40
+ if (!sortable) {
41
+ throw new Error('SortableJS is required for jquery-sortablejs (https://github.com/SortableJS/Sortable)');
42
+ }
43
+ }
44
+ checkErrors();
45
+ factory(sortable, jq);
46
+ })(function (Sortable, $) {
47
+ "use strict";
48
+
49
+ $.fn.sortable = function (options) {
50
+ var retVal,
51
+ args = arguments;
52
+
53
+ this.each(function () {
54
+ var $el = $(this),
55
+ sortable = $el.data('sortable');
56
+
57
+ if (!sortable && (options instanceof Object || !options)) {
58
+ sortable = new Sortable(this, options);
59
+ $el.data('sortable', sortable);
60
+ } else if (sortable) {
61
+ if (options === 'destroy') {
62
+ sortable.destroy();
63
+ $el.removeData('sortable');
64
+ } else if (options === 'widget') {
65
+ retVal = sortable;
66
+ } else if (typeof sortable[options] === 'function') {
67
+ retVal = sortable[options].apply(sortable, [].slice.call(args, 1));
68
+ } else if (options in sortable.options) {
69
+ retVal = sortable.option.apply(sortable, args);
70
+ }
71
+ }
72
+ });
73
+
74
+ return (retVal === void 0) ? this : retVal;
75
+ };
76
+ });
@@ -0,0 +1,3722 @@
1
+ /**!
2
+ * https://github.com/SortableJS/Sortable
3
+ * Sortable 1.13.0
4
+ * @author RubaXa <trash@rubaxa.org>
5
+ * @author owenm <owen23355@gmail.com>
6
+ * @license MIT
7
+ */
8
+ (function (global, factory) {
9
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
10
+ typeof define === 'function' && define.amd ? define(factory) :
11
+ (global = global || self, global.Sortable = factory());
12
+ }(this, function () { 'use strict';
13
+
14
+ function _typeof(obj) {
15
+ if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
16
+ _typeof = function (obj) {
17
+ return typeof obj;
18
+ };
19
+ } else {
20
+ _typeof = function (obj) {
21
+ return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
22
+ };
23
+ }
24
+
25
+ return _typeof(obj);
26
+ }
27
+
28
+ function _defineProperty(obj, key, value) {
29
+ if (key in obj) {
30
+ Object.defineProperty(obj, key, {
31
+ value: value,
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true
35
+ });
36
+ } else {
37
+ obj[key] = value;
38
+ }
39
+
40
+ return obj;
41
+ }
42
+
43
+ function _extends() {
44
+ _extends = Object.assign || function (target) {
45
+ for (var i = 1; i < arguments.length; i++) {
46
+ var source = arguments[i];
47
+
48
+ for (var key in source) {
49
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
50
+ target[key] = source[key];
51
+ }
52
+ }
53
+ }
54
+
55
+ return target;
56
+ };
57
+
58
+ return _extends.apply(this, arguments);
59
+ }
60
+
61
+ function _objectSpread(target) {
62
+ for (var i = 1; i < arguments.length; i++) {
63
+ var source = arguments[i] != null ? arguments[i] : {};
64
+ var ownKeys = Object.keys(source);
65
+
66
+ if (typeof Object.getOwnPropertySymbols === 'function') {
67
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
68
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
69
+ }));
70
+ }
71
+
72
+ ownKeys.forEach(function (key) {
73
+ _defineProperty(target, key, source[key]);
74
+ });
75
+ }
76
+
77
+ return target;
78
+ }
79
+
80
+ function _objectWithoutPropertiesLoose(source, excluded) {
81
+ if (source == null) return {};
82
+ var target = {};
83
+ var sourceKeys = Object.keys(source);
84
+ var key, i;
85
+
86
+ for (i = 0; i < sourceKeys.length; i++) {
87
+ key = sourceKeys[i];
88
+ if (excluded.indexOf(key) >= 0) continue;
89
+ target[key] = source[key];
90
+ }
91
+
92
+ return target;
93
+ }
94
+
95
+ function _objectWithoutProperties(source, excluded) {
96
+ if (source == null) return {};
97
+
98
+ var target = _objectWithoutPropertiesLoose(source, excluded);
99
+
100
+ var key, i;
101
+
102
+ if (Object.getOwnPropertySymbols) {
103
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
104
+
105
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
106
+ key = sourceSymbolKeys[i];
107
+ if (excluded.indexOf(key) >= 0) continue;
108
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
109
+ target[key] = source[key];
110
+ }
111
+ }
112
+
113
+ return target;
114
+ }
115
+
116
+ function _toConsumableArray(arr) {
117
+ return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread();
118
+ }
119
+
120
+ function _arrayWithoutHoles(arr) {
121
+ if (Array.isArray(arr)) {
122
+ for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i];
123
+
124
+ return arr2;
125
+ }
126
+ }
127
+
128
+ function _iterableToArray(iter) {
129
+ if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
130
+ }
131
+
132
+ function _nonIterableSpread() {
133
+ throw new TypeError("Invalid attempt to spread non-iterable instance");
134
+ }
135
+
136
+ var version = "1.13.0";
137
+
138
+ function userAgent(pattern) {
139
+ if (typeof window !== 'undefined' && window.navigator) {
140
+ return !!
141
+ /*@__PURE__*/
142
+ navigator.userAgent.match(pattern);
143
+ }
144
+ }
145
+
146
+ var IE11OrLess = userAgent(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i);
147
+ var Edge = userAgent(/Edge/i);
148
+ var FireFox = userAgent(/firefox/i);
149
+ var Safari = userAgent(/safari/i) && !userAgent(/chrome/i) && !userAgent(/android/i);
150
+ var IOS = userAgent(/iP(ad|od|hone)/i);
151
+ var ChromeForAndroid = userAgent(/chrome/i) && userAgent(/android/i);
152
+
153
+ var captureMode = {
154
+ capture: false,
155
+ passive: false
156
+ };
157
+
158
+ function on(el, event, fn) {
159
+ el.addEventListener(event, fn, !IE11OrLess && captureMode);
160
+ }
161
+
162
+ function off(el, event, fn) {
163
+ el.removeEventListener(event, fn, !IE11OrLess && captureMode);
164
+ }
165
+
166
+ function matches(
167
+ /**HTMLElement*/
168
+ el,
169
+ /**String*/
170
+ selector) {
171
+ if (!selector) return;
172
+ selector[0] === '>' && (selector = selector.substring(1));
173
+
174
+ if (el) {
175
+ try {
176
+ if (el.matches) {
177
+ return el.matches(selector);
178
+ } else if (el.msMatchesSelector) {
179
+ return el.msMatchesSelector(selector);
180
+ } else if (el.webkitMatchesSelector) {
181
+ return el.webkitMatchesSelector(selector);
182
+ }
183
+ } catch (_) {
184
+ return false;
185
+ }
186
+ }
187
+
188
+ return false;
189
+ }
190
+
191
+ function getParentOrHost(el) {
192
+ return el.host && el !== document && el.host.nodeType ? el.host : el.parentNode;
193
+ }
194
+
195
+ function closest(
196
+ /**HTMLElement*/
197
+ el,
198
+ /**String*/
199
+ selector,
200
+ /**HTMLElement*/
201
+ ctx, includeCTX) {
202
+ if (el) {
203
+ ctx = ctx || document;
204
+
205
+ do {
206
+ if (selector != null && (selector[0] === '>' ? el.parentNode === ctx && matches(el, selector) : matches(el, selector)) || includeCTX && el === ctx) {
207
+ return el;
208
+ }
209
+
210
+ if (el === ctx) break;
211
+ /* jshint boss:true */
212
+ } while (el = getParentOrHost(el));
213
+ }
214
+
215
+ return null;
216
+ }
217
+
218
+ var R_SPACE = /\s+/g;
219
+
220
+ function toggleClass(el, name, state) {
221
+ if (el && name) {
222
+ if (el.classList) {
223
+ el.classList[state ? 'add' : 'remove'](name);
224
+ } else {
225
+ var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
226
+ el.className = (className + (state ? ' ' + name : '')).replace(R_SPACE, ' ');
227
+ }
228
+ }
229
+ }
230
+
231
+ function css(el, prop, val) {
232
+ var style = el && el.style;
233
+
234
+ if (style) {
235
+ if (val === void 0) {
236
+ if (document.defaultView && document.defaultView.getComputedStyle) {
237
+ val = document.defaultView.getComputedStyle(el, '');
238
+ } else if (el.currentStyle) {
239
+ val = el.currentStyle;
240
+ }
241
+
242
+ return prop === void 0 ? val : val[prop];
243
+ } else {
244
+ if (!(prop in style) && prop.indexOf('webkit') === -1) {
245
+ prop = '-webkit-' + prop;
246
+ }
247
+
248
+ style[prop] = val + (typeof val === 'string' ? '' : 'px');
249
+ }
250
+ }
251
+ }
252
+
253
+ function matrix(el, selfOnly) {
254
+ var appliedTransforms = '';
255
+
256
+ if (typeof el === 'string') {
257
+ appliedTransforms = el;
258
+ } else {
259
+ do {
260
+ var transform = css(el, 'transform');
261
+
262
+ if (transform && transform !== 'none') {
263
+ appliedTransforms = transform + ' ' + appliedTransforms;
264
+ }
265
+ /* jshint boss:true */
266
+
267
+ } while (!selfOnly && (el = el.parentNode));
268
+ }
269
+
270
+ var matrixFn = window.DOMMatrix || window.WebKitCSSMatrix || window.CSSMatrix || window.MSCSSMatrix;
271
+ /*jshint -W056 */
272
+
273
+ return matrixFn && new matrixFn(appliedTransforms);
274
+ }
275
+
276
+ function find(ctx, tagName, iterator) {
277
+ if (ctx) {
278
+ var list = ctx.getElementsByTagName(tagName),
279
+ i = 0,
280
+ n = list.length;
281
+
282
+ if (iterator) {
283
+ for (; i < n; i++) {
284
+ iterator(list[i], i);
285
+ }
286
+ }
287
+
288
+ return list;
289
+ }
290
+
291
+ return [];
292
+ }
293
+
294
+ function getWindowScrollingElement() {
295
+ var scrollingElement = document.scrollingElement;
296
+
297
+ if (scrollingElement) {
298
+ return scrollingElement;
299
+ } else {
300
+ return document.documentElement;
301
+ }
302
+ }
303
+ /**
304
+ * Returns the "bounding client rect" of given element
305
+ * @param {HTMLElement} el The element whose boundingClientRect is wanted
306
+ * @param {[Boolean]} relativeToContainingBlock Whether the rect should be relative to the containing block of (including) the container
307
+ * @param {[Boolean]} relativeToNonStaticParent Whether the rect should be relative to the relative parent of (including) the contaienr
308
+ * @param {[Boolean]} undoScale Whether the container's scale() should be undone
309
+ * @param {[HTMLElement]} container The parent the element will be placed in
310
+ * @return {Object} The boundingClientRect of el, with specified adjustments
311
+ */
312
+
313
+
314
+ function getRect(el, relativeToContainingBlock, relativeToNonStaticParent, undoScale, container) {
315
+ if (!el.getBoundingClientRect && el !== window) return;
316
+ var elRect, top, left, bottom, right, height, width;
317
+
318
+ if (el !== window && el.parentNode && el !== getWindowScrollingElement()) {
319
+ elRect = el.getBoundingClientRect();
320
+ top = elRect.top;
321
+ left = elRect.left;
322
+ bottom = elRect.bottom;
323
+ right = elRect.right;
324
+ height = elRect.height;
325
+ width = elRect.width;
326
+ } else {
327
+ top = 0;
328
+ left = 0;
329
+ bottom = window.innerHeight;
330
+ right = window.innerWidth;
331
+ height = window.innerHeight;
332
+ width = window.innerWidth;
333
+ }
334
+
335
+ if ((relativeToContainingBlock || relativeToNonStaticParent) && el !== window) {
336
+ // Adjust for translate()
337
+ container = container || el.parentNode; // solves #1123 (see: https://stackoverflow.com/a/37953806/6088312)
338
+ // Not needed on <= IE11
339
+
340
+ if (!IE11OrLess) {
341
+ do {
342
+ if (container && container.getBoundingClientRect && (css(container, 'transform') !== 'none' || relativeToNonStaticParent && css(container, 'position') !== 'static')) {
343
+ var containerRect = container.getBoundingClientRect(); // Set relative to edges of padding box of container
344
+
345
+ top -= containerRect.top + parseInt(css(container, 'border-top-width'));
346
+ left -= containerRect.left + parseInt(css(container, 'border-left-width'));
347
+ bottom = top + elRect.height;
348
+ right = left + elRect.width;
349
+ break;
350
+ }
351
+ /* jshint boss:true */
352
+
353
+ } while (container = container.parentNode);
354
+ }
355
+ }
356
+
357
+ if (undoScale && el !== window) {
358
+ // Adjust for scale()
359
+ var elMatrix = matrix(container || el),
360
+ scaleX = elMatrix && elMatrix.a,
361
+ scaleY = elMatrix && elMatrix.d;
362
+
363
+ if (elMatrix) {
364
+ top /= scaleY;
365
+ left /= scaleX;
366
+ width /= scaleX;
367
+ height /= scaleY;
368
+ bottom = top + height;
369
+ right = left + width;
370
+ }
371
+ }
372
+
373
+ return {
374
+ top: top,
375
+ left: left,
376
+ bottom: bottom,
377
+ right: right,
378
+ width: width,
379
+ height: height
380
+ };
381
+ }
382
+ /**
383
+ * Checks if a side of an element is scrolled past a side of its parents
384
+ * @param {HTMLElement} el The element who's side being scrolled out of view is in question
385
+ * @param {String} elSide Side of the element in question ('top', 'left', 'right', 'bottom')
386
+ * @param {String} parentSide Side of the parent in question ('top', 'left', 'right', 'bottom')
387
+ * @return {HTMLElement} The parent scroll element that the el's side is scrolled past, or null if there is no such element
388
+ */
389
+
390
+
391
+ function isScrolledPast(el, elSide, parentSide) {
392
+ var parent = getParentAutoScrollElement(el, true),
393
+ elSideVal = getRect(el)[elSide];
394
+ /* jshint boss:true */
395
+
396
+ while (parent) {
397
+ var parentSideVal = getRect(parent)[parentSide],
398
+ visible = void 0;
399
+
400
+ if (parentSide === 'top' || parentSide === 'left') {
401
+ visible = elSideVal >= parentSideVal;
402
+ } else {
403
+ visible = elSideVal <= parentSideVal;
404
+ }
405
+
406
+ if (!visible) return parent;
407
+ if (parent === getWindowScrollingElement()) break;
408
+ parent = getParentAutoScrollElement(parent, false);
409
+ }
410
+
411
+ return false;
412
+ }
413
+ /**
414
+ * Gets nth child of el, ignoring hidden children, sortable's elements (does not ignore clone if it's visible)
415
+ * and non-draggable elements
416
+ * @param {HTMLElement} el The parent element
417
+ * @param {Number} childNum The index of the child
418
+ * @param {Object} options Parent Sortable's options
419
+ * @return {HTMLElement} The child at index childNum, or null if not found
420
+ */
421
+
422
+
423
+ function getChild(el, childNum, options) {
424
+ var currentChild = 0,
425
+ i = 0,
426
+ children = el.children;
427
+
428
+ while (i < children.length) {
429
+ if (children[i].style.display !== 'none' && children[i] !== Sortable.ghost && children[i] !== Sortable.dragged && closest(children[i], options.draggable, el, false)) {
430
+ if (currentChild === childNum) {
431
+ return children[i];
432
+ }
433
+
434
+ currentChild++;
435
+ }
436
+
437
+ i++;
438
+ }
439
+
440
+ return null;
441
+ }
442
+ /**
443
+ * Gets the last child in the el, ignoring ghostEl or invisible elements (clones)
444
+ * @param {HTMLElement} el Parent element
445
+ * @param {selector} selector Any other elements that should be ignored
446
+ * @return {HTMLElement} The last child, ignoring ghostEl
447
+ */
448
+
449
+
450
+ function lastChild(el, selector) {
451
+ var last = el.lastElementChild;
452
+
453
+ while (last && (last === Sortable.ghost || css(last, 'display') === 'none' || selector && !matches(last, selector))) {
454
+ last = last.previousElementSibling;
455
+ }
456
+
457
+ return last || null;
458
+ }
459
+ /**
460
+ * Returns the index of an element within its parent for a selected set of
461
+ * elements
462
+ * @param {HTMLElement} el
463
+ * @param {selector} selector
464
+ * @return {number}
465
+ */
466
+
467
+
468
+ function index(el, selector) {
469
+ var index = 0;
470
+
471
+ if (!el || !el.parentNode) {
472
+ return -1;
473
+ }
474
+ /* jshint boss:true */
475
+
476
+
477
+ while (el = el.previousElementSibling) {
478
+ if (el.nodeName.toUpperCase() !== 'TEMPLATE' && el !== Sortable.clone && (!selector || matches(el, selector))) {
479
+ index++;
480
+ }
481
+ }
482
+
483
+ return index;
484
+ }
485
+ /**
486
+ * Returns the scroll offset of the given element, added with all the scroll offsets of parent elements.
487
+ * The value is returned in real pixels.
488
+ * @param {HTMLElement} el
489
+ * @return {Array} Offsets in the format of [left, top]
490
+ */
491
+
492
+
493
+ function getRelativeScrollOffset(el) {
494
+ var offsetLeft = 0,
495
+ offsetTop = 0,
496
+ winScroller = getWindowScrollingElement();
497
+
498
+ if (el) {
499
+ do {
500
+ var elMatrix = matrix(el),
501
+ scaleX = elMatrix.a,
502
+ scaleY = elMatrix.d;
503
+ offsetLeft += el.scrollLeft * scaleX;
504
+ offsetTop += el.scrollTop * scaleY;
505
+ } while (el !== winScroller && (el = el.parentNode));
506
+ }
507
+
508
+ return [offsetLeft, offsetTop];
509
+ }
510
+ /**
511
+ * Returns the index of the object within the given array
512
+ * @param {Array} arr Array that may or may not hold the object
513
+ * @param {Object} obj An object that has a key-value pair unique to and identical to a key-value pair in the object you want to find
514
+ * @return {Number} The index of the object in the array, or -1
515
+ */
516
+
517
+
518
+ function indexOfObject(arr, obj) {
519
+ for (var i in arr) {
520
+ if (!arr.hasOwnProperty(i)) continue;
521
+
522
+ for (var key in obj) {
523
+ if (obj.hasOwnProperty(key) && obj[key] === arr[i][key]) return Number(i);
524
+ }
525
+ }
526
+
527
+ return -1;
528
+ }
529
+
530
+ function getParentAutoScrollElement(el, includeSelf) {
531
+ // skip to window
532
+ if (!el || !el.getBoundingClientRect) return getWindowScrollingElement();
533
+ var elem = el;
534
+ var gotSelf = false;
535
+
536
+ do {
537
+ // we don't need to get elem css if it isn't even overflowing in the first place (performance)
538
+ if (elem.clientWidth < elem.scrollWidth || elem.clientHeight < elem.scrollHeight) {
539
+ var elemCSS = css(elem);
540
+
541
+ if (elem.clientWidth < elem.scrollWidth && (elemCSS.overflowX == 'auto' || elemCSS.overflowX == 'scroll') || elem.clientHeight < elem.scrollHeight && (elemCSS.overflowY == 'auto' || elemCSS.overflowY == 'scroll')) {
542
+ if (!elem.getBoundingClientRect || elem === document.body) return getWindowScrollingElement();
543
+ if (gotSelf || includeSelf) return elem;
544
+ gotSelf = true;
545
+ }
546
+ }
547
+ /* jshint boss:true */
548
+
549
+ } while (elem = elem.parentNode);
550
+
551
+ return getWindowScrollingElement();
552
+ }
553
+
554
+ function extend(dst, src) {
555
+ if (dst && src) {
556
+ for (var key in src) {
557
+ if (src.hasOwnProperty(key)) {
558
+ dst[key] = src[key];
559
+ }
560
+ }
561
+ }
562
+
563
+ return dst;
564
+ }
565
+
566
+ function isRectEqual(rect1, rect2) {
567
+ return Math.round(rect1.top) === Math.round(rect2.top) && Math.round(rect1.left) === Math.round(rect2.left) && Math.round(rect1.height) === Math.round(rect2.height) && Math.round(rect1.width) === Math.round(rect2.width);
568
+ }
569
+
570
+ var _throttleTimeout;
571
+
572
+ function throttle(callback, ms) {
573
+ return function () {
574
+ if (!_throttleTimeout) {
575
+ var args = arguments,
576
+ _this = this;
577
+
578
+ if (args.length === 1) {
579
+ callback.call(_this, args[0]);
580
+ } else {
581
+ callback.apply(_this, args);
582
+ }
583
+
584
+ _throttleTimeout = setTimeout(function () {
585
+ _throttleTimeout = void 0;
586
+ }, ms);
587
+ }
588
+ };
589
+ }
590
+
591
+ function cancelThrottle() {
592
+ clearTimeout(_throttleTimeout);
593
+ _throttleTimeout = void 0;
594
+ }
595
+
596
+ function scrollBy(el, x, y) {
597
+ el.scrollLeft += x;
598
+ el.scrollTop += y;
599
+ }
600
+
601
+ function clone(el) {
602
+ var Polymer = window.Polymer;
603
+ var $ = window.jQuery || window.Zepto;
604
+
605
+ if (Polymer && Polymer.dom) {
606
+ return Polymer.dom(el).cloneNode(true);
607
+ } else if ($) {
608
+ return $(el).clone(true)[0];
609
+ } else {
610
+ return el.cloneNode(true);
611
+ }
612
+ }
613
+
614
+ function setRect(el, rect) {
615
+ css(el, 'position', 'absolute');
616
+ css(el, 'top', rect.top);
617
+ css(el, 'left', rect.left);
618
+ css(el, 'width', rect.width);
619
+ css(el, 'height', rect.height);
620
+ }
621
+
622
+ function unsetRect(el) {
623
+ css(el, 'position', '');
624
+ css(el, 'top', '');
625
+ css(el, 'left', '');
626
+ css(el, 'width', '');
627
+ css(el, 'height', '');
628
+ }
629
+
630
+ var expando = 'Sortable' + new Date().getTime();
631
+
632
+ function AnimationStateManager() {
633
+ var animationStates = [],
634
+ animationCallbackId;
635
+ return {
636
+ captureAnimationState: function captureAnimationState() {
637
+ animationStates = [];
638
+ if (!this.options.animation) return;
639
+ var children = [].slice.call(this.el.children);
640
+ children.forEach(function (child) {
641
+ if (css(child, 'display') === 'none' || child === Sortable.ghost) return;
642
+ animationStates.push({
643
+ target: child,
644
+ rect: getRect(child)
645
+ });
646
+
647
+ var fromRect = _objectSpread({}, animationStates[animationStates.length - 1].rect); // If animating: compensate for current animation
648
+
649
+
650
+ if (child.thisAnimationDuration) {
651
+ var childMatrix = matrix(child, true);
652
+
653
+ if (childMatrix) {
654
+ fromRect.top -= childMatrix.f;
655
+ fromRect.left -= childMatrix.e;
656
+ }
657
+ }
658
+
659
+ child.fromRect = fromRect;
660
+ });
661
+ },
662
+ addAnimationState: function addAnimationState(state) {
663
+ animationStates.push(state);
664
+ },
665
+ removeAnimationState: function removeAnimationState(target) {
666
+ animationStates.splice(indexOfObject(animationStates, {
667
+ target: target
668
+ }), 1);
669
+ },
670
+ animateAll: function animateAll(callback) {
671
+ var _this = this;
672
+
673
+ if (!this.options.animation) {
674
+ clearTimeout(animationCallbackId);
675
+ if (typeof callback === 'function') callback();
676
+ return;
677
+ }
678
+
679
+ var animating = false,
680
+ animationTime = 0;
681
+ animationStates.forEach(function (state) {
682
+ var time = 0,
683
+ target = state.target,
684
+ fromRect = target.fromRect,
685
+ toRect = getRect(target),
686
+ prevFromRect = target.prevFromRect,
687
+ prevToRect = target.prevToRect,
688
+ animatingRect = state.rect,
689
+ targetMatrix = matrix(target, true);
690
+
691
+ if (targetMatrix) {
692
+ // Compensate for current animation
693
+ toRect.top -= targetMatrix.f;
694
+ toRect.left -= targetMatrix.e;
695
+ }
696
+
697
+ target.toRect = toRect;
698
+
699
+ if (target.thisAnimationDuration) {
700
+ // Could also check if animatingRect is between fromRect and toRect
701
+ if (isRectEqual(prevFromRect, toRect) && !isRectEqual(fromRect, toRect) && // Make sure animatingRect is on line between toRect & fromRect
702
+ (animatingRect.top - toRect.top) / (animatingRect.left - toRect.left) === (fromRect.top - toRect.top) / (fromRect.left - toRect.left)) {
703
+ // If returning to same place as started from animation and on same axis
704
+ time = calculateRealTime(animatingRect, prevFromRect, prevToRect, _this.options);
705
+ }
706
+ } // if fromRect != toRect: animate
707
+
708
+
709
+ if (!isRectEqual(toRect, fromRect)) {
710
+ target.prevFromRect = fromRect;
711
+ target.prevToRect = toRect;
712
+
713
+ if (!time) {
714
+ time = _this.options.animation;
715
+ }
716
+
717
+ _this.animate(target, animatingRect, toRect, time);
718
+ }
719
+
720
+ if (time) {
721
+ animating = true;
722
+ animationTime = Math.max(animationTime, time);
723
+ clearTimeout(target.animationResetTimer);
724
+ target.animationResetTimer = setTimeout(function () {
725
+ target.animationTime = 0;
726
+ target.prevFromRect = null;
727
+ target.fromRect = null;
728
+ target.prevToRect = null;
729
+ target.thisAnimationDuration = null;
730
+ }, time);
731
+ target.thisAnimationDuration = time;
732
+ }
733
+ });
734
+ clearTimeout(animationCallbackId);
735
+
736
+ if (!animating) {
737
+ if (typeof callback === 'function') callback();
738
+ } else {
739
+ animationCallbackId = setTimeout(function () {
740
+ if (typeof callback === 'function') callback();
741
+ }, animationTime);
742
+ }
743
+
744
+ animationStates = [];
745
+ },
746
+ animate: function animate(target, currentRect, toRect, duration) {
747
+ if (duration) {
748
+ css(target, 'transition', '');
749
+ css(target, 'transform', '');
750
+ var elMatrix = matrix(this.el),
751
+ scaleX = elMatrix && elMatrix.a,
752
+ scaleY = elMatrix && elMatrix.d,
753
+ translateX = (currentRect.left - toRect.left) / (scaleX || 1),
754
+ translateY = (currentRect.top - toRect.top) / (scaleY || 1);
755
+ target.animatingX = !!translateX;
756
+ target.animatingY = !!translateY;
757
+ css(target, 'transform', 'translate3d(' + translateX + 'px,' + translateY + 'px,0)');
758
+ this.forRepaintDummy = repaint(target); // repaint
759
+
760
+ css(target, 'transition', 'transform ' + duration + 'ms' + (this.options.easing ? ' ' + this.options.easing : ''));
761
+ css(target, 'transform', 'translate3d(0,0,0)');
762
+ typeof target.animated === 'number' && clearTimeout(target.animated);
763
+ target.animated = setTimeout(function () {
764
+ css(target, 'transition', '');
765
+ css(target, 'transform', '');
766
+ target.animated = false;
767
+ target.animatingX = false;
768
+ target.animatingY = false;
769
+ }, duration);
770
+ }
771
+ }
772
+ };
773
+ }
774
+
775
+ function repaint(target) {
776
+ return target.offsetWidth;
777
+ }
778
+
779
+ function calculateRealTime(animatingRect, fromRect, toRect, options) {
780
+ return Math.sqrt(Math.pow(fromRect.top - animatingRect.top, 2) + Math.pow(fromRect.left - animatingRect.left, 2)) / Math.sqrt(Math.pow(fromRect.top - toRect.top, 2) + Math.pow(fromRect.left - toRect.left, 2)) * options.animation;
781
+ }
782
+
783
+ var plugins = [];
784
+ var defaults = {
785
+ initializeByDefault: true
786
+ };
787
+ var PluginManager = {
788
+ mount: function mount(plugin) {
789
+ // Set default static properties
790
+ for (var option in defaults) {
791
+ if (defaults.hasOwnProperty(option) && !(option in plugin)) {
792
+ plugin[option] = defaults[option];
793
+ }
794
+ }
795
+
796
+ plugins.forEach(function (p) {
797
+ if (p.pluginName === plugin.pluginName) {
798
+ throw "Sortable: Cannot mount plugin ".concat(plugin.pluginName, " more than once");
799
+ }
800
+ });
801
+ plugins.push(plugin);
802
+ },
803
+ pluginEvent: function pluginEvent(eventName, sortable, evt) {
804
+ var _this = this;
805
+
806
+ this.eventCanceled = false;
807
+
808
+ evt.cancel = function () {
809
+ _this.eventCanceled = true;
810
+ };
811
+
812
+ var eventNameGlobal = eventName + 'Global';
813
+ plugins.forEach(function (plugin) {
814
+ if (!sortable[plugin.pluginName]) return; // Fire global events if it exists in this sortable
815
+
816
+ if (sortable[plugin.pluginName][eventNameGlobal]) {
817
+ sortable[plugin.pluginName][eventNameGlobal](_objectSpread({
818
+ sortable: sortable
819
+ }, evt));
820
+ } // Only fire plugin event if plugin is enabled in this sortable,
821
+ // and plugin has event defined
822
+
823
+
824
+ if (sortable.options[plugin.pluginName] && sortable[plugin.pluginName][eventName]) {
825
+ sortable[plugin.pluginName][eventName](_objectSpread({
826
+ sortable: sortable
827
+ }, evt));
828
+ }
829
+ });
830
+ },
831
+ initializePlugins: function initializePlugins(sortable, el, defaults, options) {
832
+ plugins.forEach(function (plugin) {
833
+ var pluginName = plugin.pluginName;
834
+ if (!sortable.options[pluginName] && !plugin.initializeByDefault) return;
835
+ var initialized = new plugin(sortable, el, sortable.options);
836
+ initialized.sortable = sortable;
837
+ initialized.options = sortable.options;
838
+ sortable[pluginName] = initialized; // Add default options from plugin
839
+
840
+ _extends(defaults, initialized.defaults);
841
+ });
842
+
843
+ for (var option in sortable.options) {
844
+ if (!sortable.options.hasOwnProperty(option)) continue;
845
+ var modified = this.modifyOption(sortable, option, sortable.options[option]);
846
+
847
+ if (typeof modified !== 'undefined') {
848
+ sortable.options[option] = modified;
849
+ }
850
+ }
851
+ },
852
+ getEventProperties: function getEventProperties(name, sortable) {
853
+ var eventProperties = {};
854
+ plugins.forEach(function (plugin) {
855
+ if (typeof plugin.eventProperties !== 'function') return;
856
+
857
+ _extends(eventProperties, plugin.eventProperties.call(sortable[plugin.pluginName], name));
858
+ });
859
+ return eventProperties;
860
+ },
861
+ modifyOption: function modifyOption(sortable, name, value) {
862
+ var modifiedValue;
863
+ plugins.forEach(function (plugin) {
864
+ // Plugin must exist on the Sortable
865
+ if (!sortable[plugin.pluginName]) return; // If static option listener exists for this option, call in the context of the Sortable's instance of this plugin
866
+
867
+ if (plugin.optionListeners && typeof plugin.optionListeners[name] === 'function') {
868
+ modifiedValue = plugin.optionListeners[name].call(sortable[plugin.pluginName], value);
869
+ }
870
+ });
871
+ return modifiedValue;
872
+ }
873
+ };
874
+
875
+ function dispatchEvent(_ref) {
876
+ var sortable = _ref.sortable,
877
+ rootEl = _ref.rootEl,
878
+ name = _ref.name,
879
+ targetEl = _ref.targetEl,
880
+ cloneEl = _ref.cloneEl,
881
+ toEl = _ref.toEl,
882
+ fromEl = _ref.fromEl,
883
+ oldIndex = _ref.oldIndex,
884
+ newIndex = _ref.newIndex,
885
+ oldDraggableIndex = _ref.oldDraggableIndex,
886
+ newDraggableIndex = _ref.newDraggableIndex,
887
+ originalEvent = _ref.originalEvent,
888
+ putSortable = _ref.putSortable,
889
+ extraEventProperties = _ref.extraEventProperties;
890
+ sortable = sortable || rootEl && rootEl[expando];
891
+ if (!sortable) return;
892
+ var evt,
893
+ options = sortable.options,
894
+ onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1); // Support for new CustomEvent feature
895
+
896
+ if (window.CustomEvent && !IE11OrLess && !Edge) {
897
+ evt = new CustomEvent(name, {
898
+ bubbles: true,
899
+ cancelable: true
900
+ });
901
+ } else {
902
+ evt = document.createEvent('Event');
903
+ evt.initEvent(name, true, true);
904
+ }
905
+
906
+ evt.to = toEl || rootEl;
907
+ evt.from = fromEl || rootEl;
908
+ evt.item = targetEl || rootEl;
909
+ evt.clone = cloneEl;
910
+ evt.oldIndex = oldIndex;
911
+ evt.newIndex = newIndex;
912
+ evt.oldDraggableIndex = oldDraggableIndex;
913
+ evt.newDraggableIndex = newDraggableIndex;
914
+ evt.originalEvent = originalEvent;
915
+ evt.pullMode = putSortable ? putSortable.lastPutMode : undefined;
916
+
917
+ var allEventProperties = _objectSpread({}, extraEventProperties, PluginManager.getEventProperties(name, sortable));
918
+
919
+ for (var option in allEventProperties) {
920
+ evt[option] = allEventProperties[option];
921
+ }
922
+
923
+ if (rootEl) {
924
+ rootEl.dispatchEvent(evt);
925
+ }
926
+
927
+ if (options[onName]) {
928
+ options[onName].call(sortable, evt);
929
+ }
930
+ }
931
+
932
+ var pluginEvent = function pluginEvent(eventName, sortable) {
933
+ var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {},
934
+ originalEvent = _ref.evt,
935
+ data = _objectWithoutProperties(_ref, ["evt"]);
936
+
937
+ PluginManager.pluginEvent.bind(Sortable)(eventName, sortable, _objectSpread({
938
+ dragEl: dragEl,
939
+ parentEl: parentEl,
940
+ ghostEl: ghostEl,
941
+ rootEl: rootEl,
942
+ nextEl: nextEl,
943
+ lastDownEl: lastDownEl,
944
+ cloneEl: cloneEl,
945
+ cloneHidden: cloneHidden,
946
+ dragStarted: moved,
947
+ putSortable: putSortable,
948
+ activeSortable: Sortable.active,
949
+ originalEvent: originalEvent,
950
+ oldIndex: oldIndex,
951
+ oldDraggableIndex: oldDraggableIndex,
952
+ newIndex: newIndex,
953
+ newDraggableIndex: newDraggableIndex,
954
+ hideGhostForTarget: _hideGhostForTarget,
955
+ unhideGhostForTarget: _unhideGhostForTarget,
956
+ cloneNowHidden: function cloneNowHidden() {
957
+ cloneHidden = true;
958
+ },
959
+ cloneNowShown: function cloneNowShown() {
960
+ cloneHidden = false;
961
+ },
962
+ dispatchSortableEvent: function dispatchSortableEvent(name) {
963
+ _dispatchEvent({
964
+ sortable: sortable,
965
+ name: name,
966
+ originalEvent: originalEvent
967
+ });
968
+ }
969
+ }, data));
970
+ };
971
+
972
+ function _dispatchEvent(info) {
973
+ dispatchEvent(_objectSpread({
974
+ putSortable: putSortable,
975
+ cloneEl: cloneEl,
976
+ targetEl: dragEl,
977
+ rootEl: rootEl,
978
+ oldIndex: oldIndex,
979
+ oldDraggableIndex: oldDraggableIndex,
980
+ newIndex: newIndex,
981
+ newDraggableIndex: newDraggableIndex
982
+ }, info));
983
+ }
984
+
985
+ var dragEl,
986
+ parentEl,
987
+ ghostEl,
988
+ rootEl,
989
+ nextEl,
990
+ lastDownEl,
991
+ cloneEl,
992
+ cloneHidden,
993
+ oldIndex,
994
+ newIndex,
995
+ oldDraggableIndex,
996
+ newDraggableIndex,
997
+ activeGroup,
998
+ putSortable,
999
+ awaitingDragStarted = false,
1000
+ ignoreNextClick = false,
1001
+ sortables = [],
1002
+ tapEvt,
1003
+ touchEvt,
1004
+ lastDx,
1005
+ lastDy,
1006
+ tapDistanceLeft,
1007
+ tapDistanceTop,
1008
+ moved,
1009
+ lastTarget,
1010
+ lastDirection,
1011
+ pastFirstInvertThresh = false,
1012
+ isCircumstantialInvert = false,
1013
+ targetMoveDistance,
1014
+ // For positioning ghost absolutely
1015
+ ghostRelativeParent,
1016
+ ghostRelativeParentInitialScroll = [],
1017
+ // (left, top)
1018
+ _silent = false,
1019
+ savedInputChecked = [];
1020
+ /** @const */
1021
+
1022
+ var documentExists = typeof document !== 'undefined',
1023
+ PositionGhostAbsolutely = IOS,
1024
+ CSSFloatProperty = Edge || IE11OrLess ? 'cssFloat' : 'float',
1025
+ // This will not pass for IE9, because IE9 DnD only works on anchors
1026
+ supportDraggable = documentExists && !ChromeForAndroid && !IOS && 'draggable' in document.createElement('div'),
1027
+ supportCssPointerEvents = function () {
1028
+ if (!documentExists) return; // false when <= IE11
1029
+
1030
+ if (IE11OrLess) {
1031
+ return false;
1032
+ }
1033
+
1034
+ var el = document.createElement('x');
1035
+ el.style.cssText = 'pointer-events:auto';
1036
+ return el.style.pointerEvents === 'auto';
1037
+ }(),
1038
+ _detectDirection = function _detectDirection(el, options) {
1039
+ var elCSS = css(el),
1040
+ elWidth = parseInt(elCSS.width) - parseInt(elCSS.paddingLeft) - parseInt(elCSS.paddingRight) - parseInt(elCSS.borderLeftWidth) - parseInt(elCSS.borderRightWidth),
1041
+ child1 = getChild(el, 0, options),
1042
+ child2 = getChild(el, 1, options),
1043
+ firstChildCSS = child1 && css(child1),
1044
+ secondChildCSS = child2 && css(child2),
1045
+ firstChildWidth = firstChildCSS && parseInt(firstChildCSS.marginLeft) + parseInt(firstChildCSS.marginRight) + getRect(child1).width,
1046
+ secondChildWidth = secondChildCSS && parseInt(secondChildCSS.marginLeft) + parseInt(secondChildCSS.marginRight) + getRect(child2).width;
1047
+
1048
+ if (elCSS.display === 'flex') {
1049
+ return elCSS.flexDirection === 'column' || elCSS.flexDirection === 'column-reverse' ? 'vertical' : 'horizontal';
1050
+ }
1051
+
1052
+ if (elCSS.display === 'grid') {
1053
+ return elCSS.gridTemplateColumns.split(' ').length <= 1 ? 'vertical' : 'horizontal';
1054
+ }
1055
+
1056
+ if (child1 && firstChildCSS["float"] && firstChildCSS["float"] !== 'none') {
1057
+ var touchingSideChild2 = firstChildCSS["float"] === 'left' ? 'left' : 'right';
1058
+ return child2 && (secondChildCSS.clear === 'both' || secondChildCSS.clear === touchingSideChild2) ? 'vertical' : 'horizontal';
1059
+ }
1060
+
1061
+ return child1 && (firstChildCSS.display === 'block' || firstChildCSS.display === 'flex' || firstChildCSS.display === 'table' || firstChildCSS.display === 'grid' || firstChildWidth >= elWidth && elCSS[CSSFloatProperty] === 'none' || child2 && elCSS[CSSFloatProperty] === 'none' && firstChildWidth + secondChildWidth > elWidth) ? 'vertical' : 'horizontal';
1062
+ },
1063
+ _dragElInRowColumn = function _dragElInRowColumn(dragRect, targetRect, vertical) {
1064
+ var dragElS1Opp = vertical ? dragRect.left : dragRect.top,
1065
+ dragElS2Opp = vertical ? dragRect.right : dragRect.bottom,
1066
+ dragElOppLength = vertical ? dragRect.width : dragRect.height,
1067
+ targetS1Opp = vertical ? targetRect.left : targetRect.top,
1068
+ targetS2Opp = vertical ? targetRect.right : targetRect.bottom,
1069
+ targetOppLength = vertical ? targetRect.width : targetRect.height;
1070
+ return dragElS1Opp === targetS1Opp || dragElS2Opp === targetS2Opp || dragElS1Opp + dragElOppLength / 2 === targetS1Opp + targetOppLength / 2;
1071
+ },
1072
+
1073
+ /**
1074
+ * Detects first nearest empty sortable to X and Y position using emptyInsertThreshold.
1075
+ * @param {Number} x X position
1076
+ * @param {Number} y Y position
1077
+ * @return {HTMLElement} Element of the first found nearest Sortable
1078
+ */
1079
+ _detectNearestEmptySortable = function _detectNearestEmptySortable(x, y) {
1080
+ var ret;
1081
+ sortables.some(function (sortable) {
1082
+ if (lastChild(sortable)) return;
1083
+ var rect = getRect(sortable),
1084
+ threshold = sortable[expando].options.emptyInsertThreshold,
1085
+ insideHorizontally = x >= rect.left - threshold && x <= rect.right + threshold,
1086
+ insideVertically = y >= rect.top - threshold && y <= rect.bottom + threshold;
1087
+
1088
+ if (threshold && insideHorizontally && insideVertically) {
1089
+ return ret = sortable;
1090
+ }
1091
+ });
1092
+ return ret;
1093
+ },
1094
+ _prepareGroup = function _prepareGroup(options) {
1095
+ function toFn(value, pull) {
1096
+ return function (to, from, dragEl, evt) {
1097
+ var sameGroup = to.options.group.name && from.options.group.name && to.options.group.name === from.options.group.name;
1098
+
1099
+ if (value == null && (pull || sameGroup)) {
1100
+ // Default pull value
1101
+ // Default pull and put value if same group
1102
+ return true;
1103
+ } else if (value == null || value === false) {
1104
+ return false;
1105
+ } else if (pull && value === 'clone') {
1106
+ return value;
1107
+ } else if (typeof value === 'function') {
1108
+ return toFn(value(to, from, dragEl, evt), pull)(to, from, dragEl, evt);
1109
+ } else {
1110
+ var otherGroup = (pull ? to : from).options.group.name;
1111
+ return value === true || typeof value === 'string' && value === otherGroup || value.join && value.indexOf(otherGroup) > -1;
1112
+ }
1113
+ };
1114
+ }
1115
+
1116
+ var group = {};
1117
+ var originalGroup = options.group;
1118
+
1119
+ if (!originalGroup || _typeof(originalGroup) != 'object') {
1120
+ originalGroup = {
1121
+ name: originalGroup
1122
+ };
1123
+ }
1124
+
1125
+ group.name = originalGroup.name;
1126
+ group.checkPull = toFn(originalGroup.pull, true);
1127
+ group.checkPut = toFn(originalGroup.put);
1128
+ group.revertClone = originalGroup.revertClone;
1129
+ options.group = group;
1130
+ },
1131
+ _hideGhostForTarget = function _hideGhostForTarget() {
1132
+ if (!supportCssPointerEvents && ghostEl) {
1133
+ css(ghostEl, 'display', 'none');
1134
+ }
1135
+ },
1136
+ _unhideGhostForTarget = function _unhideGhostForTarget() {
1137
+ if (!supportCssPointerEvents && ghostEl) {
1138
+ css(ghostEl, 'display', '');
1139
+ }
1140
+ }; // #1184 fix - Prevent click event on fallback if dragged but item not changed position
1141
+
1142
+
1143
+ if (documentExists) {
1144
+ document.addEventListener('click', function (evt) {
1145
+ if (ignoreNextClick) {
1146
+ evt.preventDefault();
1147
+ evt.stopPropagation && evt.stopPropagation();
1148
+ evt.stopImmediatePropagation && evt.stopImmediatePropagation();
1149
+ ignoreNextClick = false;
1150
+ return false;
1151
+ }
1152
+ }, true);
1153
+ }
1154
+
1155
+ var nearestEmptyInsertDetectEvent = function nearestEmptyInsertDetectEvent(evt) {
1156
+ if (dragEl) {
1157
+ evt = evt.touches ? evt.touches[0] : evt;
1158
+
1159
+ var nearest = _detectNearestEmptySortable(evt.clientX, evt.clientY);
1160
+
1161
+ if (nearest) {
1162
+ // Create imitation event
1163
+ var event = {};
1164
+
1165
+ for (var i in evt) {
1166
+ if (evt.hasOwnProperty(i)) {
1167
+ event[i] = evt[i];
1168
+ }
1169
+ }
1170
+
1171
+ event.target = event.rootEl = nearest;
1172
+ event.preventDefault = void 0;
1173
+ event.stopPropagation = void 0;
1174
+
1175
+ nearest[expando]._onDragOver(event);
1176
+ }
1177
+ }
1178
+ };
1179
+
1180
+ var _checkOutsideTargetEl = function _checkOutsideTargetEl(evt) {
1181
+ if (dragEl) {
1182
+ dragEl.parentNode[expando]._isOutsideThisEl(evt.target);
1183
+ }
1184
+ };
1185
+ /**
1186
+ * @class Sortable
1187
+ * @param {HTMLElement} el
1188
+ * @param {Object} [options]
1189
+ */
1190
+
1191
+
1192
+ function Sortable(el, options) {
1193
+ if (!(el && el.nodeType && el.nodeType === 1)) {
1194
+ throw "Sortable: `el` must be an HTMLElement, not ".concat({}.toString.call(el));
1195
+ }
1196
+
1197
+ this.el = el; // root element
1198
+
1199
+ this.options = options = _extends({}, options); // Export instance
1200
+
1201
+ el[expando] = this;
1202
+ var defaults = {
1203
+ group: null,
1204
+ sort: true,
1205
+ disabled: false,
1206
+ store: null,
1207
+ handle: null,
1208
+ draggable: /^[uo]l$/i.test(el.nodeName) ? '>li' : '>*',
1209
+ swapThreshold: 1,
1210
+ // percentage; 0 <= x <= 1
1211
+ invertSwap: false,
1212
+ // invert always
1213
+ invertedSwapThreshold: null,
1214
+ // will be set to same as swapThreshold if default
1215
+ removeCloneOnHide: true,
1216
+ direction: function direction() {
1217
+ return _detectDirection(el, this.options);
1218
+ },
1219
+ ghostClass: 'sortable-ghost',
1220
+ chosenClass: 'sortable-chosen',
1221
+ dragClass: 'sortable-drag',
1222
+ ignore: 'a, img',
1223
+ filter: null,
1224
+ preventOnFilter: true,
1225
+ animation: 0,
1226
+ easing: null,
1227
+ setData: function setData(dataTransfer, dragEl) {
1228
+ dataTransfer.setData('Text', dragEl.textContent);
1229
+ },
1230
+ dropBubble: false,
1231
+ dragoverBubble: false,
1232
+ dataIdAttr: 'data-id',
1233
+ delay: 0,
1234
+ delayOnTouchOnly: false,
1235
+ touchStartThreshold: (Number.parseInt ? Number : window).parseInt(window.devicePixelRatio, 10) || 1,
1236
+ forceFallback: false,
1237
+ fallbackClass: 'sortable-fallback',
1238
+ fallbackOnBody: false,
1239
+ fallbackTolerance: 0,
1240
+ fallbackOffset: {
1241
+ x: 0,
1242
+ y: 0
1243
+ },
1244
+ supportPointer: Sortable.supportPointer !== false && 'PointerEvent' in window && !Safari,
1245
+ emptyInsertThreshold: 5
1246
+ };
1247
+ PluginManager.initializePlugins(this, el, defaults); // Set default options
1248
+
1249
+ for (var name in defaults) {
1250
+ !(name in options) && (options[name] = defaults[name]);
1251
+ }
1252
+
1253
+ _prepareGroup(options); // Bind all private methods
1254
+
1255
+
1256
+ for (var fn in this) {
1257
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
1258
+ this[fn] = this[fn].bind(this);
1259
+ }
1260
+ } // Setup drag mode
1261
+
1262
+
1263
+ this.nativeDraggable = options.forceFallback ? false : supportDraggable;
1264
+
1265
+ if (this.nativeDraggable) {
1266
+ // Touch start threshold cannot be greater than the native dragstart threshold
1267
+ this.options.touchStartThreshold = 1;
1268
+ } // Bind events
1269
+
1270
+
1271
+ if (options.supportPointer) {
1272
+ on(el, 'pointerdown', this._onTapStart);
1273
+ } else {
1274
+ on(el, 'mousedown', this._onTapStart);
1275
+ on(el, 'touchstart', this._onTapStart);
1276
+ }
1277
+
1278
+ if (this.nativeDraggable) {
1279
+ on(el, 'dragover', this);
1280
+ on(el, 'dragenter', this);
1281
+ }
1282
+
1283
+ sortables.push(this.el); // Restore sorting
1284
+
1285
+ options.store && options.store.get && this.sort(options.store.get(this) || []); // Add animation state manager
1286
+
1287
+ _extends(this, AnimationStateManager());
1288
+ }
1289
+
1290
+ Sortable.prototype =
1291
+ /** @lends Sortable.prototype */
1292
+ {
1293
+ constructor: Sortable,
1294
+ _isOutsideThisEl: function _isOutsideThisEl(target) {
1295
+ if (!this.el.contains(target) && target !== this.el) {
1296
+ lastTarget = null;
1297
+ }
1298
+ },
1299
+ _getDirection: function _getDirection(evt, target) {
1300
+ return typeof this.options.direction === 'function' ? this.options.direction.call(this, evt, target, dragEl) : this.options.direction;
1301
+ },
1302
+ _onTapStart: function _onTapStart(
1303
+ /** Event|TouchEvent */
1304
+ evt) {
1305
+ if (!evt.cancelable) return;
1306
+
1307
+ var _this = this,
1308
+ el = this.el,
1309
+ options = this.options,
1310
+ preventOnFilter = options.preventOnFilter,
1311
+ type = evt.type,
1312
+ touch = evt.touches && evt.touches[0] || evt.pointerType && evt.pointerType === 'touch' && evt,
1313
+ target = (touch || evt).target,
1314
+ originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0] || evt.composedPath && evt.composedPath()[0]) || target,
1315
+ filter = options.filter;
1316
+
1317
+ _saveInputCheckedState(el); // Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
1318
+
1319
+
1320
+ if (dragEl) {
1321
+ return;
1322
+ }
1323
+
1324
+ if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
1325
+ return; // only left button and enabled
1326
+ } // cancel dnd if original target is content editable
1327
+
1328
+
1329
+ if (originalTarget.isContentEditable) {
1330
+ return;
1331
+ } // Safari ignores further event handling after mousedown
1332
+
1333
+
1334
+ if (!this.nativeDraggable && Safari && target && target.tagName.toUpperCase() === 'SELECT') {
1335
+ return;
1336
+ }
1337
+
1338
+ target = closest(target, options.draggable, el, false);
1339
+
1340
+ if (target && target.animated) {
1341
+ return;
1342
+ }
1343
+
1344
+ if (lastDownEl === target) {
1345
+ // Ignoring duplicate `down`
1346
+ return;
1347
+ } // Get the index of the dragged element within its parent
1348
+
1349
+
1350
+ oldIndex = index(target);
1351
+ oldDraggableIndex = index(target, options.draggable); // Check filter
1352
+
1353
+ if (typeof filter === 'function') {
1354
+ if (filter.call(this, evt, target, this)) {
1355
+ _dispatchEvent({
1356
+ sortable: _this,
1357
+ rootEl: originalTarget,
1358
+ name: 'filter',
1359
+ targetEl: target,
1360
+ toEl: el,
1361
+ fromEl: el
1362
+ });
1363
+
1364
+ pluginEvent('filter', _this, {
1365
+ evt: evt
1366
+ });
1367
+ preventOnFilter && evt.cancelable && evt.preventDefault();
1368
+ return; // cancel dnd
1369
+ }
1370
+ } else if (filter) {
1371
+ filter = filter.split(',').some(function (criteria) {
1372
+ criteria = closest(originalTarget, criteria.trim(), el, false);
1373
+
1374
+ if (criteria) {
1375
+ _dispatchEvent({
1376
+ sortable: _this,
1377
+ rootEl: criteria,
1378
+ name: 'filter',
1379
+ targetEl: target,
1380
+ fromEl: el,
1381
+ toEl: el
1382
+ });
1383
+
1384
+ pluginEvent('filter', _this, {
1385
+ evt: evt
1386
+ });
1387
+ return true;
1388
+ }
1389
+ });
1390
+
1391
+ if (filter) {
1392
+ preventOnFilter && evt.cancelable && evt.preventDefault();
1393
+ return; // cancel dnd
1394
+ }
1395
+ }
1396
+
1397
+ if (options.handle && !closest(originalTarget, options.handle, el, false)) {
1398
+ return;
1399
+ } // Prepare `dragstart`
1400
+
1401
+
1402
+ this._prepareDragStart(evt, touch, target);
1403
+ },
1404
+ _prepareDragStart: function _prepareDragStart(
1405
+ /** Event */
1406
+ evt,
1407
+ /** Touch */
1408
+ touch,
1409
+ /** HTMLElement */
1410
+ target) {
1411
+ var _this = this,
1412
+ el = _this.el,
1413
+ options = _this.options,
1414
+ ownerDocument = el.ownerDocument,
1415
+ dragStartFn;
1416
+
1417
+ if (target && !dragEl && target.parentNode === el) {
1418
+ var dragRect = getRect(target);
1419
+ rootEl = el;
1420
+ dragEl = target;
1421
+ parentEl = dragEl.parentNode;
1422
+ nextEl = dragEl.nextSibling;
1423
+ lastDownEl = target;
1424
+ activeGroup = options.group;
1425
+ Sortable.dragged = dragEl;
1426
+ tapEvt = {
1427
+ target: dragEl,
1428
+ clientX: (touch || evt).clientX,
1429
+ clientY: (touch || evt).clientY
1430
+ };
1431
+ tapDistanceLeft = tapEvt.clientX - dragRect.left;
1432
+ tapDistanceTop = tapEvt.clientY - dragRect.top;
1433
+ this._lastX = (touch || evt).clientX;
1434
+ this._lastY = (touch || evt).clientY;
1435
+ dragEl.style['will-change'] = 'all';
1436
+
1437
+ dragStartFn = function dragStartFn() {
1438
+ pluginEvent('delayEnded', _this, {
1439
+ evt: evt
1440
+ });
1441
+
1442
+ if (Sortable.eventCanceled) {
1443
+ _this._onDrop();
1444
+
1445
+ return;
1446
+ } // Delayed drag has been triggered
1447
+ // we can re-enable the events: touchmove/mousemove
1448
+
1449
+
1450
+ _this._disableDelayedDragEvents();
1451
+
1452
+ if (!FireFox && _this.nativeDraggable) {
1453
+ dragEl.draggable = true;
1454
+ } // Bind the events: dragstart/dragend
1455
+
1456
+
1457
+ _this._triggerDragStart(evt, touch); // Drag start event
1458
+
1459
+
1460
+ _dispatchEvent({
1461
+ sortable: _this,
1462
+ name: 'choose',
1463
+ originalEvent: evt
1464
+ }); // Chosen item
1465
+
1466
+
1467
+ toggleClass(dragEl, options.chosenClass, true);
1468
+ }; // Disable "draggable"
1469
+
1470
+
1471
+ options.ignore.split(',').forEach(function (criteria) {
1472
+ find(dragEl, criteria.trim(), _disableDraggable);
1473
+ });
1474
+ on(ownerDocument, 'dragover', nearestEmptyInsertDetectEvent);
1475
+ on(ownerDocument, 'mousemove', nearestEmptyInsertDetectEvent);
1476
+ on(ownerDocument, 'touchmove', nearestEmptyInsertDetectEvent);
1477
+ on(ownerDocument, 'mouseup', _this._onDrop);
1478
+ on(ownerDocument, 'touchend', _this._onDrop);
1479
+ on(ownerDocument, 'touchcancel', _this._onDrop); // Make dragEl draggable (must be before delay for FireFox)
1480
+
1481
+ if (FireFox && this.nativeDraggable) {
1482
+ this.options.touchStartThreshold = 4;
1483
+ dragEl.draggable = true;
1484
+ }
1485
+
1486
+ pluginEvent('delayStart', this, {
1487
+ evt: evt
1488
+ }); // Delay is impossible for native DnD in Edge or IE
1489
+
1490
+ if (options.delay && (!options.delayOnTouchOnly || touch) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
1491
+ if (Sortable.eventCanceled) {
1492
+ this._onDrop();
1493
+
1494
+ return;
1495
+ } // If the user moves the pointer or let go the click or touch
1496
+ // before the delay has been reached:
1497
+ // disable the delayed drag
1498
+
1499
+
1500
+ on(ownerDocument, 'mouseup', _this._disableDelayedDrag);
1501
+ on(ownerDocument, 'touchend', _this._disableDelayedDrag);
1502
+ on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
1503
+ on(ownerDocument, 'mousemove', _this._delayedDragTouchMoveHandler);
1504
+ on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
1505
+ options.supportPointer && on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
1506
+ _this._dragStartTimer = setTimeout(dragStartFn, options.delay);
1507
+ } else {
1508
+ dragStartFn();
1509
+ }
1510
+ }
1511
+ },
1512
+ _delayedDragTouchMoveHandler: function _delayedDragTouchMoveHandler(
1513
+ /** TouchEvent|PointerEvent **/
1514
+ e) {
1515
+ var touch = e.touches ? e.touches[0] : e;
1516
+
1517
+ if (Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) >= Math.floor(this.options.touchStartThreshold / (this.nativeDraggable && window.devicePixelRatio || 1))) {
1518
+ this._disableDelayedDrag();
1519
+ }
1520
+ },
1521
+ _disableDelayedDrag: function _disableDelayedDrag() {
1522
+ dragEl && _disableDraggable(dragEl);
1523
+ clearTimeout(this._dragStartTimer);
1524
+
1525
+ this._disableDelayedDragEvents();
1526
+ },
1527
+ _disableDelayedDragEvents: function _disableDelayedDragEvents() {
1528
+ var ownerDocument = this.el.ownerDocument;
1529
+ off(ownerDocument, 'mouseup', this._disableDelayedDrag);
1530
+ off(ownerDocument, 'touchend', this._disableDelayedDrag);
1531
+ off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
1532
+ off(ownerDocument, 'mousemove', this._delayedDragTouchMoveHandler);
1533
+ off(ownerDocument, 'touchmove', this._delayedDragTouchMoveHandler);
1534
+ off(ownerDocument, 'pointermove', this._delayedDragTouchMoveHandler);
1535
+ },
1536
+ _triggerDragStart: function _triggerDragStart(
1537
+ /** Event */
1538
+ evt,
1539
+ /** Touch */
1540
+ touch) {
1541
+ touch = touch || evt.pointerType == 'touch' && evt;
1542
+
1543
+ if (!this.nativeDraggable || touch) {
1544
+ if (this.options.supportPointer) {
1545
+ on(document, 'pointermove', this._onTouchMove);
1546
+ } else if (touch) {
1547
+ on(document, 'touchmove', this._onTouchMove);
1548
+ } else {
1549
+ on(document, 'mousemove', this._onTouchMove);
1550
+ }
1551
+ } else {
1552
+ on(dragEl, 'dragend', this);
1553
+ on(rootEl, 'dragstart', this._onDragStart);
1554
+ }
1555
+
1556
+ try {
1557
+ if (document.selection) {
1558
+ // Timeout neccessary for IE9
1559
+ _nextTick(function () {
1560
+ document.selection.empty();
1561
+ });
1562
+ } else {
1563
+ window.getSelection().removeAllRanges();
1564
+ }
1565
+ } catch (err) {}
1566
+ },
1567
+ _dragStarted: function _dragStarted(fallback, evt) {
1568
+
1569
+ awaitingDragStarted = false;
1570
+
1571
+ if (rootEl && dragEl) {
1572
+ pluginEvent('dragStarted', this, {
1573
+ evt: evt
1574
+ });
1575
+
1576
+ if (this.nativeDraggable) {
1577
+ on(document, 'dragover', _checkOutsideTargetEl);
1578
+ }
1579
+
1580
+ var options = this.options; // Apply effect
1581
+
1582
+ !fallback && toggleClass(dragEl, options.dragClass, false);
1583
+ toggleClass(dragEl, options.ghostClass, true);
1584
+ Sortable.active = this;
1585
+ fallback && this._appendGhost(); // Drag start event
1586
+
1587
+ _dispatchEvent({
1588
+ sortable: this,
1589
+ name: 'start',
1590
+ originalEvent: evt
1591
+ });
1592
+ } else {
1593
+ this._nulling();
1594
+ }
1595
+ },
1596
+ _emulateDragOver: function _emulateDragOver() {
1597
+ if (touchEvt) {
1598
+ this._lastX = touchEvt.clientX;
1599
+ this._lastY = touchEvt.clientY;
1600
+
1601
+ _hideGhostForTarget();
1602
+
1603
+ var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1604
+ var parent = target;
1605
+
1606
+ while (target && target.shadowRoot) {
1607
+ target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
1608
+ if (target === parent) break;
1609
+ parent = target;
1610
+ }
1611
+
1612
+ dragEl.parentNode[expando]._isOutsideThisEl(target);
1613
+
1614
+ if (parent) {
1615
+ do {
1616
+ if (parent[expando]) {
1617
+ var inserted = void 0;
1618
+ inserted = parent[expando]._onDragOver({
1619
+ clientX: touchEvt.clientX,
1620
+ clientY: touchEvt.clientY,
1621
+ target: target,
1622
+ rootEl: parent
1623
+ });
1624
+
1625
+ if (inserted && !this.options.dragoverBubble) {
1626
+ break;
1627
+ }
1628
+ }
1629
+
1630
+ target = parent; // store last element
1631
+ }
1632
+ /* jshint boss:true */
1633
+ while (parent = parent.parentNode);
1634
+ }
1635
+
1636
+ _unhideGhostForTarget();
1637
+ }
1638
+ },
1639
+ _onTouchMove: function _onTouchMove(
1640
+ /**TouchEvent*/
1641
+ evt) {
1642
+ if (tapEvt) {
1643
+ var options = this.options,
1644
+ fallbackTolerance = options.fallbackTolerance,
1645
+ fallbackOffset = options.fallbackOffset,
1646
+ touch = evt.touches ? evt.touches[0] : evt,
1647
+ ghostMatrix = ghostEl && matrix(ghostEl, true),
1648
+ scaleX = ghostEl && ghostMatrix && ghostMatrix.a,
1649
+ scaleY = ghostEl && ghostMatrix && ghostMatrix.d,
1650
+ relativeScrollOffset = PositionGhostAbsolutely && ghostRelativeParent && getRelativeScrollOffset(ghostRelativeParent),
1651
+ dx = (touch.clientX - tapEvt.clientX + fallbackOffset.x) / (scaleX || 1) + (relativeScrollOffset ? relativeScrollOffset[0] - ghostRelativeParentInitialScroll[0] : 0) / (scaleX || 1),
1652
+ dy = (touch.clientY - tapEvt.clientY + fallbackOffset.y) / (scaleY || 1) + (relativeScrollOffset ? relativeScrollOffset[1] - ghostRelativeParentInitialScroll[1] : 0) / (scaleY || 1); // only set the status to dragging, when we are actually dragging
1653
+
1654
+ if (!Sortable.active && !awaitingDragStarted) {
1655
+ if (fallbackTolerance && Math.max(Math.abs(touch.clientX - this._lastX), Math.abs(touch.clientY - this._lastY)) < fallbackTolerance) {
1656
+ return;
1657
+ }
1658
+
1659
+ this._onDragStart(evt, true);
1660
+ }
1661
+
1662
+ if (ghostEl) {
1663
+ if (ghostMatrix) {
1664
+ ghostMatrix.e += dx - (lastDx || 0);
1665
+ ghostMatrix.f += dy - (lastDy || 0);
1666
+ } else {
1667
+ ghostMatrix = {
1668
+ a: 1,
1669
+ b: 0,
1670
+ c: 0,
1671
+ d: 1,
1672
+ e: dx,
1673
+ f: dy
1674
+ };
1675
+ }
1676
+
1677
+ var cssMatrix = "matrix(".concat(ghostMatrix.a, ",").concat(ghostMatrix.b, ",").concat(ghostMatrix.c, ",").concat(ghostMatrix.d, ",").concat(ghostMatrix.e, ",").concat(ghostMatrix.f, ")");
1678
+ css(ghostEl, 'webkitTransform', cssMatrix);
1679
+ css(ghostEl, 'mozTransform', cssMatrix);
1680
+ css(ghostEl, 'msTransform', cssMatrix);
1681
+ css(ghostEl, 'transform', cssMatrix);
1682
+ lastDx = dx;
1683
+ lastDy = dy;
1684
+ touchEvt = touch;
1685
+ }
1686
+
1687
+ evt.cancelable && evt.preventDefault();
1688
+ }
1689
+ },
1690
+ _appendGhost: function _appendGhost() {
1691
+ // Bug if using scale(): https://stackoverflow.com/questions/2637058
1692
+ // Not being adjusted for
1693
+ if (!ghostEl) {
1694
+ var container = this.options.fallbackOnBody ? document.body : rootEl,
1695
+ rect = getRect(dragEl, true, PositionGhostAbsolutely, true, container),
1696
+ options = this.options; // Position absolutely
1697
+
1698
+ if (PositionGhostAbsolutely) {
1699
+ // Get relatively positioned parent
1700
+ ghostRelativeParent = container;
1701
+
1702
+ while (css(ghostRelativeParent, 'position') === 'static' && css(ghostRelativeParent, 'transform') === 'none' && ghostRelativeParent !== document) {
1703
+ ghostRelativeParent = ghostRelativeParent.parentNode;
1704
+ }
1705
+
1706
+ if (ghostRelativeParent !== document.body && ghostRelativeParent !== document.documentElement) {
1707
+ if (ghostRelativeParent === document) ghostRelativeParent = getWindowScrollingElement();
1708
+ rect.top += ghostRelativeParent.scrollTop;
1709
+ rect.left += ghostRelativeParent.scrollLeft;
1710
+ } else {
1711
+ ghostRelativeParent = getWindowScrollingElement();
1712
+ }
1713
+
1714
+ ghostRelativeParentInitialScroll = getRelativeScrollOffset(ghostRelativeParent);
1715
+ }
1716
+
1717
+ ghostEl = dragEl.cloneNode(true);
1718
+ toggleClass(ghostEl, options.ghostClass, false);
1719
+ toggleClass(ghostEl, options.fallbackClass, true);
1720
+ toggleClass(ghostEl, options.dragClass, true);
1721
+ css(ghostEl, 'transition', '');
1722
+ css(ghostEl, 'transform', '');
1723
+ css(ghostEl, 'box-sizing', 'border-box');
1724
+ css(ghostEl, 'margin', 0);
1725
+ css(ghostEl, 'top', rect.top);
1726
+ css(ghostEl, 'left', rect.left);
1727
+ css(ghostEl, 'width', rect.width);
1728
+ css(ghostEl, 'height', rect.height);
1729
+ css(ghostEl, 'opacity', '0.8');
1730
+ css(ghostEl, 'position', PositionGhostAbsolutely ? 'absolute' : 'fixed');
1731
+ css(ghostEl, 'zIndex', '100000');
1732
+ css(ghostEl, 'pointerEvents', 'none');
1733
+ Sortable.ghost = ghostEl;
1734
+ container.appendChild(ghostEl); // Set transform-origin
1735
+
1736
+ css(ghostEl, 'transform-origin', tapDistanceLeft / parseInt(ghostEl.style.width) * 100 + '% ' + tapDistanceTop / parseInt(ghostEl.style.height) * 100 + '%');
1737
+ }
1738
+ },
1739
+ _onDragStart: function _onDragStart(
1740
+ /**Event*/
1741
+ evt,
1742
+ /**boolean*/
1743
+ fallback) {
1744
+ var _this = this;
1745
+
1746
+ var dataTransfer = evt.dataTransfer;
1747
+ var options = _this.options;
1748
+ pluginEvent('dragStart', this, {
1749
+ evt: evt
1750
+ });
1751
+
1752
+ if (Sortable.eventCanceled) {
1753
+ this._onDrop();
1754
+
1755
+ return;
1756
+ }
1757
+
1758
+ pluginEvent('setupClone', this);
1759
+
1760
+ if (!Sortable.eventCanceled) {
1761
+ cloneEl = clone(dragEl);
1762
+ cloneEl.draggable = false;
1763
+ cloneEl.style['will-change'] = '';
1764
+
1765
+ this._hideClone();
1766
+
1767
+ toggleClass(cloneEl, this.options.chosenClass, false);
1768
+ Sortable.clone = cloneEl;
1769
+ } // #1143: IFrame support workaround
1770
+
1771
+
1772
+ _this.cloneId = _nextTick(function () {
1773
+ pluginEvent('clone', _this);
1774
+ if (Sortable.eventCanceled) return;
1775
+
1776
+ if (!_this.options.removeCloneOnHide) {
1777
+ rootEl.insertBefore(cloneEl, dragEl);
1778
+ }
1779
+
1780
+ _this._hideClone();
1781
+
1782
+ _dispatchEvent({
1783
+ sortable: _this,
1784
+ name: 'clone'
1785
+ });
1786
+ });
1787
+ !fallback && toggleClass(dragEl, options.dragClass, true); // Set proper drop events
1788
+
1789
+ if (fallback) {
1790
+ ignoreNextClick = true;
1791
+ _this._loopId = setInterval(_this._emulateDragOver, 50);
1792
+ } else {
1793
+ // Undo what was set in _prepareDragStart before drag started
1794
+ off(document, 'mouseup', _this._onDrop);
1795
+ off(document, 'touchend', _this._onDrop);
1796
+ off(document, 'touchcancel', _this._onDrop);
1797
+
1798
+ if (dataTransfer) {
1799
+ dataTransfer.effectAllowed = 'move';
1800
+ options.setData && options.setData.call(_this, dataTransfer, dragEl);
1801
+ }
1802
+
1803
+ on(document, 'drop', _this); // #1276 fix:
1804
+
1805
+ css(dragEl, 'transform', 'translateZ(0)');
1806
+ }
1807
+
1808
+ awaitingDragStarted = true;
1809
+ _this._dragStartId = _nextTick(_this._dragStarted.bind(_this, fallback, evt));
1810
+ on(document, 'selectstart', _this);
1811
+ moved = true;
1812
+
1813
+ if (Safari) {
1814
+ css(document.body, 'user-select', 'none');
1815
+ }
1816
+ },
1817
+ // Returns true - if no further action is needed (either inserted or another condition)
1818
+ _onDragOver: function _onDragOver(
1819
+ /**Event*/
1820
+ evt) {
1821
+ var el = this.el,
1822
+ target = evt.target,
1823
+ dragRect,
1824
+ targetRect,
1825
+ revert,
1826
+ options = this.options,
1827
+ group = options.group,
1828
+ activeSortable = Sortable.active,
1829
+ isOwner = activeGroup === group,
1830
+ canSort = options.sort,
1831
+ fromSortable = putSortable || activeSortable,
1832
+ vertical,
1833
+ _this = this,
1834
+ completedFired = false;
1835
+
1836
+ if (_silent) return;
1837
+
1838
+ function dragOverEvent(name, extra) {
1839
+ pluginEvent(name, _this, _objectSpread({
1840
+ evt: evt,
1841
+ isOwner: isOwner,
1842
+ axis: vertical ? 'vertical' : 'horizontal',
1843
+ revert: revert,
1844
+ dragRect: dragRect,
1845
+ targetRect: targetRect,
1846
+ canSort: canSort,
1847
+ fromSortable: fromSortable,
1848
+ target: target,
1849
+ completed: completed,
1850
+ onMove: function onMove(target, after) {
1851
+ return _onMove(rootEl, el, dragEl, dragRect, target, getRect(target), evt, after);
1852
+ },
1853
+ changed: changed
1854
+ }, extra));
1855
+ } // Capture animation state
1856
+
1857
+
1858
+ function capture() {
1859
+ dragOverEvent('dragOverAnimationCapture');
1860
+
1861
+ _this.captureAnimationState();
1862
+
1863
+ if (_this !== fromSortable) {
1864
+ fromSortable.captureAnimationState();
1865
+ }
1866
+ } // Return invocation when dragEl is inserted (or completed)
1867
+
1868
+
1869
+ function completed(insertion) {
1870
+ dragOverEvent('dragOverCompleted', {
1871
+ insertion: insertion
1872
+ });
1873
+
1874
+ if (insertion) {
1875
+ // Clones must be hidden before folding animation to capture dragRectAbsolute properly
1876
+ if (isOwner) {
1877
+ activeSortable._hideClone();
1878
+ } else {
1879
+ activeSortable._showClone(_this);
1880
+ }
1881
+
1882
+ if (_this !== fromSortable) {
1883
+ // Set ghost class to new sortable's ghost class
1884
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : activeSortable.options.ghostClass, false);
1885
+ toggleClass(dragEl, options.ghostClass, true);
1886
+ }
1887
+
1888
+ if (putSortable !== _this && _this !== Sortable.active) {
1889
+ putSortable = _this;
1890
+ } else if (_this === Sortable.active && putSortable) {
1891
+ putSortable = null;
1892
+ } // Animation
1893
+
1894
+
1895
+ if (fromSortable === _this) {
1896
+ _this._ignoreWhileAnimating = target;
1897
+ }
1898
+
1899
+ _this.animateAll(function () {
1900
+ dragOverEvent('dragOverAnimationComplete');
1901
+ _this._ignoreWhileAnimating = null;
1902
+ });
1903
+
1904
+ if (_this !== fromSortable) {
1905
+ fromSortable.animateAll();
1906
+ fromSortable._ignoreWhileAnimating = null;
1907
+ }
1908
+ } // Null lastTarget if it is not inside a previously swapped element
1909
+
1910
+
1911
+ if (target === dragEl && !dragEl.animated || target === el && !target.animated) {
1912
+ lastTarget = null;
1913
+ } // no bubbling and not fallback
1914
+
1915
+
1916
+ if (!options.dragoverBubble && !evt.rootEl && target !== document) {
1917
+ dragEl.parentNode[expando]._isOutsideThisEl(evt.target); // Do not detect for empty insert if already inserted
1918
+
1919
+
1920
+ !insertion && nearestEmptyInsertDetectEvent(evt);
1921
+ }
1922
+
1923
+ !options.dragoverBubble && evt.stopPropagation && evt.stopPropagation();
1924
+ return completedFired = true;
1925
+ } // Call when dragEl has been inserted
1926
+
1927
+
1928
+ function changed() {
1929
+ newIndex = index(dragEl);
1930
+ newDraggableIndex = index(dragEl, options.draggable);
1931
+
1932
+ _dispatchEvent({
1933
+ sortable: _this,
1934
+ name: 'change',
1935
+ toEl: el,
1936
+ newIndex: newIndex,
1937
+ newDraggableIndex: newDraggableIndex,
1938
+ originalEvent: evt
1939
+ });
1940
+ }
1941
+
1942
+ if (evt.preventDefault !== void 0) {
1943
+ evt.cancelable && evt.preventDefault();
1944
+ }
1945
+
1946
+ target = closest(target, options.draggable, el, true);
1947
+ dragOverEvent('dragOver');
1948
+ if (Sortable.eventCanceled) return completedFired;
1949
+
1950
+ if (dragEl.contains(evt.target) || target.animated && target.animatingX && target.animatingY || _this._ignoreWhileAnimating === target) {
1951
+ return completed(false);
1952
+ }
1953
+
1954
+ ignoreNextClick = false;
1955
+
1956
+ if (activeSortable && !options.disabled && (isOwner ? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
1957
+ : putSortable === this || (this.lastPutMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) && group.checkPut(this, activeSortable, dragEl, evt))) {
1958
+ vertical = this._getDirection(evt, target) === 'vertical';
1959
+ dragRect = getRect(dragEl);
1960
+ dragOverEvent('dragOverValid');
1961
+ if (Sortable.eventCanceled) return completedFired;
1962
+
1963
+ if (revert) {
1964
+ parentEl = rootEl; // actualization
1965
+
1966
+ capture();
1967
+
1968
+ this._hideClone();
1969
+
1970
+ dragOverEvent('revert');
1971
+
1972
+ if (!Sortable.eventCanceled) {
1973
+ if (nextEl) {
1974
+ rootEl.insertBefore(dragEl, nextEl);
1975
+ } else {
1976
+ rootEl.appendChild(dragEl);
1977
+ }
1978
+ }
1979
+
1980
+ return completed(true);
1981
+ }
1982
+
1983
+ var elLastChild = lastChild(el, options.draggable);
1984
+
1985
+ if (!elLastChild || _ghostIsLast(evt, vertical, this) && !elLastChild.animated) {
1986
+ // If already at end of list: Do not insert
1987
+ if (elLastChild === dragEl) {
1988
+ return completed(false);
1989
+ } // assign target only if condition is true
1990
+
1991
+
1992
+ if (elLastChild && el === evt.target) {
1993
+ target = elLastChild;
1994
+ }
1995
+
1996
+ if (target) {
1997
+ targetRect = getRect(target);
1998
+ }
1999
+
2000
+ if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, !!target) !== false) {
2001
+ capture();
2002
+ el.appendChild(dragEl);
2003
+ parentEl = el; // actualization
2004
+
2005
+ changed();
2006
+ return completed(true);
2007
+ }
2008
+ } else if (target.parentNode === el) {
2009
+ targetRect = getRect(target);
2010
+ var direction = 0,
2011
+ targetBeforeFirstSwap,
2012
+ differentLevel = dragEl.parentNode !== el,
2013
+ differentRowCol = !_dragElInRowColumn(dragEl.animated && dragEl.toRect || dragRect, target.animated && target.toRect || targetRect, vertical),
2014
+ side1 = vertical ? 'top' : 'left',
2015
+ scrolledPastTop = isScrolledPast(target, 'top', 'top') || isScrolledPast(dragEl, 'top', 'top'),
2016
+ scrollBefore = scrolledPastTop ? scrolledPastTop.scrollTop : void 0;
2017
+
2018
+ if (lastTarget !== target) {
2019
+ targetBeforeFirstSwap = targetRect[side1];
2020
+ pastFirstInvertThresh = false;
2021
+ isCircumstantialInvert = !differentRowCol && options.invertSwap || differentLevel;
2022
+ }
2023
+
2024
+ direction = _getSwapDirection(evt, target, targetRect, vertical, differentRowCol ? 1 : options.swapThreshold, options.invertedSwapThreshold == null ? options.swapThreshold : options.invertedSwapThreshold, isCircumstantialInvert, lastTarget === target);
2025
+ var sibling;
2026
+
2027
+ if (direction !== 0) {
2028
+ // Check if target is beside dragEl in respective direction (ignoring hidden elements)
2029
+ var dragIndex = index(dragEl);
2030
+
2031
+ do {
2032
+ dragIndex -= direction;
2033
+ sibling = parentEl.children[dragIndex];
2034
+ } while (sibling && (css(sibling, 'display') === 'none' || sibling === ghostEl));
2035
+ } // If dragEl is already beside target: Do not insert
2036
+
2037
+
2038
+ if (direction === 0 || sibling === target) {
2039
+ return completed(false);
2040
+ }
2041
+
2042
+ lastTarget = target;
2043
+ lastDirection = direction;
2044
+ var nextSibling = target.nextElementSibling,
2045
+ after = false;
2046
+ after = direction === 1;
2047
+
2048
+ var moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, after);
2049
+
2050
+ if (moveVector !== false) {
2051
+ if (moveVector === 1 || moveVector === -1) {
2052
+ after = moveVector === 1;
2053
+ }
2054
+
2055
+ _silent = true;
2056
+ setTimeout(_unsilent, 30);
2057
+ capture();
2058
+
2059
+ if (after && !nextSibling) {
2060
+ el.appendChild(dragEl);
2061
+ } else {
2062
+ target.parentNode.insertBefore(dragEl, after ? nextSibling : target);
2063
+ } // Undo chrome's scroll adjustment (has no effect on other browsers)
2064
+
2065
+
2066
+ if (scrolledPastTop) {
2067
+ scrollBy(scrolledPastTop, 0, scrollBefore - scrolledPastTop.scrollTop);
2068
+ }
2069
+
2070
+ parentEl = dragEl.parentNode; // actualization
2071
+ // must be done before animation
2072
+
2073
+ if (targetBeforeFirstSwap !== undefined && !isCircumstantialInvert) {
2074
+ targetMoveDistance = Math.abs(targetBeforeFirstSwap - getRect(target)[side1]);
2075
+ }
2076
+
2077
+ changed();
2078
+ return completed(true);
2079
+ }
2080
+ }
2081
+
2082
+ if (el.contains(dragEl)) {
2083
+ return completed(false);
2084
+ }
2085
+ }
2086
+
2087
+ return false;
2088
+ },
2089
+ _ignoreWhileAnimating: null,
2090
+ _offMoveEvents: function _offMoveEvents() {
2091
+ off(document, 'mousemove', this._onTouchMove);
2092
+ off(document, 'touchmove', this._onTouchMove);
2093
+ off(document, 'pointermove', this._onTouchMove);
2094
+ off(document, 'dragover', nearestEmptyInsertDetectEvent);
2095
+ off(document, 'mousemove', nearestEmptyInsertDetectEvent);
2096
+ off(document, 'touchmove', nearestEmptyInsertDetectEvent);
2097
+ },
2098
+ _offUpEvents: function _offUpEvents() {
2099
+ var ownerDocument = this.el.ownerDocument;
2100
+ off(ownerDocument, 'mouseup', this._onDrop);
2101
+ off(ownerDocument, 'touchend', this._onDrop);
2102
+ off(ownerDocument, 'pointerup', this._onDrop);
2103
+ off(ownerDocument, 'touchcancel', this._onDrop);
2104
+ off(document, 'selectstart', this);
2105
+ },
2106
+ _onDrop: function _onDrop(
2107
+ /**Event*/
2108
+ evt) {
2109
+ var el = this.el,
2110
+ options = this.options; // Get the index of the dragged element within its parent
2111
+
2112
+ newIndex = index(dragEl);
2113
+ newDraggableIndex = index(dragEl, options.draggable);
2114
+ pluginEvent('drop', this, {
2115
+ evt: evt
2116
+ });
2117
+ parentEl = dragEl && dragEl.parentNode; // Get again after plugin event
2118
+
2119
+ newIndex = index(dragEl);
2120
+ newDraggableIndex = index(dragEl, options.draggable);
2121
+
2122
+ if (Sortable.eventCanceled) {
2123
+ this._nulling();
2124
+
2125
+ return;
2126
+ }
2127
+
2128
+ awaitingDragStarted = false;
2129
+ isCircumstantialInvert = false;
2130
+ pastFirstInvertThresh = false;
2131
+ clearInterval(this._loopId);
2132
+ clearTimeout(this._dragStartTimer);
2133
+
2134
+ _cancelNextTick(this.cloneId);
2135
+
2136
+ _cancelNextTick(this._dragStartId); // Unbind events
2137
+
2138
+
2139
+ if (this.nativeDraggable) {
2140
+ off(document, 'drop', this);
2141
+ off(el, 'dragstart', this._onDragStart);
2142
+ }
2143
+
2144
+ this._offMoveEvents();
2145
+
2146
+ this._offUpEvents();
2147
+
2148
+ if (Safari) {
2149
+ css(document.body, 'user-select', '');
2150
+ }
2151
+
2152
+ css(dragEl, 'transform', '');
2153
+
2154
+ if (evt) {
2155
+ if (moved) {
2156
+ evt.cancelable && evt.preventDefault();
2157
+ !options.dropBubble && evt.stopPropagation();
2158
+ }
2159
+
2160
+ ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
2161
+
2162
+ if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
2163
+ // Remove clone(s)
2164
+ cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
2165
+ }
2166
+
2167
+ if (dragEl) {
2168
+ if (this.nativeDraggable) {
2169
+ off(dragEl, 'dragend', this);
2170
+ }
2171
+
2172
+ _disableDraggable(dragEl);
2173
+
2174
+ dragEl.style['will-change'] = ''; // Remove classes
2175
+ // ghostClass is added in dragStarted
2176
+
2177
+ if (moved && !awaitingDragStarted) {
2178
+ toggleClass(dragEl, putSortable ? putSortable.options.ghostClass : this.options.ghostClass, false);
2179
+ }
2180
+
2181
+ toggleClass(dragEl, this.options.chosenClass, false); // Drag stop event
2182
+
2183
+ _dispatchEvent({
2184
+ sortable: this,
2185
+ name: 'unchoose',
2186
+ toEl: parentEl,
2187
+ newIndex: null,
2188
+ newDraggableIndex: null,
2189
+ originalEvent: evt
2190
+ });
2191
+
2192
+ if (rootEl !== parentEl) {
2193
+ if (newIndex >= 0) {
2194
+ // Add event
2195
+ _dispatchEvent({
2196
+ rootEl: parentEl,
2197
+ name: 'add',
2198
+ toEl: parentEl,
2199
+ fromEl: rootEl,
2200
+ originalEvent: evt
2201
+ }); // Remove event
2202
+
2203
+
2204
+ _dispatchEvent({
2205
+ sortable: this,
2206
+ name: 'remove',
2207
+ toEl: parentEl,
2208
+ originalEvent: evt
2209
+ }); // drag from one list and drop into another
2210
+
2211
+
2212
+ _dispatchEvent({
2213
+ rootEl: parentEl,
2214
+ name: 'sort',
2215
+ toEl: parentEl,
2216
+ fromEl: rootEl,
2217
+ originalEvent: evt
2218
+ });
2219
+
2220
+ _dispatchEvent({
2221
+ sortable: this,
2222
+ name: 'sort',
2223
+ toEl: parentEl,
2224
+ originalEvent: evt
2225
+ });
2226
+ }
2227
+
2228
+ putSortable && putSortable.save();
2229
+ } else {
2230
+ if (newIndex !== oldIndex) {
2231
+ if (newIndex >= 0) {
2232
+ // drag & drop within the same list
2233
+ _dispatchEvent({
2234
+ sortable: this,
2235
+ name: 'update',
2236
+ toEl: parentEl,
2237
+ originalEvent: evt
2238
+ });
2239
+
2240
+ _dispatchEvent({
2241
+ sortable: this,
2242
+ name: 'sort',
2243
+ toEl: parentEl,
2244
+ originalEvent: evt
2245
+ });
2246
+ }
2247
+ }
2248
+ }
2249
+
2250
+ if (Sortable.active) {
2251
+ /* jshint eqnull:true */
2252
+ if (newIndex == null || newIndex === -1) {
2253
+ newIndex = oldIndex;
2254
+ newDraggableIndex = oldDraggableIndex;
2255
+ }
2256
+
2257
+ _dispatchEvent({
2258
+ sortable: this,
2259
+ name: 'end',
2260
+ toEl: parentEl,
2261
+ originalEvent: evt
2262
+ }); // Save sorting
2263
+
2264
+
2265
+ this.save();
2266
+ }
2267
+ }
2268
+ }
2269
+
2270
+ this._nulling();
2271
+ },
2272
+ _nulling: function _nulling() {
2273
+ pluginEvent('nulling', this);
2274
+ rootEl = dragEl = parentEl = ghostEl = nextEl = cloneEl = lastDownEl = cloneHidden = tapEvt = touchEvt = moved = newIndex = newDraggableIndex = oldIndex = oldDraggableIndex = lastTarget = lastDirection = putSortable = activeGroup = Sortable.dragged = Sortable.ghost = Sortable.clone = Sortable.active = null;
2275
+ savedInputChecked.forEach(function (el) {
2276
+ el.checked = true;
2277
+ });
2278
+ savedInputChecked.length = lastDx = lastDy = 0;
2279
+ },
2280
+ handleEvent: function handleEvent(
2281
+ /**Event*/
2282
+ evt) {
2283
+ switch (evt.type) {
2284
+ case 'drop':
2285
+ case 'dragend':
2286
+ this._onDrop(evt);
2287
+
2288
+ break;
2289
+
2290
+ case 'dragenter':
2291
+ case 'dragover':
2292
+ if (dragEl) {
2293
+ this._onDragOver(evt);
2294
+
2295
+ _globalDragOver(evt);
2296
+ }
2297
+
2298
+ break;
2299
+
2300
+ case 'selectstart':
2301
+ evt.preventDefault();
2302
+ break;
2303
+ }
2304
+ },
2305
+
2306
+ /**
2307
+ * Serializes the item into an array of string.
2308
+ * @returns {String[]}
2309
+ */
2310
+ toArray: function toArray() {
2311
+ var order = [],
2312
+ el,
2313
+ children = this.el.children,
2314
+ i = 0,
2315
+ n = children.length,
2316
+ options = this.options;
2317
+
2318
+ for (; i < n; i++) {
2319
+ el = children[i];
2320
+
2321
+ if (closest(el, options.draggable, this.el, false)) {
2322
+ order.push(el.getAttribute(options.dataIdAttr) || _generateId(el));
2323
+ }
2324
+ }
2325
+
2326
+ return order;
2327
+ },
2328
+
2329
+ /**
2330
+ * Sorts the elements according to the array.
2331
+ * @param {String[]} order order of the items
2332
+ */
2333
+ sort: function sort(order, useAnimation) {
2334
+ var items = {},
2335
+ rootEl = this.el;
2336
+ this.toArray().forEach(function (id, i) {
2337
+ var el = rootEl.children[i];
2338
+
2339
+ if (closest(el, this.options.draggable, rootEl, false)) {
2340
+ items[id] = el;
2341
+ }
2342
+ }, this);
2343
+ useAnimation && this.captureAnimationState();
2344
+ order.forEach(function (id) {
2345
+ if (items[id]) {
2346
+ rootEl.removeChild(items[id]);
2347
+ rootEl.appendChild(items[id]);
2348
+ }
2349
+ });
2350
+ useAnimation && this.animateAll();
2351
+ },
2352
+
2353
+ /**
2354
+ * Save the current sorting
2355
+ */
2356
+ save: function save() {
2357
+ var store = this.options.store;
2358
+ store && store.set && store.set(this);
2359
+ },
2360
+
2361
+ /**
2362
+ * For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.
2363
+ * @param {HTMLElement} el
2364
+ * @param {String} [selector] default: `options.draggable`
2365
+ * @returns {HTMLElement|null}
2366
+ */
2367
+ closest: function closest$1(el, selector) {
2368
+ return closest(el, selector || this.options.draggable, this.el, false);
2369
+ },
2370
+
2371
+ /**
2372
+ * Set/get option
2373
+ * @param {string} name
2374
+ * @param {*} [value]
2375
+ * @returns {*}
2376
+ */
2377
+ option: function option(name, value) {
2378
+ var options = this.options;
2379
+
2380
+ if (value === void 0) {
2381
+ return options[name];
2382
+ } else {
2383
+ var modifiedValue = PluginManager.modifyOption(this, name, value);
2384
+
2385
+ if (typeof modifiedValue !== 'undefined') {
2386
+ options[name] = modifiedValue;
2387
+ } else {
2388
+ options[name] = value;
2389
+ }
2390
+
2391
+ if (name === 'group') {
2392
+ _prepareGroup(options);
2393
+ }
2394
+ }
2395
+ },
2396
+
2397
+ /**
2398
+ * Destroy
2399
+ */
2400
+ destroy: function destroy() {
2401
+ pluginEvent('destroy', this);
2402
+ var el = this.el;
2403
+ el[expando] = null;
2404
+ off(el, 'mousedown', this._onTapStart);
2405
+ off(el, 'touchstart', this._onTapStart);
2406
+ off(el, 'pointerdown', this._onTapStart);
2407
+
2408
+ if (this.nativeDraggable) {
2409
+ off(el, 'dragover', this);
2410
+ off(el, 'dragenter', this);
2411
+ } // Remove draggable attributes
2412
+
2413
+
2414
+ Array.prototype.forEach.call(el.querySelectorAll('[draggable]'), function (el) {
2415
+ el.removeAttribute('draggable');
2416
+ });
2417
+
2418
+ this._onDrop();
2419
+
2420
+ this._disableDelayedDragEvents();
2421
+
2422
+ sortables.splice(sortables.indexOf(this.el), 1);
2423
+ this.el = el = null;
2424
+ },
2425
+ _hideClone: function _hideClone() {
2426
+ if (!cloneHidden) {
2427
+ pluginEvent('hideClone', this);
2428
+ if (Sortable.eventCanceled) return;
2429
+ css(cloneEl, 'display', 'none');
2430
+
2431
+ if (this.options.removeCloneOnHide && cloneEl.parentNode) {
2432
+ cloneEl.parentNode.removeChild(cloneEl);
2433
+ }
2434
+
2435
+ cloneHidden = true;
2436
+ }
2437
+ },
2438
+ _showClone: function _showClone(putSortable) {
2439
+ if (putSortable.lastPutMode !== 'clone') {
2440
+ this._hideClone();
2441
+
2442
+ return;
2443
+ }
2444
+
2445
+ if (cloneHidden) {
2446
+ pluginEvent('showClone', this);
2447
+ if (Sortable.eventCanceled) return; // show clone at dragEl or original position
2448
+
2449
+ if (dragEl.parentNode == rootEl && !this.options.group.revertClone) {
2450
+ rootEl.insertBefore(cloneEl, dragEl);
2451
+ } else if (nextEl) {
2452
+ rootEl.insertBefore(cloneEl, nextEl);
2453
+ } else {
2454
+ rootEl.appendChild(cloneEl);
2455
+ }
2456
+
2457
+ if (this.options.group.revertClone) {
2458
+ this.animate(dragEl, cloneEl);
2459
+ }
2460
+
2461
+ css(cloneEl, 'display', '');
2462
+ cloneHidden = false;
2463
+ }
2464
+ }
2465
+ };
2466
+
2467
+ function _globalDragOver(
2468
+ /**Event*/
2469
+ evt) {
2470
+ if (evt.dataTransfer) {
2471
+ evt.dataTransfer.dropEffect = 'move';
2472
+ }
2473
+
2474
+ evt.cancelable && evt.preventDefault();
2475
+ }
2476
+
2477
+ function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvent, willInsertAfter) {
2478
+ var evt,
2479
+ sortable = fromEl[expando],
2480
+ onMoveFn = sortable.options.onMove,
2481
+ retVal; // Support for new CustomEvent feature
2482
+
2483
+ if (window.CustomEvent && !IE11OrLess && !Edge) {
2484
+ evt = new CustomEvent('move', {
2485
+ bubbles: true,
2486
+ cancelable: true
2487
+ });
2488
+ } else {
2489
+ evt = document.createEvent('Event');
2490
+ evt.initEvent('move', true, true);
2491
+ }
2492
+
2493
+ evt.to = toEl;
2494
+ evt.from = fromEl;
2495
+ evt.dragged = dragEl;
2496
+ evt.draggedRect = dragRect;
2497
+ evt.related = targetEl || toEl;
2498
+ evt.relatedRect = targetRect || getRect(toEl);
2499
+ evt.willInsertAfter = willInsertAfter;
2500
+ evt.originalEvent = originalEvent;
2501
+ fromEl.dispatchEvent(evt);
2502
+
2503
+ if (onMoveFn) {
2504
+ retVal = onMoveFn.call(sortable, evt, originalEvent);
2505
+ }
2506
+
2507
+ return retVal;
2508
+ }
2509
+
2510
+ function _disableDraggable(el) {
2511
+ el.draggable = false;
2512
+ }
2513
+
2514
+ function _unsilent() {
2515
+ _silent = false;
2516
+ }
2517
+
2518
+ function _ghostIsLast(evt, vertical, sortable) {
2519
+ var rect = getRect(lastChild(sortable.el, sortable.options.draggable));
2520
+ var spacer = 10;
2521
+ return vertical ? evt.clientX > rect.right + spacer || evt.clientX <= rect.right && evt.clientY > rect.bottom && evt.clientX >= rect.left : evt.clientX > rect.right && evt.clientY > rect.top || evt.clientX <= rect.right && evt.clientY > rect.bottom + spacer;
2522
+ }
2523
+
2524
+ function _getSwapDirection(evt, target, targetRect, vertical, swapThreshold, invertedSwapThreshold, invertSwap, isLastTarget) {
2525
+ var mouseOnAxis = vertical ? evt.clientY : evt.clientX,
2526
+ targetLength = vertical ? targetRect.height : targetRect.width,
2527
+ targetS1 = vertical ? targetRect.top : targetRect.left,
2528
+ targetS2 = vertical ? targetRect.bottom : targetRect.right,
2529
+ invert = false;
2530
+
2531
+ if (!invertSwap) {
2532
+ // Never invert or create dragEl shadow when target movemenet causes mouse to move past the end of regular swapThreshold
2533
+ if (isLastTarget && targetMoveDistance < targetLength * swapThreshold) {
2534
+ // multiplied only by swapThreshold because mouse will already be inside target by (1 - threshold) * targetLength / 2
2535
+ // check if past first invert threshold on side opposite of lastDirection
2536
+ if (!pastFirstInvertThresh && (lastDirection === 1 ? mouseOnAxis > targetS1 + targetLength * invertedSwapThreshold / 2 : mouseOnAxis < targetS2 - targetLength * invertedSwapThreshold / 2)) {
2537
+ // past first invert threshold, do not restrict inverted threshold to dragEl shadow
2538
+ pastFirstInvertThresh = true;
2539
+ }
2540
+
2541
+ if (!pastFirstInvertThresh) {
2542
+ // dragEl shadow (target move distance shadow)
2543
+ if (lastDirection === 1 ? mouseOnAxis < targetS1 + targetMoveDistance // over dragEl shadow
2544
+ : mouseOnAxis > targetS2 - targetMoveDistance) {
2545
+ return -lastDirection;
2546
+ }
2547
+ } else {
2548
+ invert = true;
2549
+ }
2550
+ } else {
2551
+ // Regular
2552
+ if (mouseOnAxis > targetS1 + targetLength * (1 - swapThreshold) / 2 && mouseOnAxis < targetS2 - targetLength * (1 - swapThreshold) / 2) {
2553
+ return _getInsertDirection(target);
2554
+ }
2555
+ }
2556
+ }
2557
+
2558
+ invert = invert || invertSwap;
2559
+
2560
+ if (invert) {
2561
+ // Invert of regular
2562
+ if (mouseOnAxis < targetS1 + targetLength * invertedSwapThreshold / 2 || mouseOnAxis > targetS2 - targetLength * invertedSwapThreshold / 2) {
2563
+ return mouseOnAxis > targetS1 + targetLength / 2 ? 1 : -1;
2564
+ }
2565
+ }
2566
+
2567
+ return 0;
2568
+ }
2569
+ /**
2570
+ * Gets the direction dragEl must be swapped relative to target in order to make it
2571
+ * seem that dragEl has been "inserted" into that element's position
2572
+ * @param {HTMLElement} target The target whose position dragEl is being inserted at
2573
+ * @return {Number} Direction dragEl must be swapped
2574
+ */
2575
+
2576
+
2577
+ function _getInsertDirection(target) {
2578
+ if (index(dragEl) < index(target)) {
2579
+ return 1;
2580
+ } else {
2581
+ return -1;
2582
+ }
2583
+ }
2584
+ /**
2585
+ * Generate id
2586
+ * @param {HTMLElement} el
2587
+ * @returns {String}
2588
+ * @private
2589
+ */
2590
+
2591
+
2592
+ function _generateId(el) {
2593
+ var str = el.tagName + el.className + el.src + el.href + el.textContent,
2594
+ i = str.length,
2595
+ sum = 0;
2596
+
2597
+ while (i--) {
2598
+ sum += str.charCodeAt(i);
2599
+ }
2600
+
2601
+ return sum.toString(36);
2602
+ }
2603
+
2604
+ function _saveInputCheckedState(root) {
2605
+ savedInputChecked.length = 0;
2606
+ var inputs = root.getElementsByTagName('input');
2607
+ var idx = inputs.length;
2608
+
2609
+ while (idx--) {
2610
+ var el = inputs[idx];
2611
+ el.checked && savedInputChecked.push(el);
2612
+ }
2613
+ }
2614
+
2615
+ function _nextTick(fn) {
2616
+ return setTimeout(fn, 0);
2617
+ }
2618
+
2619
+ function _cancelNextTick(id) {
2620
+ return clearTimeout(id);
2621
+ } // Fixed #973:
2622
+
2623
+
2624
+ if (documentExists) {
2625
+ on(document, 'touchmove', function (evt) {
2626
+ if ((Sortable.active || awaitingDragStarted) && evt.cancelable) {
2627
+ evt.preventDefault();
2628
+ }
2629
+ });
2630
+ } // Export utils
2631
+
2632
+
2633
+ Sortable.utils = {
2634
+ on: on,
2635
+ off: off,
2636
+ css: css,
2637
+ find: find,
2638
+ is: function is(el, selector) {
2639
+ return !!closest(el, selector, el, false);
2640
+ },
2641
+ extend: extend,
2642
+ throttle: throttle,
2643
+ closest: closest,
2644
+ toggleClass: toggleClass,
2645
+ clone: clone,
2646
+ index: index,
2647
+ nextTick: _nextTick,
2648
+ cancelNextTick: _cancelNextTick,
2649
+ detectDirection: _detectDirection,
2650
+ getChild: getChild
2651
+ };
2652
+ /**
2653
+ * Get the Sortable instance of an element
2654
+ * @param {HTMLElement} element The element
2655
+ * @return {Sortable|undefined} The instance of Sortable
2656
+ */
2657
+
2658
+ Sortable.get = function (element) {
2659
+ return element[expando];
2660
+ };
2661
+ /**
2662
+ * Mount a plugin to Sortable
2663
+ * @param {...SortablePlugin|SortablePlugin[]} plugins Plugins being mounted
2664
+ */
2665
+
2666
+
2667
+ Sortable.mount = function () {
2668
+ for (var _len = arguments.length, plugins = new Array(_len), _key = 0; _key < _len; _key++) {
2669
+ plugins[_key] = arguments[_key];
2670
+ }
2671
+
2672
+ if (plugins[0].constructor === Array) plugins = plugins[0];
2673
+ plugins.forEach(function (plugin) {
2674
+ if (!plugin.prototype || !plugin.prototype.constructor) {
2675
+ throw "Sortable: Mounted plugin must be a constructor function, not ".concat({}.toString.call(plugin));
2676
+ }
2677
+
2678
+ if (plugin.utils) Sortable.utils = _objectSpread({}, Sortable.utils, plugin.utils);
2679
+ PluginManager.mount(plugin);
2680
+ });
2681
+ };
2682
+ /**
2683
+ * Create sortable instance
2684
+ * @param {HTMLElement} el
2685
+ * @param {Object} [options]
2686
+ */
2687
+
2688
+
2689
+ Sortable.create = function (el, options) {
2690
+ return new Sortable(el, options);
2691
+ }; // Export
2692
+
2693
+
2694
+ Sortable.version = version;
2695
+
2696
+ var autoScrolls = [],
2697
+ scrollEl,
2698
+ scrollRootEl,
2699
+ scrolling = false,
2700
+ lastAutoScrollX,
2701
+ lastAutoScrollY,
2702
+ touchEvt$1,
2703
+ pointerElemChangedInterval;
2704
+
2705
+ function AutoScrollPlugin() {
2706
+ function AutoScroll() {
2707
+ this.defaults = {
2708
+ scroll: true,
2709
+ scrollSensitivity: 30,
2710
+ scrollSpeed: 10,
2711
+ bubbleScroll: true
2712
+ }; // Bind all private methods
2713
+
2714
+ for (var fn in this) {
2715
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
2716
+ this[fn] = this[fn].bind(this);
2717
+ }
2718
+ }
2719
+ }
2720
+
2721
+ AutoScroll.prototype = {
2722
+ dragStarted: function dragStarted(_ref) {
2723
+ var originalEvent = _ref.originalEvent;
2724
+
2725
+ if (this.sortable.nativeDraggable) {
2726
+ on(document, 'dragover', this._handleAutoScroll);
2727
+ } else {
2728
+ if (this.options.supportPointer) {
2729
+ on(document, 'pointermove', this._handleFallbackAutoScroll);
2730
+ } else if (originalEvent.touches) {
2731
+ on(document, 'touchmove', this._handleFallbackAutoScroll);
2732
+ } else {
2733
+ on(document, 'mousemove', this._handleFallbackAutoScroll);
2734
+ }
2735
+ }
2736
+ },
2737
+ dragOverCompleted: function dragOverCompleted(_ref2) {
2738
+ var originalEvent = _ref2.originalEvent;
2739
+
2740
+ // For when bubbling is canceled and using fallback (fallback 'touchmove' always reached)
2741
+ if (!this.options.dragOverBubble && !originalEvent.rootEl) {
2742
+ this._handleAutoScroll(originalEvent);
2743
+ }
2744
+ },
2745
+ drop: function drop() {
2746
+ if (this.sortable.nativeDraggable) {
2747
+ off(document, 'dragover', this._handleAutoScroll);
2748
+ } else {
2749
+ off(document, 'pointermove', this._handleFallbackAutoScroll);
2750
+ off(document, 'touchmove', this._handleFallbackAutoScroll);
2751
+ off(document, 'mousemove', this._handleFallbackAutoScroll);
2752
+ }
2753
+
2754
+ clearPointerElemChangedInterval();
2755
+ clearAutoScrolls();
2756
+ cancelThrottle();
2757
+ },
2758
+ nulling: function nulling() {
2759
+ touchEvt$1 = scrollRootEl = scrollEl = scrolling = pointerElemChangedInterval = lastAutoScrollX = lastAutoScrollY = null;
2760
+ autoScrolls.length = 0;
2761
+ },
2762
+ _handleFallbackAutoScroll: function _handleFallbackAutoScroll(evt) {
2763
+ this._handleAutoScroll(evt, true);
2764
+ },
2765
+ _handleAutoScroll: function _handleAutoScroll(evt, fallback) {
2766
+ var _this = this;
2767
+
2768
+ var x = (evt.touches ? evt.touches[0] : evt).clientX,
2769
+ y = (evt.touches ? evt.touches[0] : evt).clientY,
2770
+ elem = document.elementFromPoint(x, y);
2771
+ touchEvt$1 = evt; // IE does not seem to have native autoscroll,
2772
+ // Edge's autoscroll seems too conditional,
2773
+ // MACOS Safari does not have autoscroll,
2774
+ // Firefox and Chrome are good
2775
+
2776
+ if (fallback || Edge || IE11OrLess || Safari) {
2777
+ autoScroll(evt, this.options, elem, fallback); // Listener for pointer element change
2778
+
2779
+ var ogElemScroller = getParentAutoScrollElement(elem, true);
2780
+
2781
+ if (scrolling && (!pointerElemChangedInterval || x !== lastAutoScrollX || y !== lastAutoScrollY)) {
2782
+ pointerElemChangedInterval && clearPointerElemChangedInterval(); // Detect for pointer elem change, emulating native DnD behaviour
2783
+
2784
+ pointerElemChangedInterval = setInterval(function () {
2785
+ var newElem = getParentAutoScrollElement(document.elementFromPoint(x, y), true);
2786
+
2787
+ if (newElem !== ogElemScroller) {
2788
+ ogElemScroller = newElem;
2789
+ clearAutoScrolls();
2790
+ }
2791
+
2792
+ autoScroll(evt, _this.options, newElem, fallback);
2793
+ }, 10);
2794
+ lastAutoScrollX = x;
2795
+ lastAutoScrollY = y;
2796
+ }
2797
+ } else {
2798
+ // if DnD is enabled (and browser has good autoscrolling), first autoscroll will already scroll, so get parent autoscroll of first autoscroll
2799
+ if (!this.options.bubbleScroll || getParentAutoScrollElement(elem, true) === getWindowScrollingElement()) {
2800
+ clearAutoScrolls();
2801
+ return;
2802
+ }
2803
+
2804
+ autoScroll(evt, this.options, getParentAutoScrollElement(elem, false), false);
2805
+ }
2806
+ }
2807
+ };
2808
+ return _extends(AutoScroll, {
2809
+ pluginName: 'scroll',
2810
+ initializeByDefault: true
2811
+ });
2812
+ }
2813
+
2814
+ function clearAutoScrolls() {
2815
+ autoScrolls.forEach(function (autoScroll) {
2816
+ clearInterval(autoScroll.pid);
2817
+ });
2818
+ autoScrolls = [];
2819
+ }
2820
+
2821
+ function clearPointerElemChangedInterval() {
2822
+ clearInterval(pointerElemChangedInterval);
2823
+ }
2824
+
2825
+ var autoScroll = throttle(function (evt, options, rootEl, isFallback) {
2826
+ // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
2827
+ if (!options.scroll) return;
2828
+ var x = (evt.touches ? evt.touches[0] : evt).clientX,
2829
+ y = (evt.touches ? evt.touches[0] : evt).clientY,
2830
+ sens = options.scrollSensitivity,
2831
+ speed = options.scrollSpeed,
2832
+ winScroller = getWindowScrollingElement();
2833
+ var scrollThisInstance = false,
2834
+ scrollCustomFn; // New scroll root, set scrollEl
2835
+
2836
+ if (scrollRootEl !== rootEl) {
2837
+ scrollRootEl = rootEl;
2838
+ clearAutoScrolls();
2839
+ scrollEl = options.scroll;
2840
+ scrollCustomFn = options.scrollFn;
2841
+
2842
+ if (scrollEl === true) {
2843
+ scrollEl = getParentAutoScrollElement(rootEl, true);
2844
+ }
2845
+ }
2846
+
2847
+ var layersOut = 0;
2848
+ var currentParent = scrollEl;
2849
+
2850
+ do {
2851
+ var el = currentParent,
2852
+ rect = getRect(el),
2853
+ top = rect.top,
2854
+ bottom = rect.bottom,
2855
+ left = rect.left,
2856
+ right = rect.right,
2857
+ width = rect.width,
2858
+ height = rect.height,
2859
+ canScrollX = void 0,
2860
+ canScrollY = void 0,
2861
+ scrollWidth = el.scrollWidth,
2862
+ scrollHeight = el.scrollHeight,
2863
+ elCSS = css(el),
2864
+ scrollPosX = el.scrollLeft,
2865
+ scrollPosY = el.scrollTop;
2866
+
2867
+ if (el === winScroller) {
2868
+ canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll' || elCSS.overflowX === 'visible');
2869
+ canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll' || elCSS.overflowY === 'visible');
2870
+ } else {
2871
+ canScrollX = width < scrollWidth && (elCSS.overflowX === 'auto' || elCSS.overflowX === 'scroll');
2872
+ canScrollY = height < scrollHeight && (elCSS.overflowY === 'auto' || elCSS.overflowY === 'scroll');
2873
+ }
2874
+
2875
+ var vx = canScrollX && (Math.abs(right - x) <= sens && scrollPosX + width < scrollWidth) - (Math.abs(left - x) <= sens && !!scrollPosX);
2876
+ var vy = canScrollY && (Math.abs(bottom - y) <= sens && scrollPosY + height < scrollHeight) - (Math.abs(top - y) <= sens && !!scrollPosY);
2877
+
2878
+ if (!autoScrolls[layersOut]) {
2879
+ for (var i = 0; i <= layersOut; i++) {
2880
+ if (!autoScrolls[i]) {
2881
+ autoScrolls[i] = {};
2882
+ }
2883
+ }
2884
+ }
2885
+
2886
+ if (autoScrolls[layersOut].vx != vx || autoScrolls[layersOut].vy != vy || autoScrolls[layersOut].el !== el) {
2887
+ autoScrolls[layersOut].el = el;
2888
+ autoScrolls[layersOut].vx = vx;
2889
+ autoScrolls[layersOut].vy = vy;
2890
+ clearInterval(autoScrolls[layersOut].pid);
2891
+
2892
+ if (vx != 0 || vy != 0) {
2893
+ scrollThisInstance = true;
2894
+ /* jshint loopfunc:true */
2895
+
2896
+ autoScrolls[layersOut].pid = setInterval(function () {
2897
+ // emulate drag over during autoscroll (fallback), emulating native DnD behaviour
2898
+ if (isFallback && this.layer === 0) {
2899
+ Sortable.active._onTouchMove(touchEvt$1); // To move ghost if it is positioned absolutely
2900
+
2901
+ }
2902
+
2903
+ var scrollOffsetY = autoScrolls[this.layer].vy ? autoScrolls[this.layer].vy * speed : 0;
2904
+ var scrollOffsetX = autoScrolls[this.layer].vx ? autoScrolls[this.layer].vx * speed : 0;
2905
+
2906
+ if (typeof scrollCustomFn === 'function') {
2907
+ if (scrollCustomFn.call(Sortable.dragged.parentNode[expando], scrollOffsetX, scrollOffsetY, evt, touchEvt$1, autoScrolls[this.layer].el) !== 'continue') {
2908
+ return;
2909
+ }
2910
+ }
2911
+
2912
+ scrollBy(autoScrolls[this.layer].el, scrollOffsetX, scrollOffsetY);
2913
+ }.bind({
2914
+ layer: layersOut
2915
+ }), 24);
2916
+ }
2917
+ }
2918
+
2919
+ layersOut++;
2920
+ } while (options.bubbleScroll && currentParent !== winScroller && (currentParent = getParentAutoScrollElement(currentParent, false)));
2921
+
2922
+ scrolling = scrollThisInstance; // in case another function catches scrolling as false in between when it is not
2923
+ }, 30);
2924
+
2925
+ var drop = function drop(_ref) {
2926
+ var originalEvent = _ref.originalEvent,
2927
+ putSortable = _ref.putSortable,
2928
+ dragEl = _ref.dragEl,
2929
+ activeSortable = _ref.activeSortable,
2930
+ dispatchSortableEvent = _ref.dispatchSortableEvent,
2931
+ hideGhostForTarget = _ref.hideGhostForTarget,
2932
+ unhideGhostForTarget = _ref.unhideGhostForTarget;
2933
+ if (!originalEvent) return;
2934
+ var toSortable = putSortable || activeSortable;
2935
+ hideGhostForTarget();
2936
+ var touch = originalEvent.changedTouches && originalEvent.changedTouches.length ? originalEvent.changedTouches[0] : originalEvent;
2937
+ var target = document.elementFromPoint(touch.clientX, touch.clientY);
2938
+ unhideGhostForTarget();
2939
+
2940
+ if (toSortable && !toSortable.el.contains(target)) {
2941
+ dispatchSortableEvent('spill');
2942
+ this.onSpill({
2943
+ dragEl: dragEl,
2944
+ putSortable: putSortable
2945
+ });
2946
+ }
2947
+ };
2948
+
2949
+ function Revert() {}
2950
+
2951
+ Revert.prototype = {
2952
+ startIndex: null,
2953
+ dragStart: function dragStart(_ref2) {
2954
+ var oldDraggableIndex = _ref2.oldDraggableIndex;
2955
+ this.startIndex = oldDraggableIndex;
2956
+ },
2957
+ onSpill: function onSpill(_ref3) {
2958
+ var dragEl = _ref3.dragEl,
2959
+ putSortable = _ref3.putSortable;
2960
+ this.sortable.captureAnimationState();
2961
+
2962
+ if (putSortable) {
2963
+ putSortable.captureAnimationState();
2964
+ }
2965
+
2966
+ var nextSibling = getChild(this.sortable.el, this.startIndex, this.options);
2967
+
2968
+ if (nextSibling) {
2969
+ this.sortable.el.insertBefore(dragEl, nextSibling);
2970
+ } else {
2971
+ this.sortable.el.appendChild(dragEl);
2972
+ }
2973
+
2974
+ this.sortable.animateAll();
2975
+
2976
+ if (putSortable) {
2977
+ putSortable.animateAll();
2978
+ }
2979
+ },
2980
+ drop: drop
2981
+ };
2982
+
2983
+ _extends(Revert, {
2984
+ pluginName: 'revertOnSpill'
2985
+ });
2986
+
2987
+ function Remove() {}
2988
+
2989
+ Remove.prototype = {
2990
+ onSpill: function onSpill(_ref4) {
2991
+ var dragEl = _ref4.dragEl,
2992
+ putSortable = _ref4.putSortable;
2993
+ var parentSortable = putSortable || this.sortable;
2994
+ parentSortable.captureAnimationState();
2995
+ dragEl.parentNode && dragEl.parentNode.removeChild(dragEl);
2996
+ parentSortable.animateAll();
2997
+ },
2998
+ drop: drop
2999
+ };
3000
+
3001
+ _extends(Remove, {
3002
+ pluginName: 'removeOnSpill'
3003
+ });
3004
+
3005
+ var lastSwapEl;
3006
+
3007
+ function SwapPlugin() {
3008
+ function Swap() {
3009
+ this.defaults = {
3010
+ swapClass: 'sortable-swap-highlight'
3011
+ };
3012
+ }
3013
+
3014
+ Swap.prototype = {
3015
+ dragStart: function dragStart(_ref) {
3016
+ var dragEl = _ref.dragEl;
3017
+ lastSwapEl = dragEl;
3018
+ },
3019
+ dragOverValid: function dragOverValid(_ref2) {
3020
+ var completed = _ref2.completed,
3021
+ target = _ref2.target,
3022
+ onMove = _ref2.onMove,
3023
+ activeSortable = _ref2.activeSortable,
3024
+ changed = _ref2.changed,
3025
+ cancel = _ref2.cancel;
3026
+ if (!activeSortable.options.swap) return;
3027
+ var el = this.sortable.el,
3028
+ options = this.options;
3029
+
3030
+ if (target && target !== el) {
3031
+ var prevSwapEl = lastSwapEl;
3032
+
3033
+ if (onMove(target) !== false) {
3034
+ toggleClass(target, options.swapClass, true);
3035
+ lastSwapEl = target;
3036
+ } else {
3037
+ lastSwapEl = null;
3038
+ }
3039
+
3040
+ if (prevSwapEl && prevSwapEl !== lastSwapEl) {
3041
+ toggleClass(prevSwapEl, options.swapClass, false);
3042
+ }
3043
+ }
3044
+
3045
+ changed();
3046
+ completed(true);
3047
+ cancel();
3048
+ },
3049
+ drop: function drop(_ref3) {
3050
+ var activeSortable = _ref3.activeSortable,
3051
+ putSortable = _ref3.putSortable,
3052
+ dragEl = _ref3.dragEl;
3053
+ var toSortable = putSortable || this.sortable;
3054
+ var options = this.options;
3055
+ lastSwapEl && toggleClass(lastSwapEl, options.swapClass, false);
3056
+
3057
+ if (lastSwapEl && (options.swap || putSortable && putSortable.options.swap)) {
3058
+ if (dragEl !== lastSwapEl) {
3059
+ toSortable.captureAnimationState();
3060
+ if (toSortable !== activeSortable) activeSortable.captureAnimationState();
3061
+ swapNodes(dragEl, lastSwapEl);
3062
+ toSortable.animateAll();
3063
+ if (toSortable !== activeSortable) activeSortable.animateAll();
3064
+ }
3065
+ }
3066
+ },
3067
+ nulling: function nulling() {
3068
+ lastSwapEl = null;
3069
+ }
3070
+ };
3071
+ return _extends(Swap, {
3072
+ pluginName: 'swap',
3073
+ eventProperties: function eventProperties() {
3074
+ return {
3075
+ swapItem: lastSwapEl
3076
+ };
3077
+ }
3078
+ });
3079
+ }
3080
+
3081
+ function swapNodes(n1, n2) {
3082
+ var p1 = n1.parentNode,
3083
+ p2 = n2.parentNode,
3084
+ i1,
3085
+ i2;
3086
+ if (!p1 || !p2 || p1.isEqualNode(n2) || p2.isEqualNode(n1)) return;
3087
+ i1 = index(n1);
3088
+ i2 = index(n2);
3089
+
3090
+ if (p1.isEqualNode(p2) && i1 < i2) {
3091
+ i2++;
3092
+ }
3093
+
3094
+ p1.insertBefore(n2, p1.children[i1]);
3095
+ p2.insertBefore(n1, p2.children[i2]);
3096
+ }
3097
+
3098
+ var multiDragElements = [],
3099
+ multiDragClones = [],
3100
+ lastMultiDragSelect,
3101
+ // for selection with modifier key down (SHIFT)
3102
+ multiDragSortable,
3103
+ initialFolding = false,
3104
+ // Initial multi-drag fold when drag started
3105
+ folding = false,
3106
+ // Folding any other time
3107
+ dragStarted = false,
3108
+ dragEl$1,
3109
+ clonesFromRect,
3110
+ clonesHidden;
3111
+
3112
+ function MultiDragPlugin() {
3113
+ function MultiDrag(sortable) {
3114
+ // Bind all private methods
3115
+ for (var fn in this) {
3116
+ if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
3117
+ this[fn] = this[fn].bind(this);
3118
+ }
3119
+ }
3120
+
3121
+ if (sortable.options.supportPointer) {
3122
+ on(document, 'pointerup', this._deselectMultiDrag);
3123
+ } else {
3124
+ on(document, 'mouseup', this._deselectMultiDrag);
3125
+ on(document, 'touchend', this._deselectMultiDrag);
3126
+ }
3127
+
3128
+ on(document, 'keydown', this._checkKeyDown);
3129
+ on(document, 'keyup', this._checkKeyUp);
3130
+ this.defaults = {
3131
+ selectedClass: 'sortable-selected',
3132
+ multiDragKey: null,
3133
+ setData: function setData(dataTransfer, dragEl) {
3134
+ var data = '';
3135
+
3136
+ if (multiDragElements.length && multiDragSortable === sortable) {
3137
+ multiDragElements.forEach(function (multiDragElement, i) {
3138
+ data += (!i ? '' : ', ') + multiDragElement.textContent;
3139
+ });
3140
+ } else {
3141
+ data = dragEl.textContent;
3142
+ }
3143
+
3144
+ dataTransfer.setData('Text', data);
3145
+ }
3146
+ };
3147
+ }
3148
+
3149
+ MultiDrag.prototype = {
3150
+ multiDragKeyDown: false,
3151
+ isMultiDrag: false,
3152
+ delayStartGlobal: function delayStartGlobal(_ref) {
3153
+ var dragged = _ref.dragEl;
3154
+ dragEl$1 = dragged;
3155
+ },
3156
+ delayEnded: function delayEnded() {
3157
+ this.isMultiDrag = ~multiDragElements.indexOf(dragEl$1);
3158
+ },
3159
+ setupClone: function setupClone(_ref2) {
3160
+ var sortable = _ref2.sortable,
3161
+ cancel = _ref2.cancel;
3162
+ if (!this.isMultiDrag) return;
3163
+
3164
+ for (var i = 0; i < multiDragElements.length; i++) {
3165
+ multiDragClones.push(clone(multiDragElements[i]));
3166
+ multiDragClones[i].sortableIndex = multiDragElements[i].sortableIndex;
3167
+ multiDragClones[i].draggable = false;
3168
+ multiDragClones[i].style['will-change'] = '';
3169
+ toggleClass(multiDragClones[i], this.options.selectedClass, false);
3170
+ multiDragElements[i] === dragEl$1 && toggleClass(multiDragClones[i], this.options.chosenClass, false);
3171
+ }
3172
+
3173
+ sortable._hideClone();
3174
+
3175
+ cancel();
3176
+ },
3177
+ clone: function clone(_ref3) {
3178
+ var sortable = _ref3.sortable,
3179
+ rootEl = _ref3.rootEl,
3180
+ dispatchSortableEvent = _ref3.dispatchSortableEvent,
3181
+ cancel = _ref3.cancel;
3182
+ if (!this.isMultiDrag) return;
3183
+
3184
+ if (!this.options.removeCloneOnHide) {
3185
+ if (multiDragElements.length && multiDragSortable === sortable) {
3186
+ insertMultiDragClones(true, rootEl);
3187
+ dispatchSortableEvent('clone');
3188
+ cancel();
3189
+ }
3190
+ }
3191
+ },
3192
+ showClone: function showClone(_ref4) {
3193
+ var cloneNowShown = _ref4.cloneNowShown,
3194
+ rootEl = _ref4.rootEl,
3195
+ cancel = _ref4.cancel;
3196
+ if (!this.isMultiDrag) return;
3197
+ insertMultiDragClones(false, rootEl);
3198
+ multiDragClones.forEach(function (clone) {
3199
+ css(clone, 'display', '');
3200
+ });
3201
+ cloneNowShown();
3202
+ clonesHidden = false;
3203
+ cancel();
3204
+ },
3205
+ hideClone: function hideClone(_ref5) {
3206
+ var _this = this;
3207
+
3208
+ var sortable = _ref5.sortable,
3209
+ cloneNowHidden = _ref5.cloneNowHidden,
3210
+ cancel = _ref5.cancel;
3211
+ if (!this.isMultiDrag) return;
3212
+ multiDragClones.forEach(function (clone) {
3213
+ css(clone, 'display', 'none');
3214
+
3215
+ if (_this.options.removeCloneOnHide && clone.parentNode) {
3216
+ clone.parentNode.removeChild(clone);
3217
+ }
3218
+ });
3219
+ cloneNowHidden();
3220
+ clonesHidden = true;
3221
+ cancel();
3222
+ },
3223
+ dragStartGlobal: function dragStartGlobal(_ref6) {
3224
+ var sortable = _ref6.sortable;
3225
+
3226
+ if (!this.isMultiDrag && multiDragSortable) {
3227
+ multiDragSortable.multiDrag._deselectMultiDrag();
3228
+ }
3229
+
3230
+ multiDragElements.forEach(function (multiDragElement) {
3231
+ multiDragElement.sortableIndex = index(multiDragElement);
3232
+ }); // Sort multi-drag elements
3233
+
3234
+ multiDragElements = multiDragElements.sort(function (a, b) {
3235
+ return a.sortableIndex - b.sortableIndex;
3236
+ });
3237
+ dragStarted = true;
3238
+ },
3239
+ dragStarted: function dragStarted(_ref7) {
3240
+ var _this2 = this;
3241
+
3242
+ var sortable = _ref7.sortable;
3243
+ if (!this.isMultiDrag) return;
3244
+
3245
+ if (this.options.sort) {
3246
+ // Capture rects,
3247
+ // hide multi drag elements (by positioning them absolute),
3248
+ // set multi drag elements rects to dragRect,
3249
+ // show multi drag elements,
3250
+ // animate to rects,
3251
+ // unset rects & remove from DOM
3252
+ sortable.captureAnimationState();
3253
+
3254
+ if (this.options.animation) {
3255
+ multiDragElements.forEach(function (multiDragElement) {
3256
+ if (multiDragElement === dragEl$1) return;
3257
+ css(multiDragElement, 'position', 'absolute');
3258
+ });
3259
+ var dragRect = getRect(dragEl$1, false, true, true);
3260
+ multiDragElements.forEach(function (multiDragElement) {
3261
+ if (multiDragElement === dragEl$1) return;
3262
+ setRect(multiDragElement, dragRect);
3263
+ });
3264
+ folding = true;
3265
+ initialFolding = true;
3266
+ }
3267
+ }
3268
+
3269
+ sortable.animateAll(function () {
3270
+ folding = false;
3271
+ initialFolding = false;
3272
+
3273
+ if (_this2.options.animation) {
3274
+ multiDragElements.forEach(function (multiDragElement) {
3275
+ unsetRect(multiDragElement);
3276
+ });
3277
+ } // Remove all auxiliary multidrag items from el, if sorting enabled
3278
+
3279
+
3280
+ if (_this2.options.sort) {
3281
+ removeMultiDragElements();
3282
+ }
3283
+ });
3284
+ },
3285
+ dragOver: function dragOver(_ref8) {
3286
+ var target = _ref8.target,
3287
+ completed = _ref8.completed,
3288
+ cancel = _ref8.cancel;
3289
+
3290
+ if (folding && ~multiDragElements.indexOf(target)) {
3291
+ completed(false);
3292
+ cancel();
3293
+ }
3294
+ },
3295
+ revert: function revert(_ref9) {
3296
+ var fromSortable = _ref9.fromSortable,
3297
+ rootEl = _ref9.rootEl,
3298
+ sortable = _ref9.sortable,
3299
+ dragRect = _ref9.dragRect;
3300
+
3301
+ if (multiDragElements.length > 1) {
3302
+ // Setup unfold animation
3303
+ multiDragElements.forEach(function (multiDragElement) {
3304
+ sortable.addAnimationState({
3305
+ target: multiDragElement,
3306
+ rect: folding ? getRect(multiDragElement) : dragRect
3307
+ });
3308
+ unsetRect(multiDragElement);
3309
+ multiDragElement.fromRect = dragRect;
3310
+ fromSortable.removeAnimationState(multiDragElement);
3311
+ });
3312
+ folding = false;
3313
+ insertMultiDragElements(!this.options.removeCloneOnHide, rootEl);
3314
+ }
3315
+ },
3316
+ dragOverCompleted: function dragOverCompleted(_ref10) {
3317
+ var sortable = _ref10.sortable,
3318
+ isOwner = _ref10.isOwner,
3319
+ insertion = _ref10.insertion,
3320
+ activeSortable = _ref10.activeSortable,
3321
+ parentEl = _ref10.parentEl,
3322
+ putSortable = _ref10.putSortable;
3323
+ var options = this.options;
3324
+
3325
+ if (insertion) {
3326
+ // Clones must be hidden before folding animation to capture dragRectAbsolute properly
3327
+ if (isOwner) {
3328
+ activeSortable._hideClone();
3329
+ }
3330
+
3331
+ initialFolding = false; // If leaving sort:false root, or already folding - Fold to new location
3332
+
3333
+ if (options.animation && multiDragElements.length > 1 && (folding || !isOwner && !activeSortable.options.sort && !putSortable)) {
3334
+ // Fold: Set all multi drag elements's rects to dragEl's rect when multi-drag elements are invisible
3335
+ var dragRectAbsolute = getRect(dragEl$1, false, true, true);
3336
+ multiDragElements.forEach(function (multiDragElement) {
3337
+ if (multiDragElement === dragEl$1) return;
3338
+ setRect(multiDragElement, dragRectAbsolute); // Move element(s) to end of parentEl so that it does not interfere with multi-drag clones insertion if they are inserted
3339
+ // while folding, and so that we can capture them again because old sortable will no longer be fromSortable
3340
+
3341
+ parentEl.appendChild(multiDragElement);
3342
+ });
3343
+ folding = true;
3344
+ } // Clones must be shown (and check to remove multi drags) after folding when interfering multiDragElements are moved out
3345
+
3346
+
3347
+ if (!isOwner) {
3348
+ // Only remove if not folding (folding will remove them anyways)
3349
+ if (!folding) {
3350
+ removeMultiDragElements();
3351
+ }
3352
+
3353
+ if (multiDragElements.length > 1) {
3354
+ var clonesHiddenBefore = clonesHidden;
3355
+
3356
+ activeSortable._showClone(sortable); // Unfold animation for clones if showing from hidden
3357
+
3358
+
3359
+ if (activeSortable.options.animation && !clonesHidden && clonesHiddenBefore) {
3360
+ multiDragClones.forEach(function (clone) {
3361
+ activeSortable.addAnimationState({
3362
+ target: clone,
3363
+ rect: clonesFromRect
3364
+ });
3365
+ clone.fromRect = clonesFromRect;
3366
+ clone.thisAnimationDuration = null;
3367
+ });
3368
+ }
3369
+ } else {
3370
+ activeSortable._showClone(sortable);
3371
+ }
3372
+ }
3373
+ }
3374
+ },
3375
+ dragOverAnimationCapture: function dragOverAnimationCapture(_ref11) {
3376
+ var dragRect = _ref11.dragRect,
3377
+ isOwner = _ref11.isOwner,
3378
+ activeSortable = _ref11.activeSortable;
3379
+ multiDragElements.forEach(function (multiDragElement) {
3380
+ multiDragElement.thisAnimationDuration = null;
3381
+ });
3382
+
3383
+ if (activeSortable.options.animation && !isOwner && activeSortable.multiDrag.isMultiDrag) {
3384
+ clonesFromRect = _extends({}, dragRect);
3385
+ var dragMatrix = matrix(dragEl$1, true);
3386
+ clonesFromRect.top -= dragMatrix.f;
3387
+ clonesFromRect.left -= dragMatrix.e;
3388
+ }
3389
+ },
3390
+ dragOverAnimationComplete: function dragOverAnimationComplete() {
3391
+ if (folding) {
3392
+ folding = false;
3393
+ removeMultiDragElements();
3394
+ }
3395
+ },
3396
+ drop: function drop(_ref12) {
3397
+ var evt = _ref12.originalEvent,
3398
+ rootEl = _ref12.rootEl,
3399
+ parentEl = _ref12.parentEl,
3400
+ sortable = _ref12.sortable,
3401
+ dispatchSortableEvent = _ref12.dispatchSortableEvent,
3402
+ oldIndex = _ref12.oldIndex,
3403
+ putSortable = _ref12.putSortable;
3404
+ var toSortable = putSortable || this.sortable;
3405
+ if (!evt) return;
3406
+ var options = this.options,
3407
+ children = parentEl.children; // Multi-drag selection
3408
+
3409
+ if (!dragStarted) {
3410
+ if (options.multiDragKey && !this.multiDragKeyDown) {
3411
+ this._deselectMultiDrag();
3412
+ }
3413
+
3414
+ toggleClass(dragEl$1, options.selectedClass, !~multiDragElements.indexOf(dragEl$1));
3415
+
3416
+ if (!~multiDragElements.indexOf(dragEl$1)) {
3417
+ multiDragElements.push(dragEl$1);
3418
+ dispatchEvent({
3419
+ sortable: sortable,
3420
+ rootEl: rootEl,
3421
+ name: 'select',
3422
+ targetEl: dragEl$1,
3423
+ originalEvt: evt
3424
+ }); // Modifier activated, select from last to dragEl
3425
+
3426
+ if (evt.shiftKey && lastMultiDragSelect && sortable.el.contains(lastMultiDragSelect)) {
3427
+ var lastIndex = index(lastMultiDragSelect),
3428
+ currentIndex = index(dragEl$1);
3429
+
3430
+ if (~lastIndex && ~currentIndex && lastIndex !== currentIndex) {
3431
+ // Must include lastMultiDragSelect (select it), in case modified selection from no selection
3432
+ // (but previous selection existed)
3433
+ var n, i;
3434
+
3435
+ if (currentIndex > lastIndex) {
3436
+ i = lastIndex;
3437
+ n = currentIndex;
3438
+ } else {
3439
+ i = currentIndex;
3440
+ n = lastIndex + 1;
3441
+ }
3442
+
3443
+ for (; i < n; i++) {
3444
+ if (~multiDragElements.indexOf(children[i])) continue;
3445
+ toggleClass(children[i], options.selectedClass, true);
3446
+ multiDragElements.push(children[i]);
3447
+ dispatchEvent({
3448
+ sortable: sortable,
3449
+ rootEl: rootEl,
3450
+ name: 'select',
3451
+ targetEl: children[i],
3452
+ originalEvt: evt
3453
+ });
3454
+ }
3455
+ }
3456
+ } else {
3457
+ lastMultiDragSelect = dragEl$1;
3458
+ }
3459
+
3460
+ multiDragSortable = toSortable;
3461
+ } else {
3462
+ multiDragElements.splice(multiDragElements.indexOf(dragEl$1), 1);
3463
+ lastMultiDragSelect = null;
3464
+ dispatchEvent({
3465
+ sortable: sortable,
3466
+ rootEl: rootEl,
3467
+ name: 'deselect',
3468
+ targetEl: dragEl$1,
3469
+ originalEvt: evt
3470
+ });
3471
+ }
3472
+ } // Multi-drag drop
3473
+
3474
+
3475
+ if (dragStarted && this.isMultiDrag) {
3476
+ // Do not "unfold" after around dragEl if reverted
3477
+ if ((parentEl[expando].options.sort || parentEl !== rootEl) && multiDragElements.length > 1) {
3478
+ var dragRect = getRect(dragEl$1),
3479
+ multiDragIndex = index(dragEl$1, ':not(.' + this.options.selectedClass + ')');
3480
+ if (!initialFolding && options.animation) dragEl$1.thisAnimationDuration = null;
3481
+ toSortable.captureAnimationState();
3482
+
3483
+ if (!initialFolding) {
3484
+ if (options.animation) {
3485
+ dragEl$1.fromRect = dragRect;
3486
+ multiDragElements.forEach(function (multiDragElement) {
3487
+ multiDragElement.thisAnimationDuration = null;
3488
+
3489
+ if (multiDragElement !== dragEl$1) {
3490
+ var rect = folding ? getRect(multiDragElement) : dragRect;
3491
+ multiDragElement.fromRect = rect; // Prepare unfold animation
3492
+
3493
+ toSortable.addAnimationState({
3494
+ target: multiDragElement,
3495
+ rect: rect
3496
+ });
3497
+ }
3498
+ });
3499
+ } // Multi drag elements are not necessarily removed from the DOM on drop, so to reinsert
3500
+ // properly they must all be removed
3501
+
3502
+
3503
+ removeMultiDragElements();
3504
+ multiDragElements.forEach(function (multiDragElement) {
3505
+ if (children[multiDragIndex]) {
3506
+ parentEl.insertBefore(multiDragElement, children[multiDragIndex]);
3507
+ } else {
3508
+ parentEl.appendChild(multiDragElement);
3509
+ }
3510
+
3511
+ multiDragIndex++;
3512
+ }); // If initial folding is done, the elements may have changed position because they are now
3513
+ // unfolding around dragEl, even though dragEl may not have his index changed, so update event
3514
+ // must be fired here as Sortable will not.
3515
+
3516
+ if (oldIndex === index(dragEl$1)) {
3517
+ var update = false;
3518
+ multiDragElements.forEach(function (multiDragElement) {
3519
+ if (multiDragElement.sortableIndex !== index(multiDragElement)) {
3520
+ update = true;
3521
+ return;
3522
+ }
3523
+ });
3524
+
3525
+ if (update) {
3526
+ dispatchSortableEvent('update');
3527
+ }
3528
+ }
3529
+ } // Must be done after capturing individual rects (scroll bar)
3530
+
3531
+
3532
+ multiDragElements.forEach(function (multiDragElement) {
3533
+ unsetRect(multiDragElement);
3534
+ });
3535
+ toSortable.animateAll();
3536
+ }
3537
+
3538
+ multiDragSortable = toSortable;
3539
+ } // Remove clones if necessary
3540
+
3541
+
3542
+ if (rootEl === parentEl || putSortable && putSortable.lastPutMode !== 'clone') {
3543
+ multiDragClones.forEach(function (clone) {
3544
+ clone.parentNode && clone.parentNode.removeChild(clone);
3545
+ });
3546
+ }
3547
+ },
3548
+ nullingGlobal: function nullingGlobal() {
3549
+ this.isMultiDrag = dragStarted = false;
3550
+ multiDragClones.length = 0;
3551
+ },
3552
+ destroyGlobal: function destroyGlobal() {
3553
+ this._deselectMultiDrag();
3554
+
3555
+ off(document, 'pointerup', this._deselectMultiDrag);
3556
+ off(document, 'mouseup', this._deselectMultiDrag);
3557
+ off(document, 'touchend', this._deselectMultiDrag);
3558
+ off(document, 'keydown', this._checkKeyDown);
3559
+ off(document, 'keyup', this._checkKeyUp);
3560
+ },
3561
+ _deselectMultiDrag: function _deselectMultiDrag(evt) {
3562
+ if (typeof dragStarted !== "undefined" && dragStarted) return; // Only deselect if selection is in this sortable
3563
+
3564
+ if (multiDragSortable !== this.sortable) return; // Only deselect if target is not item in this sortable
3565
+
3566
+ if (evt && closest(evt.target, this.options.draggable, this.sortable.el, false)) return; // Only deselect if left click
3567
+
3568
+ if (evt && evt.button !== 0) return;
3569
+
3570
+ while (multiDragElements.length) {
3571
+ var el = multiDragElements[0];
3572
+ toggleClass(el, this.options.selectedClass, false);
3573
+ multiDragElements.shift();
3574
+ dispatchEvent({
3575
+ sortable: this.sortable,
3576
+ rootEl: this.sortable.el,
3577
+ name: 'deselect',
3578
+ targetEl: el,
3579
+ originalEvt: evt
3580
+ });
3581
+ }
3582
+ },
3583
+ _checkKeyDown: function _checkKeyDown(evt) {
3584
+ if (evt.key === this.options.multiDragKey) {
3585
+ this.multiDragKeyDown = true;
3586
+ }
3587
+ },
3588
+ _checkKeyUp: function _checkKeyUp(evt) {
3589
+ if (evt.key === this.options.multiDragKey) {
3590
+ this.multiDragKeyDown = false;
3591
+ }
3592
+ }
3593
+ };
3594
+ return _extends(MultiDrag, {
3595
+ // Static methods & properties
3596
+ pluginName: 'multiDrag',
3597
+ utils: {
3598
+ /**
3599
+ * Selects the provided multi-drag item
3600
+ * @param {HTMLElement} el The element to be selected
3601
+ */
3602
+ select: function select(el) {
3603
+ var sortable = el.parentNode[expando];
3604
+ if (!sortable || !sortable.options.multiDrag || ~multiDragElements.indexOf(el)) return;
3605
+
3606
+ if (multiDragSortable && multiDragSortable !== sortable) {
3607
+ multiDragSortable.multiDrag._deselectMultiDrag();
3608
+
3609
+ multiDragSortable = sortable;
3610
+ }
3611
+
3612
+ toggleClass(el, sortable.options.selectedClass, true);
3613
+ multiDragElements.push(el);
3614
+ },
3615
+
3616
+ /**
3617
+ * Deselects the provided multi-drag item
3618
+ * @param {HTMLElement} el The element to be deselected
3619
+ */
3620
+ deselect: function deselect(el) {
3621
+ var sortable = el.parentNode[expando],
3622
+ index = multiDragElements.indexOf(el);
3623
+ if (!sortable || !sortable.options.multiDrag || !~index) return;
3624
+ toggleClass(el, sortable.options.selectedClass, false);
3625
+ multiDragElements.splice(index, 1);
3626
+ }
3627
+ },
3628
+ eventProperties: function eventProperties() {
3629
+ var _this3 = this;
3630
+
3631
+ var oldIndicies = [],
3632
+ newIndicies = [];
3633
+ multiDragElements.forEach(function (multiDragElement) {
3634
+ oldIndicies.push({
3635
+ multiDragElement: multiDragElement,
3636
+ index: multiDragElement.sortableIndex
3637
+ }); // multiDragElements will already be sorted if folding
3638
+
3639
+ var newIndex;
3640
+
3641
+ if (folding && multiDragElement !== dragEl$1) {
3642
+ newIndex = -1;
3643
+ } else if (folding) {
3644
+ newIndex = index(multiDragElement, ':not(.' + _this3.options.selectedClass + ')');
3645
+ } else {
3646
+ newIndex = index(multiDragElement);
3647
+ }
3648
+
3649
+ newIndicies.push({
3650
+ multiDragElement: multiDragElement,
3651
+ index: newIndex
3652
+ });
3653
+ });
3654
+ return {
3655
+ items: _toConsumableArray(multiDragElements),
3656
+ clones: [].concat(multiDragClones),
3657
+ oldIndicies: oldIndicies,
3658
+ newIndicies: newIndicies
3659
+ };
3660
+ },
3661
+ optionListeners: {
3662
+ multiDragKey: function multiDragKey(key) {
3663
+ key = key.toLowerCase();
3664
+
3665
+ if (key === 'ctrl') {
3666
+ key = 'Control';
3667
+ } else if (key.length > 1) {
3668
+ key = key.charAt(0).toUpperCase() + key.substr(1);
3669
+ }
3670
+
3671
+ return key;
3672
+ }
3673
+ }
3674
+ });
3675
+ }
3676
+
3677
+ function insertMultiDragElements(clonesInserted, rootEl) {
3678
+ multiDragElements.forEach(function (multiDragElement, i) {
3679
+ var target = rootEl.children[multiDragElement.sortableIndex + (clonesInserted ? Number(i) : 0)];
3680
+
3681
+ if (target) {
3682
+ rootEl.insertBefore(multiDragElement, target);
3683
+ } else {
3684
+ rootEl.appendChild(multiDragElement);
3685
+ }
3686
+ });
3687
+ }
3688
+ /**
3689
+ * Insert multi-drag clones
3690
+ * @param {[Boolean]} elementsInserted Whether the multi-drag elements are inserted
3691
+ * @param {HTMLElement} rootEl
3692
+ */
3693
+
3694
+
3695
+ function insertMultiDragClones(elementsInserted, rootEl) {
3696
+ multiDragClones.forEach(function (clone, i) {
3697
+ var target = rootEl.children[clone.sortableIndex + (elementsInserted ? Number(i) : 0)];
3698
+
3699
+ if (target) {
3700
+ rootEl.insertBefore(clone, target);
3701
+ } else {
3702
+ rootEl.appendChild(clone);
3703
+ }
3704
+ });
3705
+ }
3706
+
3707
+ function removeMultiDragElements() {
3708
+ multiDragElements.forEach(function (multiDragElement) {
3709
+ if (multiDragElement === dragEl$1) return;
3710
+ multiDragElement.parentNode && multiDragElement.parentNode.removeChild(multiDragElement);
3711
+ });
3712
+ }
3713
+
3714
+ Sortable.mount(new AutoScrollPlugin());
3715
+ Sortable.mount(Remove, Revert);
3716
+
3717
+ Sortable.mount(new SwapPlugin());
3718
+ Sortable.mount(new MultiDragPlugin());
3719
+
3720
+ return Sortable;
3721
+
3722
+ }));