sortable-rails 1.4.2.2 → 1.7.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: add29262b604c8f0f72de3852b9925c8a9197d4e56ee8c27b0e4de96a47d1cf3
|
4
|
+
data.tar.gz: 3c9e21f967f2a21ece80bc332117961f76dadd1bb3b047cdafabe9343cbc6061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4160a55b0e0ce80c2a44f211db40dca31a363bab776582960fa89f7b00a94b77f83da47177125cd2d93580fccb441bc2dadb41022da5d345bde76d6af5f03d40
|
7
|
+
data.tar.gz: dd953211af3c135f1f9d37c97a4c13bd8135420ba00be39f34fa30701f0d5506a1accc432761f45fb38bbb710756b4626ce50cfa88cb4025e2c424c8655c4b0e
|
@@ -4,8 +4,7 @@
|
|
4
4
|
* @license MIT
|
5
5
|
*/
|
6
6
|
|
7
|
-
|
8
|
-
(function (factory) {
|
7
|
+
(function sortableModule(factory) {
|
9
8
|
"use strict";
|
10
9
|
|
11
10
|
if (typeof define === "function" && define.amd) {
|
@@ -14,20 +13,17 @@
|
|
14
13
|
else if (typeof module != "undefined" && typeof module.exports != "undefined") {
|
15
14
|
module.exports = factory();
|
16
15
|
}
|
17
|
-
else if (typeof Package !== "undefined") {
|
18
|
-
Sortable = factory(); // export for Meteor.js
|
19
|
-
}
|
20
16
|
else {
|
21
17
|
/* jshint sub:true */
|
22
18
|
window["Sortable"] = factory();
|
23
19
|
}
|
24
|
-
})(function () {
|
20
|
+
})(function sortableFactory() {
|
25
21
|
"use strict";
|
26
|
-
|
27
|
-
if (typeof window
|
28
|
-
return function() {
|
29
|
-
throw new Error(
|
30
|
-
}
|
22
|
+
|
23
|
+
if (typeof window === "undefined" || !window.document) {
|
24
|
+
return function sortableError() {
|
25
|
+
throw new Error("Sortable.js requires a window with a document");
|
26
|
+
};
|
31
27
|
}
|
32
28
|
|
33
29
|
var dragEl,
|
@@ -36,9 +32,11 @@
|
|
36
32
|
cloneEl,
|
37
33
|
rootEl,
|
38
34
|
nextEl,
|
35
|
+
lastDownEl,
|
39
36
|
|
40
37
|
scrollEl,
|
41
38
|
scrollParentEl,
|
39
|
+
scrollCustomFn,
|
42
40
|
|
43
41
|
lastEl,
|
44
42
|
lastCSS,
|
@@ -48,6 +46,8 @@
|
|
48
46
|
newIndex,
|
49
47
|
|
50
48
|
activeGroup,
|
49
|
+
putSortable,
|
50
|
+
|
51
51
|
autoScroll = {},
|
52
52
|
|
53
53
|
tapEvt,
|
@@ -55,17 +55,31 @@
|
|
55
55
|
|
56
56
|
moved,
|
57
57
|
|
58
|
+
forRepaintDummy,
|
59
|
+
|
58
60
|
/** @const */
|
59
|
-
|
61
|
+
R_SPACE = /\s+/g,
|
62
|
+
R_FLOAT = /left|right|inline/,
|
60
63
|
|
61
64
|
expando = 'Sortable' + (new Date).getTime(),
|
62
65
|
|
63
66
|
win = window,
|
64
67
|
document = win.document,
|
65
68
|
parseInt = win.parseInt,
|
69
|
+
setTimeout = win.setTimeout,
|
70
|
+
|
71
|
+
$ = win.jQuery || win.Zepto,
|
72
|
+
Polymer = win.Polymer,
|
66
73
|
|
67
|
-
|
74
|
+
captureMode = false,
|
75
|
+
passiveMode = false,
|
76
|
+
|
77
|
+
supportDraggable = ('draggable' in document.createElement('div')),
|
68
78
|
supportCssPointerEvents = (function (el) {
|
79
|
+
// false when IE11
|
80
|
+
if (!!navigator.userAgent.match(/(?:Trident.*rv[ :]?11\.|msie)/i)) {
|
81
|
+
return false;
|
82
|
+
}
|
69
83
|
el = document.createElement('x');
|
70
84
|
el.style.cssText = 'pointer-events:auto';
|
71
85
|
return el.style.pointerEvents === 'auto';
|
@@ -74,14 +88,18 @@
|
|
74
88
|
_silent = false,
|
75
89
|
|
76
90
|
abs = Math.abs,
|
77
|
-
|
91
|
+
min = Math.min,
|
78
92
|
|
93
|
+
savedInputChecked = [],
|
79
94
|
touchDragOverListeners = [],
|
80
95
|
|
96
|
+
alwaysFalse = function () { return false; },
|
97
|
+
|
81
98
|
_autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) {
|
82
99
|
// Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
|
83
100
|
if (rootEl && options.scroll) {
|
84
|
-
var
|
101
|
+
var _this = rootEl[expando],
|
102
|
+
el,
|
85
103
|
rect,
|
86
104
|
sens = options.scrollSensitivity,
|
87
105
|
speed = options.scrollSpeed,
|
@@ -93,13 +111,17 @@
|
|
93
111
|
winHeight = window.innerHeight,
|
94
112
|
|
95
113
|
vx,
|
96
|
-
vy
|
114
|
+
vy,
|
115
|
+
|
116
|
+
scrollOffsetX,
|
117
|
+
scrollOffsetY
|
97
118
|
;
|
98
119
|
|
99
120
|
// Delect scrollEl
|
100
121
|
if (scrollParentEl !== rootEl) {
|
101
122
|
scrollEl = options.scroll;
|
102
123
|
scrollParentEl = rootEl;
|
124
|
+
scrollCustomFn = options.scrollFn;
|
103
125
|
|
104
126
|
if (scrollEl === true) {
|
105
127
|
scrollEl = rootEl;
|
@@ -141,11 +163,20 @@
|
|
141
163
|
|
142
164
|
if (el) {
|
143
165
|
autoScroll.pid = setInterval(function () {
|
166
|
+
scrollOffsetY = vy ? vy * speed : 0;
|
167
|
+
scrollOffsetX = vx ? vx * speed : 0;
|
168
|
+
|
169
|
+
if ('function' === typeof(scrollCustomFn)) {
|
170
|
+
if (scrollCustomFn.call(_this, scrollOffsetX, scrollOffsetY, evt, touchEvt, el) !== 'continue') {
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
|
144
175
|
if (el === win) {
|
145
|
-
win.scrollTo(win.pageXOffset +
|
176
|
+
win.scrollTo(win.pageXOffset + scrollOffsetX, win.pageYOffset + scrollOffsetY);
|
146
177
|
} else {
|
147
|
-
|
148
|
-
|
178
|
+
el.scrollTop += scrollOffsetY;
|
179
|
+
el.scrollLeft += scrollOffsetX;
|
149
180
|
}
|
150
181
|
}, 24);
|
151
182
|
}
|
@@ -154,23 +185,60 @@
|
|
154
185
|
}, 30),
|
155
186
|
|
156
187
|
_prepareGroup = function (options) {
|
157
|
-
|
188
|
+
function toFn(value, pull) {
|
189
|
+
if (value == null || value === true) {
|
190
|
+
value = group.name;
|
191
|
+
if (value == null) {
|
192
|
+
return alwaysFalse;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
|
196
|
+
if (typeof value === 'function') {
|
197
|
+
return value;
|
198
|
+
} else {
|
199
|
+
return function (to, from) {
|
200
|
+
var fromGroup = from.options.group.name;
|
201
|
+
|
202
|
+
return pull
|
203
|
+
? value
|
204
|
+
: value && (value.join
|
205
|
+
? value.indexOf(fromGroup) > -1
|
206
|
+
: (fromGroup == value)
|
207
|
+
);
|
208
|
+
};
|
209
|
+
}
|
210
|
+
}
|
211
|
+
|
212
|
+
var group = {};
|
213
|
+
var originalGroup = options.group;
|
158
214
|
|
159
|
-
if (!
|
160
|
-
|
215
|
+
if (!originalGroup || typeof originalGroup != 'object') {
|
216
|
+
originalGroup = {name: originalGroup};
|
161
217
|
}
|
162
218
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
});
|
219
|
+
group.name = originalGroup.name;
|
220
|
+
group.checkPull = toFn(originalGroup.pull, true);
|
221
|
+
group.checkPut = toFn(originalGroup.put);
|
222
|
+
group.revertClone = originalGroup.revertClone;
|
168
223
|
|
169
|
-
options.
|
224
|
+
options.group = group;
|
170
225
|
}
|
171
226
|
;
|
172
227
|
|
173
|
-
|
228
|
+
// Detect support a passive mode
|
229
|
+
try {
|
230
|
+
window.addEventListener('test', null, Object.defineProperty({}, 'passive', {
|
231
|
+
get: function () {
|
232
|
+
// `false`, because everything starts to work incorrectly and instead of d'n'd,
|
233
|
+
// begins the page has scrolled.
|
234
|
+
passiveMode = false;
|
235
|
+
captureMode = {
|
236
|
+
capture: false,
|
237
|
+
passive: passiveMode
|
238
|
+
};
|
239
|
+
}
|
240
|
+
}));
|
241
|
+
} catch (err) {}
|
174
242
|
|
175
243
|
/**
|
176
244
|
* @class Sortable
|
@@ -189,22 +257,23 @@
|
|
189
257
|
// Export instance
|
190
258
|
el[expando] = this;
|
191
259
|
|
192
|
-
|
193
260
|
// Default options
|
194
261
|
var defaults = {
|
195
|
-
group:
|
262
|
+
group: null,
|
196
263
|
sort: true,
|
197
264
|
disabled: false,
|
198
265
|
store: null,
|
199
266
|
handle: null,
|
200
|
-
|
267
|
+
scroll: true,
|
201
268
|
scrollSensitivity: 30,
|
202
269
|
scrollSpeed: 10,
|
203
270
|
draggable: /[uo]l/i.test(el.nodeName) ? 'li' : '>*',
|
204
271
|
ghostClass: 'sortable-ghost',
|
205
272
|
chosenClass: 'sortable-chosen',
|
273
|
+
dragClass: 'sortable-drag',
|
206
274
|
ignore: 'a, img',
|
207
275
|
filter: null,
|
276
|
+
preventOnFilter: true,
|
208
277
|
animation: 0,
|
209
278
|
setData: function (dataTransfer, dragEl) {
|
210
279
|
dataTransfer.setData('Text', dragEl.textContent);
|
@@ -213,9 +282,13 @@
|
|
213
282
|
dragoverBubble: false,
|
214
283
|
dataIdAttr: 'data-id',
|
215
284
|
delay: 0,
|
285
|
+
touchStartThreshold: parseInt(window.devicePixelRatio, 10) || 1,
|
216
286
|
forceFallback: false,
|
217
287
|
fallbackClass: 'sortable-fallback',
|
218
|
-
fallbackOnBody: false
|
288
|
+
fallbackOnBody: false,
|
289
|
+
fallbackTolerance: 0,
|
290
|
+
fallbackOffset: {x: 0, y: 0},
|
291
|
+
supportPointer: Sortable.supportPointer !== false
|
219
292
|
};
|
220
293
|
|
221
294
|
|
@@ -228,7 +301,7 @@
|
|
228
301
|
|
229
302
|
// Bind all private methods
|
230
303
|
for (var fn in this) {
|
231
|
-
if (fn.charAt(0) === '_') {
|
304
|
+
if (fn.charAt(0) === '_' && typeof this[fn] === 'function') {
|
232
305
|
this[fn] = this[fn].bind(this);
|
233
306
|
}
|
234
307
|
}
|
@@ -239,6 +312,7 @@
|
|
239
312
|
// Bind events
|
240
313
|
_on(el, 'mousedown', this._onTapStart);
|
241
314
|
_on(el, 'touchstart', this._onTapStart);
|
315
|
+
options.supportPointer && _on(el, 'pointerdown', this._onTapStart);
|
242
316
|
|
243
317
|
if (this.nativeDraggable) {
|
244
318
|
_on(el, 'dragover', this);
|
@@ -259,31 +333,50 @@
|
|
259
333
|
var _this = this,
|
260
334
|
el = this.el,
|
261
335
|
options = this.options,
|
336
|
+
preventOnFilter = options.preventOnFilter,
|
262
337
|
type = evt.type,
|
263
338
|
touch = evt.touches && evt.touches[0],
|
264
339
|
target = (touch || evt).target,
|
265
|
-
originalTarget = target,
|
266
|
-
filter = options.filter
|
340
|
+
originalTarget = evt.target.shadowRoot && (evt.path && evt.path[0]) || target,
|
341
|
+
filter = options.filter,
|
342
|
+
startIndex;
|
343
|
+
|
344
|
+
_saveInputCheckedState(el);
|
267
345
|
|
268
346
|
|
269
|
-
|
347
|
+
// Don't trigger start event when an element is been dragged, otherwise the evt.oldindex always wrong when set option.group.
|
348
|
+
if (dragEl) {
|
349
|
+
return;
|
350
|
+
}
|
351
|
+
|
352
|
+
if (/mousedown|pointerdown/.test(type) && evt.button !== 0 || options.disabled) {
|
270
353
|
return; // only left button or enabled
|
271
354
|
}
|
272
355
|
|
356
|
+
// cancel dnd if original target is content editable
|
357
|
+
if (originalTarget.isContentEditable) {
|
358
|
+
return;
|
359
|
+
}
|
360
|
+
|
273
361
|
target = _closest(target, options.draggable, el);
|
274
362
|
|
275
363
|
if (!target) {
|
276
364
|
return;
|
277
365
|
}
|
278
366
|
|
279
|
-
|
280
|
-
|
367
|
+
if (lastDownEl === target) {
|
368
|
+
// Ignoring duplicate `down`
|
369
|
+
return;
|
370
|
+
}
|
371
|
+
|
372
|
+
// Get the index of the dragged element within its parent
|
373
|
+
startIndex = _index(target, options.draggable);
|
281
374
|
|
282
375
|
// Check filter
|
283
376
|
if (typeof filter === 'function') {
|
284
377
|
if (filter.call(this, evt, target, this)) {
|
285
|
-
_dispatchEvent(_this, originalTarget, 'filter', target, el,
|
286
|
-
evt.preventDefault();
|
378
|
+
_dispatchEvent(_this, originalTarget, 'filter', target, el, el, startIndex);
|
379
|
+
preventOnFilter && evt.preventDefault();
|
287
380
|
return; // cancel dnd
|
288
381
|
}
|
289
382
|
}
|
@@ -292,28 +385,26 @@
|
|
292
385
|
criteria = _closest(originalTarget, criteria.trim(), el);
|
293
386
|
|
294
387
|
if (criteria) {
|
295
|
-
_dispatchEvent(_this, criteria, 'filter', target, el,
|
388
|
+
_dispatchEvent(_this, criteria, 'filter', target, el, el, startIndex);
|
296
389
|
return true;
|
297
390
|
}
|
298
391
|
});
|
299
392
|
|
300
393
|
if (filter) {
|
301
|
-
evt.preventDefault();
|
394
|
+
preventOnFilter && evt.preventDefault();
|
302
395
|
return; // cancel dnd
|
303
396
|
}
|
304
397
|
}
|
305
398
|
|
306
|
-
|
307
399
|
if (options.handle && !_closest(originalTarget, options.handle, el)) {
|
308
400
|
return;
|
309
401
|
}
|
310
402
|
|
311
|
-
|
312
403
|
// Prepare `dragstart`
|
313
|
-
this._prepareDragStart(evt, touch, target);
|
404
|
+
this._prepareDragStart(evt, touch, target, startIndex);
|
314
405
|
},
|
315
406
|
|
316
|
-
_prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target) {
|
407
|
+
_prepareDragStart: function (/** Event */evt, /** Touch */touch, /** HTMLElement */target, /** Number */startIndex) {
|
317
408
|
var _this = this,
|
318
409
|
el = _this.el,
|
319
410
|
options = _this.options,
|
@@ -327,7 +418,14 @@
|
|
327
418
|
dragEl = target;
|
328
419
|
parentEl = dragEl.parentNode;
|
329
420
|
nextEl = dragEl.nextSibling;
|
421
|
+
lastDownEl = target;
|
330
422
|
activeGroup = options.group;
|
423
|
+
oldIndex = startIndex;
|
424
|
+
|
425
|
+
this._lastX = (touch || evt).clientX;
|
426
|
+
this._lastY = (touch || evt).clientY;
|
427
|
+
|
428
|
+
dragEl.style['will-change'] = 'all';
|
331
429
|
|
332
430
|
dragStartFn = function () {
|
333
431
|
// Delayed drag has been triggered
|
@@ -335,13 +433,16 @@
|
|
335
433
|
_this._disableDelayedDrag();
|
336
434
|
|
337
435
|
// Make the element draggable
|
338
|
-
dragEl.draggable =
|
436
|
+
dragEl.draggable = _this.nativeDraggable;
|
339
437
|
|
340
438
|
// Chosen item
|
341
|
-
_toggleClass(dragEl,
|
439
|
+
_toggleClass(dragEl, options.chosenClass, true);
|
342
440
|
|
343
441
|
// Bind the events: dragstart/dragend
|
344
|
-
_this._triggerDragStart(touch);
|
442
|
+
_this._triggerDragStart(evt, touch);
|
443
|
+
|
444
|
+
// Drag start event
|
445
|
+
_dispatchEvent(_this, rootEl, 'choose', dragEl, rootEl, rootEl, oldIndex);
|
345
446
|
};
|
346
447
|
|
347
448
|
// Disable "draggable"
|
@@ -352,6 +453,8 @@
|
|
352
453
|
_on(ownerDocument, 'mouseup', _this._onDrop);
|
353
454
|
_on(ownerDocument, 'touchend', _this._onDrop);
|
354
455
|
_on(ownerDocument, 'touchcancel', _this._onDrop);
|
456
|
+
_on(ownerDocument, 'selectstart', _this);
|
457
|
+
options.supportPointer && _on(ownerDocument, 'pointercancel', _this._onDrop);
|
355
458
|
|
356
459
|
if (options.delay) {
|
357
460
|
// If the user moves the pointer or let go the click or touch
|
@@ -361,12 +464,21 @@
|
|
361
464
|
_on(ownerDocument, 'touchend', _this._disableDelayedDrag);
|
362
465
|
_on(ownerDocument, 'touchcancel', _this._disableDelayedDrag);
|
363
466
|
_on(ownerDocument, 'mousemove', _this._disableDelayedDrag);
|
364
|
-
_on(ownerDocument, 'touchmove', _this.
|
467
|
+
_on(ownerDocument, 'touchmove', _this._delayedDragTouchMoveHandler);
|
468
|
+
options.supportPointer && _on(ownerDocument, 'pointermove', _this._delayedDragTouchMoveHandler);
|
365
469
|
|
366
470
|
_this._dragStartTimer = setTimeout(dragStartFn, options.delay);
|
367
471
|
} else {
|
368
472
|
dragStartFn();
|
369
473
|
}
|
474
|
+
|
475
|
+
|
476
|
+
}
|
477
|
+
},
|
478
|
+
|
479
|
+
_delayedDragTouchMoveHandler: function (/** TouchEvent|PointerEvent **/e) {
|
480
|
+
if (min(abs(e.clientX - this._lastX), abs(e.clientY - this._lastY)) >= this.options.touchStartThreshold) {
|
481
|
+
this._disableDelayedDrag();
|
370
482
|
}
|
371
483
|
},
|
372
484
|
|
@@ -379,9 +491,12 @@
|
|
379
491
|
_off(ownerDocument, 'touchcancel', this._disableDelayedDrag);
|
380
492
|
_off(ownerDocument, 'mousemove', this._disableDelayedDrag);
|
381
493
|
_off(ownerDocument, 'touchmove', this._disableDelayedDrag);
|
494
|
+
_off(ownerDocument, 'pointermove', this._disableDelayedDrag);
|
382
495
|
},
|
383
496
|
|
384
|
-
_triggerDragStart: function (/** Touch */touch) {
|
497
|
+
_triggerDragStart: function (/** Event */evt, /** Touch */touch) {
|
498
|
+
touch = touch || (evt.pointerType == 'touch' ? evt : null);
|
499
|
+
|
385
500
|
if (touch) {
|
386
501
|
// Touch device support
|
387
502
|
tapEvt = {
|
@@ -402,7 +517,10 @@
|
|
402
517
|
|
403
518
|
try {
|
404
519
|
if (document.selection) {
|
405
|
-
|
520
|
+
// Timeout neccessary for IE9
|
521
|
+
_nextTick(function () {
|
522
|
+
document.selection.empty();
|
523
|
+
});
|
406
524
|
} else {
|
407
525
|
window.getSelection().removeAllRanges();
|
408
526
|
}
|
@@ -412,13 +530,18 @@
|
|
412
530
|
|
413
531
|
_dragStarted: function () {
|
414
532
|
if (rootEl && dragEl) {
|
533
|
+
var options = this.options;
|
534
|
+
|
415
535
|
// Apply effect
|
416
|
-
_toggleClass(dragEl,
|
536
|
+
_toggleClass(dragEl, options.ghostClass, true);
|
537
|
+
_toggleClass(dragEl, options.dragClass, false);
|
417
538
|
|
418
539
|
Sortable.active = this;
|
419
540
|
|
420
541
|
// Drag start event
|
421
|
-
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, oldIndex);
|
542
|
+
_dispatchEvent(this, rootEl, 'start', dragEl, rootEl, rootEl, oldIndex);
|
543
|
+
} else {
|
544
|
+
this._nulling();
|
422
545
|
}
|
423
546
|
},
|
424
547
|
|
@@ -435,14 +558,18 @@
|
|
435
558
|
_css(ghostEl, 'display', 'none');
|
436
559
|
}
|
437
560
|
|
438
|
-
var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY)
|
439
|
-
|
440
|
-
|
441
|
-
|
561
|
+
var target = document.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
|
562
|
+
var parent = target;
|
563
|
+
var i = touchDragOverListeners.length;
|
564
|
+
|
565
|
+
while (target && target.shadowRoot) {
|
566
|
+
target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
|
567
|
+
parent = target;
|
568
|
+
}
|
442
569
|
|
443
570
|
if (parent) {
|
444
571
|
do {
|
445
|
-
if (parent[expando]
|
572
|
+
if (parent[expando]) {
|
446
573
|
while (i--) {
|
447
574
|
touchDragOverListeners[i]({
|
448
575
|
clientX: touchEvt.clientX,
|
@@ -470,19 +597,28 @@
|
|
470
597
|
|
471
598
|
_onTouchMove: function (/**TouchEvent*/evt) {
|
472
599
|
if (tapEvt) {
|
600
|
+
var options = this.options,
|
601
|
+
fallbackTolerance = options.fallbackTolerance,
|
602
|
+
fallbackOffset = options.fallbackOffset,
|
603
|
+
touch = evt.touches ? evt.touches[0] : evt,
|
604
|
+
dx = (touch.clientX - tapEvt.clientX) + fallbackOffset.x,
|
605
|
+
dy = (touch.clientY - tapEvt.clientY) + fallbackOffset.y,
|
606
|
+
translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)';
|
607
|
+
|
473
608
|
// only set the status to dragging, when we are actually dragging
|
474
609
|
if (!Sortable.active) {
|
610
|
+
if (fallbackTolerance &&
|
611
|
+
min(abs(touch.clientX - this._lastX), abs(touch.clientY - this._lastY)) < fallbackTolerance
|
612
|
+
) {
|
613
|
+
return;
|
614
|
+
}
|
615
|
+
|
475
616
|
this._dragStarted();
|
476
617
|
}
|
477
618
|
|
478
619
|
// as well as creating the ghost element on the document body
|
479
620
|
this._appendGhost();
|
480
621
|
|
481
|
-
var touch = evt.touches ? evt.touches[0] : evt,
|
482
|
-
dx = touch.clientX - tapEvt.clientX,
|
483
|
-
dy = touch.clientY - tapEvt.clientY,
|
484
|
-
translate3d = evt.touches ? 'translate3d(' + dx + 'px,' + dy + 'px,0)' : 'translate(' + dx + 'px,' + dy + 'px)';
|
485
|
-
|
486
622
|
moved = true;
|
487
623
|
touchEvt = touch;
|
488
624
|
|
@@ -506,6 +642,7 @@
|
|
506
642
|
|
507
643
|
_toggleClass(ghostEl, options.ghostClass, false);
|
508
644
|
_toggleClass(ghostEl, options.fallbackClass, true);
|
645
|
+
_toggleClass(ghostEl, options.dragClass, true);
|
509
646
|
|
510
647
|
_css(ghostEl, 'top', rect.top - parseInt(css.marginTop, 10));
|
511
648
|
_css(ghostEl, 'left', rect.left - parseInt(css.marginLeft, 10));
|
@@ -526,40 +663,63 @@
|
|
526
663
|
},
|
527
664
|
|
528
665
|
_onDragStart: function (/**Event*/evt, /**boolean*/useFallback) {
|
529
|
-
var
|
530
|
-
|
666
|
+
var _this = this;
|
667
|
+
var dataTransfer = evt.dataTransfer;
|
668
|
+
var options = _this.options;
|
531
669
|
|
532
|
-
|
670
|
+
_this._offUpEvents();
|
671
|
+
|
672
|
+
if (activeGroup.checkPull(_this, _this, dragEl, evt)) {
|
673
|
+
cloneEl = _clone(dragEl);
|
674
|
+
|
675
|
+
cloneEl.draggable = false;
|
676
|
+
cloneEl.style['will-change'] = '';
|
533
677
|
|
534
|
-
if (activeGroup.pull == 'clone') {
|
535
|
-
cloneEl = dragEl.cloneNode(true);
|
536
678
|
_css(cloneEl, 'display', 'none');
|
537
|
-
|
679
|
+
_toggleClass(cloneEl, _this.options.chosenClass, false);
|
680
|
+
|
681
|
+
// #1143: IFrame support workaround
|
682
|
+
_this._cloneId = _nextTick(function () {
|
683
|
+
rootEl.insertBefore(cloneEl, dragEl);
|
684
|
+
_dispatchEvent(_this, rootEl, 'clone', dragEl);
|
685
|
+
});
|
538
686
|
}
|
539
687
|
|
540
|
-
|
688
|
+
_toggleClass(dragEl, options.dragClass, true);
|
541
689
|
|
690
|
+
if (useFallback) {
|
542
691
|
if (useFallback === 'touch') {
|
543
692
|
// Bind touch events
|
544
|
-
_on(document, 'touchmove',
|
545
|
-
_on(document, 'touchend',
|
546
|
-
_on(document, 'touchcancel',
|
693
|
+
_on(document, 'touchmove', _this._onTouchMove);
|
694
|
+
_on(document, 'touchend', _this._onDrop);
|
695
|
+
_on(document, 'touchcancel', _this._onDrop);
|
696
|
+
|
697
|
+
if (options.supportPointer) {
|
698
|
+
_on(document, 'pointermove', _this._onTouchMove);
|
699
|
+
_on(document, 'pointerup', _this._onDrop);
|
700
|
+
}
|
547
701
|
} else {
|
548
702
|
// Old brwoser
|
549
|
-
_on(document, 'mousemove',
|
550
|
-
_on(document, 'mouseup',
|
703
|
+
_on(document, 'mousemove', _this._onTouchMove);
|
704
|
+
_on(document, 'mouseup', _this._onDrop);
|
551
705
|
}
|
552
706
|
|
553
|
-
|
707
|
+
_this._loopId = setInterval(_this._emulateDragOver, 50);
|
554
708
|
}
|
555
709
|
else {
|
556
710
|
if (dataTransfer) {
|
557
711
|
dataTransfer.effectAllowed = 'move';
|
558
|
-
options.setData && options.setData.call(
|
712
|
+
options.setData && options.setData.call(_this, dataTransfer, dragEl);
|
559
713
|
}
|
560
714
|
|
561
|
-
_on(document, 'drop',
|
562
|
-
|
715
|
+
_on(document, 'drop', _this);
|
716
|
+
|
717
|
+
// #1143: Бывает элемент с IFrame внутри блокирует `drop`,
|
718
|
+
// поэтому если вызвался `mouseover`, значит надо отменять весь d'n'd.
|
719
|
+
// Breaking Chrome 62+
|
720
|
+
// _on(document, 'mouseover', _this);
|
721
|
+
|
722
|
+
_this._dragStartId = _nextTick(_this._dragStarted);
|
563
723
|
}
|
564
724
|
},
|
565
725
|
|
@@ -567,11 +727,13 @@
|
|
567
727
|
var el = this.el,
|
568
728
|
target,
|
569
729
|
dragRect,
|
730
|
+
targetRect,
|
570
731
|
revert,
|
571
732
|
options = this.options,
|
572
733
|
group = options.group,
|
573
|
-
|
734
|
+
activeSortable = Sortable.active,
|
574
735
|
isOwner = (activeGroup === group),
|
736
|
+
isMovingBetweenSortable = false,
|
575
737
|
canSort = options.sort;
|
576
738
|
|
577
739
|
if (evt.preventDefault !== void 0) {
|
@@ -579,14 +741,21 @@
|
|
579
741
|
!options.dragoverBubble && evt.stopPropagation();
|
580
742
|
}
|
581
743
|
|
744
|
+
if (dragEl.animated) {
|
745
|
+
return;
|
746
|
+
}
|
747
|
+
|
582
748
|
moved = true;
|
583
749
|
|
584
|
-
if (
|
750
|
+
if (activeSortable && !options.disabled &&
|
585
751
|
(isOwner
|
586
752
|
? canSort || (revert = !rootEl.contains(dragEl)) // Reverting item into the original list
|
587
|
-
:
|
588
|
-
|
589
|
-
(
|
753
|
+
: (
|
754
|
+
putSortable === this ||
|
755
|
+
(
|
756
|
+
(activeSortable.lastPullMode = activeGroup.checkPull(this, activeSortable, dragEl, evt)) &&
|
757
|
+
group.checkPut(this, activeSortable, dragEl, evt)
|
758
|
+
)
|
590
759
|
)
|
591
760
|
) &&
|
592
761
|
(evt.rootEl === void 0 || evt.rootEl === this.el) // touch fallback
|
@@ -601,8 +770,14 @@
|
|
601
770
|
target = _closest(evt.target, options.draggable, el);
|
602
771
|
dragRect = dragEl.getBoundingClientRect();
|
603
772
|
|
773
|
+
if (putSortable !== this) {
|
774
|
+
putSortable = this;
|
775
|
+
isMovingBetweenSortable = true;
|
776
|
+
}
|
777
|
+
|
604
778
|
if (revert) {
|
605
|
-
_cloneHide(true);
|
779
|
+
_cloneHide(activeSortable, true);
|
780
|
+
parentEl = rootEl; // actualization
|
606
781
|
|
607
782
|
if (cloneEl || nextEl) {
|
608
783
|
rootEl.insertBefore(dragEl, cloneEl || nextEl);
|
@@ -616,8 +791,12 @@
|
|
616
791
|
|
617
792
|
|
618
793
|
if ((el.children.length === 0) || (el.children[0] === ghostEl) ||
|
619
|
-
(el === evt.target) && (
|
794
|
+
(el === evt.target) && (_ghostIsLast(el, evt))
|
620
795
|
) {
|
796
|
+
//assign target only if condition is true
|
797
|
+
if (el.children.length !== 0 && el.children[0] !== ghostEl && el === evt.target) {
|
798
|
+
target = el.lastElementChild;
|
799
|
+
}
|
621
800
|
|
622
801
|
if (target) {
|
623
802
|
if (target.animated) {
|
@@ -627,9 +806,9 @@
|
|
627
806
|
targetRect = target.getBoundingClientRect();
|
628
807
|
}
|
629
808
|
|
630
|
-
_cloneHide(isOwner);
|
809
|
+
_cloneHide(activeSortable, isOwner);
|
631
810
|
|
632
|
-
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect) !== false) {
|
811
|
+
if (_onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt) !== false) {
|
633
812
|
if (!dragEl.contains(el)) {
|
634
813
|
el.appendChild(dragEl);
|
635
814
|
parentEl = el; // actualization
|
@@ -646,41 +825,46 @@
|
|
646
825
|
lastParentCSS = _css(target.parentNode);
|
647
826
|
}
|
648
827
|
|
828
|
+
targetRect = target.getBoundingClientRect();
|
649
829
|
|
650
|
-
var
|
651
|
-
width = targetRect.right - targetRect.left,
|
830
|
+
var width = targetRect.right - targetRect.left,
|
652
831
|
height = targetRect.bottom - targetRect.top,
|
653
|
-
floating =
|
832
|
+
floating = R_FLOAT.test(lastCSS.cssFloat + lastCSS.display)
|
654
833
|
|| (lastParentCSS.display == 'flex' && lastParentCSS['flex-direction'].indexOf('row') === 0),
|
655
834
|
isWide = (target.offsetWidth > dragEl.offsetWidth),
|
656
835
|
isLong = (target.offsetHeight > dragEl.offsetHeight),
|
657
836
|
halfway = (floating ? (evt.clientX - targetRect.left) / width : (evt.clientY - targetRect.top) / height) > 0.5,
|
658
837
|
nextSibling = target.nextElementSibling,
|
659
|
-
|
660
|
-
after
|
838
|
+
after = false
|
661
839
|
;
|
662
840
|
|
663
|
-
if (
|
664
|
-
|
665
|
-
|
841
|
+
if (floating) {
|
842
|
+
var elTop = dragEl.offsetTop,
|
843
|
+
tgTop = target.offsetTop;
|
666
844
|
|
667
|
-
|
845
|
+
if (elTop === tgTop) {
|
846
|
+
after = (target.previousElementSibling === dragEl) && !isWide || halfway && isWide;
|
847
|
+
}
|
848
|
+
else if (target.previousElementSibling === dragEl || dragEl.previousElementSibling === target) {
|
849
|
+
after = (evt.clientY - targetRect.top) / height > 0.5;
|
850
|
+
} else {
|
851
|
+
after = tgTop > elTop;
|
852
|
+
}
|
853
|
+
} else if (!isMovingBetweenSortable) {
|
854
|
+
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
|
855
|
+
}
|
668
856
|
|
857
|
+
var moveVector = _onMove(rootEl, el, dragEl, dragRect, target, targetRect, evt, after);
|
858
|
+
|
859
|
+
if (moveVector !== false) {
|
669
860
|
if (moveVector === 1 || moveVector === -1) {
|
670
861
|
after = (moveVector === 1);
|
671
862
|
}
|
672
|
-
else if (floating) {
|
673
|
-
var elTop = dragEl.offsetTop,
|
674
|
-
tgTop = target.offsetTop;
|
675
863
|
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
}
|
681
|
-
} else {
|
682
|
-
after = (nextSibling !== dragEl) && !isLong || halfway && isLong;
|
683
|
-
}
|
864
|
+
_silent = true;
|
865
|
+
setTimeout(_unsilent, 30);
|
866
|
+
|
867
|
+
_cloneHide(activeSortable, isOwner);
|
684
868
|
|
685
869
|
if (!dragEl.contains(el)) {
|
686
870
|
if (after && !nextSibling) {
|
@@ -705,13 +889,17 @@
|
|
705
889
|
if (ms) {
|
706
890
|
var currentRect = target.getBoundingClientRect();
|
707
891
|
|
892
|
+
if (prevRect.nodeType === 1) {
|
893
|
+
prevRect = prevRect.getBoundingClientRect();
|
894
|
+
}
|
895
|
+
|
708
896
|
_css(target, 'transition', 'none');
|
709
897
|
_css(target, 'transform', 'translate3d('
|
710
898
|
+ (prevRect.left - currentRect.left) + 'px,'
|
711
899
|
+ (prevRect.top - currentRect.top) + 'px,0)'
|
712
900
|
);
|
713
901
|
|
714
|
-
target.offsetWidth; // repaint
|
902
|
+
forRepaintDummy = target.offsetWidth; // repaint
|
715
903
|
|
716
904
|
_css(target, 'transition', 'all ' + ms + 'ms');
|
717
905
|
_css(target, 'transform', 'translate3d(0,0,0)');
|
@@ -729,9 +917,13 @@
|
|
729
917
|
var ownerDocument = this.el.ownerDocument;
|
730
918
|
|
731
919
|
_off(document, 'touchmove', this._onTouchMove);
|
920
|
+
_off(document, 'pointermove', this._onTouchMove);
|
732
921
|
_off(ownerDocument, 'mouseup', this._onDrop);
|
733
922
|
_off(ownerDocument, 'touchend', this._onDrop);
|
923
|
+
_off(ownerDocument, 'pointerup', this._onDrop);
|
734
924
|
_off(ownerDocument, 'touchcancel', this._onDrop);
|
925
|
+
_off(ownerDocument, 'pointercancel', this._onDrop);
|
926
|
+
_off(ownerDocument, 'selectstart', this);
|
735
927
|
},
|
736
928
|
|
737
929
|
_onDrop: function (/**Event*/evt) {
|
@@ -742,7 +934,11 @@
|
|
742
934
|
clearInterval(autoScroll.pid);
|
743
935
|
clearTimeout(this._dragStartTimer);
|
744
936
|
|
937
|
+
_cancelNextTick(this._cloneId);
|
938
|
+
_cancelNextTick(this._dragStartId);
|
939
|
+
|
745
940
|
// Unbind events
|
941
|
+
_off(document, 'mouseover', this);
|
746
942
|
_off(document, 'mousemove', this._onTouchMove);
|
747
943
|
|
748
944
|
if (this.nativeDraggable) {
|
@@ -758,7 +954,12 @@
|
|
758
954
|
!options.dropBubble && evt.stopPropagation();
|
759
955
|
}
|
760
956
|
|
761
|
-
ghostEl && ghostEl.parentNode.removeChild(ghostEl);
|
957
|
+
ghostEl && ghostEl.parentNode && ghostEl.parentNode.removeChild(ghostEl);
|
958
|
+
|
959
|
+
if (rootEl === parentEl || Sortable.active.lastPullMode !== 'clone') {
|
960
|
+
// Remove clone
|
961
|
+
cloneEl && cloneEl.parentNode && cloneEl.parentNode.removeChild(cloneEl);
|
962
|
+
}
|
762
963
|
|
763
964
|
if (dragEl) {
|
764
965
|
if (this.nativeDraggable) {
|
@@ -766,48 +967,50 @@
|
|
766
967
|
}
|
767
968
|
|
768
969
|
_disableDraggable(dragEl);
|
970
|
+
dragEl.style['will-change'] = '';
|
769
971
|
|
770
972
|
// Remove class's
|
771
973
|
_toggleClass(dragEl, this.options.ghostClass, false);
|
772
974
|
_toggleClass(dragEl, this.options.chosenClass, false);
|
773
975
|
|
976
|
+
// Drag stop event
|
977
|
+
_dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex, null, evt);
|
978
|
+
|
774
979
|
if (rootEl !== parentEl) {
|
775
980
|
newIndex = _index(dragEl, options.draggable);
|
776
981
|
|
777
982
|
if (newIndex >= 0) {
|
778
|
-
// drag from one list and drop into another
|
779
|
-
_dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
|
780
|
-
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
|
781
|
-
|
782
983
|
// Add event
|
783
|
-
_dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex);
|
984
|
+
_dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
|
784
985
|
|
785
986
|
// Remove event
|
786
|
-
_dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex);
|
987
|
+
_dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
|
988
|
+
|
989
|
+
// drag from one list and drop into another
|
990
|
+
_dispatchEvent(null, parentEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
|
991
|
+
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
|
787
992
|
}
|
788
993
|
}
|
789
994
|
else {
|
790
|
-
// Remove clone
|
791
|
-
cloneEl && cloneEl.parentNode.removeChild(cloneEl);
|
792
|
-
|
793
995
|
if (dragEl.nextSibling !== nextEl) {
|
794
996
|
// Get the index of the dragged element within its parent
|
795
997
|
newIndex = _index(dragEl, options.draggable);
|
796
998
|
|
797
999
|
if (newIndex >= 0) {
|
798
1000
|
// drag & drop within the same list
|
799
|
-
_dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex);
|
800
|
-
_dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex);
|
1001
|
+
_dispatchEvent(this, rootEl, 'update', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
|
1002
|
+
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
|
801
1003
|
}
|
802
1004
|
}
|
803
1005
|
}
|
804
1006
|
|
805
1007
|
if (Sortable.active) {
|
806
|
-
|
1008
|
+
/* jshint eqnull:true */
|
1009
|
+
if (newIndex == null || newIndex === -1) {
|
807
1010
|
newIndex = oldIndex;
|
808
1011
|
}
|
809
1012
|
|
810
|
-
_dispatchEvent(this, rootEl, 'end', dragEl, rootEl, oldIndex, newIndex);
|
1013
|
+
_dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
|
811
1014
|
|
812
1015
|
// Save sorting
|
813
1016
|
this.save();
|
@@ -815,17 +1018,18 @@
|
|
815
1018
|
}
|
816
1019
|
|
817
1020
|
}
|
1021
|
+
|
818
1022
|
this._nulling();
|
819
1023
|
},
|
820
1024
|
|
821
1025
|
_nulling: function() {
|
822
|
-
// Nulling
|
823
1026
|
rootEl =
|
824
1027
|
dragEl =
|
825
1028
|
parentEl =
|
826
1029
|
ghostEl =
|
827
1030
|
nextEl =
|
828
1031
|
cloneEl =
|
1032
|
+
lastDownEl =
|
829
1033
|
|
830
1034
|
scrollEl =
|
831
1035
|
scrollParentEl =
|
@@ -839,21 +1043,38 @@
|
|
839
1043
|
lastEl =
|
840
1044
|
lastCSS =
|
841
1045
|
|
1046
|
+
putSortable =
|
842
1047
|
activeGroup =
|
843
1048
|
Sortable.active = null;
|
1049
|
+
|
1050
|
+
savedInputChecked.forEach(function (el) {
|
1051
|
+
el.checked = true;
|
1052
|
+
});
|
1053
|
+
savedInputChecked.length = 0;
|
844
1054
|
},
|
845
1055
|
|
846
1056
|
handleEvent: function (/**Event*/evt) {
|
847
|
-
|
1057
|
+
switch (evt.type) {
|
1058
|
+
case 'drop':
|
1059
|
+
case 'dragend':
|
1060
|
+
this._onDrop(evt);
|
1061
|
+
break;
|
1062
|
+
|
1063
|
+
case 'dragover':
|
1064
|
+
case 'dragenter':
|
1065
|
+
if (dragEl) {
|
1066
|
+
this._onDragOver(evt);
|
1067
|
+
_globalDragOver(evt);
|
1068
|
+
}
|
1069
|
+
break;
|
848
1070
|
|
849
|
-
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
|
855
|
-
|
856
|
-
this._onDrop(evt);
|
1071
|
+
case 'mouseover':
|
1072
|
+
this._onDrop(evt);
|
1073
|
+
break;
|
1074
|
+
|
1075
|
+
case 'selectstart':
|
1076
|
+
evt.preventDefault();
|
1077
|
+
break;
|
857
1078
|
}
|
858
1079
|
},
|
859
1080
|
|
@@ -956,6 +1177,7 @@
|
|
956
1177
|
|
957
1178
|
_off(el, 'mousedown', this._onTapStart);
|
958
1179
|
_off(el, 'touchstart', this._onTapStart);
|
1180
|
+
_off(el, 'pointerdown', this._onTapStart);
|
959
1181
|
|
960
1182
|
if (this.nativeDraggable) {
|
961
1183
|
_off(el, 'dragover', this);
|
@@ -976,10 +1198,25 @@
|
|
976
1198
|
};
|
977
1199
|
|
978
1200
|
|
979
|
-
function _cloneHide(state) {
|
1201
|
+
function _cloneHide(sortable, state) {
|
1202
|
+
if (sortable.lastPullMode !== 'clone') {
|
1203
|
+
state = true;
|
1204
|
+
}
|
1205
|
+
|
980
1206
|
if (cloneEl && (cloneEl.state !== state)) {
|
981
1207
|
_css(cloneEl, 'display', state ? 'none' : '');
|
982
|
-
|
1208
|
+
|
1209
|
+
if (!state) {
|
1210
|
+
if (cloneEl.state) {
|
1211
|
+
if (sortable.options.group.revertClone) {
|
1212
|
+
rootEl.insertBefore(cloneEl, nextEl);
|
1213
|
+
sortable._animate(dragEl, cloneEl);
|
1214
|
+
} else {
|
1215
|
+
rootEl.insertBefore(cloneEl, dragEl);
|
1216
|
+
}
|
1217
|
+
}
|
1218
|
+
}
|
1219
|
+
|
983
1220
|
cloneEl.state = state;
|
984
1221
|
}
|
985
1222
|
}
|
@@ -990,20 +1227,24 @@
|
|
990
1227
|
ctx = ctx || document;
|
991
1228
|
|
992
1229
|
do {
|
993
|
-
if (
|
994
|
-
(selector === '>*' && el.parentNode === ctx)
|
995
|
-
|| _matches(el, selector)
|
996
|
-
) {
|
1230
|
+
if ((selector === '>*' && el.parentNode === ctx) || _matches(el, selector)) {
|
997
1231
|
return el;
|
998
1232
|
}
|
999
|
-
|
1000
|
-
while (el
|
1233
|
+
/* jshint boss:true */
|
1234
|
+
} while (el = _getParentOrHost(el));
|
1001
1235
|
}
|
1002
1236
|
|
1003
1237
|
return null;
|
1004
1238
|
}
|
1005
1239
|
|
1006
1240
|
|
1241
|
+
function _getParentOrHost(el) {
|
1242
|
+
var parent = el.host;
|
1243
|
+
|
1244
|
+
return (parent && parent.nodeType) ? parent : el.parentNode;
|
1245
|
+
}
|
1246
|
+
|
1247
|
+
|
1007
1248
|
function _globalDragOver(/**Event*/evt) {
|
1008
1249
|
if (evt.dataTransfer) {
|
1009
1250
|
evt.dataTransfer.dropEffect = 'move';
|
@@ -1013,12 +1254,12 @@
|
|
1013
1254
|
|
1014
1255
|
|
1015
1256
|
function _on(el, event, fn) {
|
1016
|
-
el.addEventListener(event, fn,
|
1257
|
+
el.addEventListener(event, fn, captureMode);
|
1017
1258
|
}
|
1018
1259
|
|
1019
1260
|
|
1020
1261
|
function _off(el, event, fn) {
|
1021
|
-
el.removeEventListener(event, fn,
|
1262
|
+
el.removeEventListener(event, fn, captureMode);
|
1022
1263
|
}
|
1023
1264
|
|
1024
1265
|
|
@@ -1028,8 +1269,8 @@
|
|
1028
1269
|
el.classList[state ? 'add' : 'remove'](name);
|
1029
1270
|
}
|
1030
1271
|
else {
|
1031
|
-
var className = (' ' + el.className + ' ').replace(
|
1032
|
-
el.className = (className + (state ? ' ' + name : '')).replace(
|
1272
|
+
var className = (' ' + el.className + ' ').replace(R_SPACE, ' ').replace(' ' + name + ' ', ' ');
|
1273
|
+
el.className = (className + (state ? ' ' + name : '')).replace(R_SPACE, ' ');
|
1033
1274
|
}
|
1034
1275
|
}
|
1035
1276
|
}
|
@@ -1078,14 +1319,16 @@
|
|
1078
1319
|
|
1079
1320
|
|
1080
1321
|
|
1081
|
-
function _dispatchEvent(sortable, rootEl, name, targetEl, fromEl, startIndex, newIndex) {
|
1322
|
+
function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex, originalEvt) {
|
1323
|
+
sortable = (sortable || rootEl[expando]);
|
1324
|
+
|
1082
1325
|
var evt = document.createEvent('Event'),
|
1083
|
-
options =
|
1326
|
+
options = sortable.options,
|
1084
1327
|
onName = 'on' + name.charAt(0).toUpperCase() + name.substr(1);
|
1085
1328
|
|
1086
1329
|
evt.initEvent(name, true, true);
|
1087
1330
|
|
1088
|
-
evt.to = rootEl;
|
1331
|
+
evt.to = toEl || rootEl;
|
1089
1332
|
evt.from = fromEl || rootEl;
|
1090
1333
|
evt.item = targetEl || rootEl;
|
1091
1334
|
evt.clone = cloneEl;
|
@@ -1093,6 +1336,8 @@
|
|
1093
1336
|
evt.oldIndex = startIndex;
|
1094
1337
|
evt.newIndex = newIndex;
|
1095
1338
|
|
1339
|
+
evt.originalEvent = originalEvt;
|
1340
|
+
|
1096
1341
|
rootEl.dispatchEvent(evt);
|
1097
1342
|
|
1098
1343
|
if (options[onName]) {
|
@@ -1101,7 +1346,7 @@
|
|
1101
1346
|
}
|
1102
1347
|
|
1103
1348
|
|
1104
|
-
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect) {
|
1349
|
+
function _onMove(fromEl, toEl, dragEl, dragRect, targetEl, targetRect, originalEvt, willInsertAfter) {
|
1105
1350
|
var evt,
|
1106
1351
|
sortable = fromEl[expando],
|
1107
1352
|
onMoveFn = sortable.options.onMove,
|
@@ -1116,11 +1361,14 @@
|
|
1116
1361
|
evt.draggedRect = dragRect;
|
1117
1362
|
evt.related = targetEl || toEl;
|
1118
1363
|
evt.relatedRect = targetRect || toEl.getBoundingClientRect();
|
1364
|
+
evt.willInsertAfter = willInsertAfter;
|
1365
|
+
|
1366
|
+
evt.originalEvent = originalEvt;
|
1119
1367
|
|
1120
1368
|
fromEl.dispatchEvent(evt);
|
1121
1369
|
|
1122
1370
|
if (onMoveFn) {
|
1123
|
-
retVal = onMoveFn.call(sortable, evt);
|
1371
|
+
retVal = onMoveFn.call(sortable, evt, originalEvt);
|
1124
1372
|
}
|
1125
1373
|
|
1126
1374
|
return retVal;
|
@@ -1140,9 +1388,12 @@
|
|
1140
1388
|
/** @returns {HTMLElement|false} */
|
1141
1389
|
function _ghostIsLast(el, evt) {
|
1142
1390
|
var lastEl = el.lastElementChild,
|
1143
|
-
|
1391
|
+
rect = lastEl.getBoundingClientRect();
|
1144
1392
|
|
1145
|
-
|
1393
|
+
// 5 — min delta
|
1394
|
+
// abs — нельзя добавлять, а то глюки при наведении сверху
|
1395
|
+
return (evt.clientY - (rect.top + rect.height) > 5) ||
|
1396
|
+
(evt.clientX - (rect.left + rect.width) > 5);
|
1146
1397
|
}
|
1147
1398
|
|
1148
1399
|
|
@@ -1179,8 +1430,7 @@
|
|
1179
1430
|
}
|
1180
1431
|
|
1181
1432
|
while (el && (el = el.previousElementSibling)) {
|
1182
|
-
if (el.nodeName.toUpperCase() !== 'TEMPLATE'
|
1183
|
-
&& _matches(el, selector)) {
|
1433
|
+
if ((el.nodeName.toUpperCase() !== 'TEMPLATE') && (selector === '>*' || _matches(el, selector))) {
|
1184
1434
|
index++;
|
1185
1435
|
}
|
1186
1436
|
}
|
@@ -1190,15 +1440,15 @@
|
|
1190
1440
|
|
1191
1441
|
function _matches(/**HTMLElement*/el, /**String*/selector) {
|
1192
1442
|
if (el) {
|
1193
|
-
|
1194
|
-
|
1195
|
-
|
1196
|
-
|
1197
|
-
|
1198
|
-
|
1199
|
-
|
1200
|
-
|
1201
|
-
|
1443
|
+
try {
|
1444
|
+
if (el.matches) {
|
1445
|
+
return el.matches(selector);
|
1446
|
+
} else if (el.msMatchesSelector) {
|
1447
|
+
return el.msMatchesSelector(selector);
|
1448
|
+
}
|
1449
|
+
} catch(_) {
|
1450
|
+
return false;
|
1451
|
+
}
|
1202
1452
|
}
|
1203
1453
|
|
1204
1454
|
return false;
|
@@ -1237,6 +1487,44 @@
|
|
1237
1487
|
return dst;
|
1238
1488
|
}
|
1239
1489
|
|
1490
|
+
function _clone(el) {
|
1491
|
+
if (Polymer && Polymer.dom) {
|
1492
|
+
return Polymer.dom(el).cloneNode(true);
|
1493
|
+
}
|
1494
|
+
else if ($) {
|
1495
|
+
return $(el).clone(true)[0];
|
1496
|
+
}
|
1497
|
+
else {
|
1498
|
+
return el.cloneNode(true);
|
1499
|
+
}
|
1500
|
+
}
|
1501
|
+
|
1502
|
+
function _saveInputCheckedState(root) {
|
1503
|
+
savedInputChecked.length = 0;
|
1504
|
+
|
1505
|
+
var inputs = root.getElementsByTagName('input');
|
1506
|
+
var idx = inputs.length;
|
1507
|
+
|
1508
|
+
while (idx--) {
|
1509
|
+
var el = inputs[idx];
|
1510
|
+
el.checked && savedInputChecked.push(el);
|
1511
|
+
}
|
1512
|
+
}
|
1513
|
+
|
1514
|
+
function _nextTick(fn) {
|
1515
|
+
return setTimeout(fn, 0);
|
1516
|
+
}
|
1517
|
+
|
1518
|
+
function _cancelNextTick(id) {
|
1519
|
+
return clearTimeout(id);
|
1520
|
+
}
|
1521
|
+
|
1522
|
+
// Fixed #973:
|
1523
|
+
_on(document, 'touchmove', function (evt) {
|
1524
|
+
if (Sortable.active) {
|
1525
|
+
evt.preventDefault();
|
1526
|
+
}
|
1527
|
+
});
|
1240
1528
|
|
1241
1529
|
// Export utils
|
1242
1530
|
Sortable.utils = {
|
@@ -1251,7 +1539,10 @@
|
|
1251
1539
|
throttle: _throttle,
|
1252
1540
|
closest: _closest,
|
1253
1541
|
toggleClass: _toggleClass,
|
1254
|
-
|
1542
|
+
clone: _clone,
|
1543
|
+
index: _index,
|
1544
|
+
nextTick: _nextTick,
|
1545
|
+
cancelNextTick: _cancelNextTick
|
1255
1546
|
};
|
1256
1547
|
|
1257
1548
|
|
@@ -1266,6 +1557,6 @@
|
|
1266
1557
|
|
1267
1558
|
|
1268
1559
|
// Export
|
1269
|
-
Sortable.version = '1.
|
1560
|
+
Sortable.version = '1.7.0';
|
1270
1561
|
return Sortable;
|
1271
1562
|
});
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sortable-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daryl Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -78,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
80
|
rubyforge_project:
|
81
|
-
rubygems_version: 2.
|
81
|
+
rubygems_version: 2.7.6
|
82
82
|
signing_key:
|
83
83
|
specification_version: 4
|
84
84
|
summary: Gemify Rubaxa's Sortable for Ruby on Rails
|