Skip to content

Commit 0620466

Browse files
authored
Merge branch 'master' into master
2 parents 3e2e94b + 847cc6b commit 0620466

File tree

5 files changed

+60
-43
lines changed

5 files changed

+60
-43
lines changed

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ var sortable = new Sortable(el, {
9999

100100
fallbackClass: "sortable-fallback", // Class name for the cloned DOM Element when using forceFallback
101101
fallbackOnBody: false, // Appends the cloned DOM Element into the Document's Body
102-
fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.
103-
102+
fallbackTolerance: 0, // Specify in pixels how far the mouse should move before it's considered as a drag.
103+
104104
scroll: true, // or HTMLElement
105-
scrollFn: function(offsetX, offsetY, originalEvent) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling
105+
scrollFn: function(offsetX, offsetY, originalEvent, touchEvt, hoverTargetEl) { ... }, // if you have custom scrollbar scrollFn may be used for autoscrolling
106106
scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling.
107107
scrollSpeed: 10, // px
108108

@@ -164,7 +164,7 @@ var sortable = new Sortable(el, {
164164
originalEvent.clientY; // mouse position
165165
// return false; — for cancel
166166
},
167-
167+
168168
// Called when creating a clone of element
169169
onClone: function (/**Event*/evt) {
170170
var origEl = evt.item;
@@ -362,7 +362,7 @@ Demo: http://jsbin.com/yacuqib/edit?html,css,js,output
362362
Emulates the native drag threshold. Specify in pixels how far the mouse should move before it's considered as a drag.
363363
Useful if the items are also clickable like in a list of links.
364364

365-
When the user clicks inside a sortable element, it's not uncommon for your hand to move a little between the time you press and the time you release.
365+
When the user clicks inside a sortable element, it's not uncommon for your hand to move a little between the time you press and the time you release.
366366
Dragging only starts if you move the pointer past a certain tolerance, so that you don't accidentally start dragging every time you click.
367367

368368
3 to 5 are probably good values.
@@ -576,12 +576,12 @@ Link to the active instance.
576576
### CDN
577577

578578
```html
579-
<!-- jsDelivr :: Sortable (http://www.jsdelivr.com/package/npm/sortablejs) -->
580-
<script src="//cdn.jsdelivr.net/npm/sortablejs@1.6.1/Sortable.min.js"></script>
579+
<!-- jsDelivr :: Sortable (https://www.jsdelivr.com/package/npm/sortablejs) -->
580+
<script src="https://cdn.jsdelivr.net/npm/sortablejs@1.6.1/Sortable.min.js"></script>
581581

582582

583-
<!-- jsDelivr :: Sortable :: Latest (http://www.jsdelivr.com/package/npm/sortablejs) -->
584-
<script src="//cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
583+
<!-- jsDelivr :: Sortable :: Latest (https://www.jsdelivr.com/package/npm/sortablejs) -->
584+
<script src="https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js"></script>
585585
```
586586

587587

Sortable.js

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

5656
moved,
5757

58+
forRepaintDummy,
59+
5860
/** @const */
5961
R_SPACE = /\s+/g,
6062
R_FLOAT = /left|right|inline/,
@@ -91,6 +93,8 @@
9193
savedInputChecked = [],
9294
touchDragOverListeners = [],
9395

96+
alwaysFalse = function () { return false; },
97+
9498
_autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) {
9599
// Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521
96100
if (rootEl && options.scroll) {
@@ -163,7 +167,9 @@
163167
scrollOffsetX = vx ? vx * speed : 0;
164168

165169
if ('function' === typeof(scrollCustomFn)) {
166-
return scrollCustomFn.call(_this, scrollOffsetX, scrollOffsetY, evt);
170+
if (scrollCustomFn.call(_this, scrollOffsetX, scrollOffsetY, evt, touchEvt, el) !== 'continue') {
171+
return;
172+
}
167173
}
168174

169175
if (el === win) {
@@ -180,8 +186,11 @@
180186

181187
_prepareGroup = function (options) {
182188
function toFn(value, pull) {
183-
if (value === void 0 || value === true) {
189+
if (value == null || value === true) {
184190
value = group.name;
191+
if (value == null) {
192+
return alwaysFalse;
193+
}
185194
}
186195

187196
if (typeof value === 'function') {
@@ -220,7 +229,9 @@
220229
try {
221230
window.addEventListener('test', null, Object.defineProperty({}, 'passive', {
222231
get: function () {
223-
passiveMode = true;
232+
// `false`, because everything starts to work incorrectly and instead of d'n'd,
233+
// begins the page has scrolled.
234+
passiveMode = false;
224235
captureMode = {
225236
capture: false,
226237
passive: passiveMode
@@ -248,12 +259,12 @@
248259

249260
// Default options
250261
var defaults = {
251-
group: Math.random(),
262+
group: null,
252263
sort: true,
253264
disabled: false,
254265
store: null,
255266
handle: null,
256-
scroll: true,
267+
scroll: true,
257268
scrollSensitivity: 30,
258269
scrollSpeed: 10,
259270
draggable: /[uo]l/i.test(el.nodeName) ? 'li' : '>*',
@@ -277,7 +288,7 @@
277288
fallbackOnBody: false,
278289
fallbackTolerance: 0,
279290
fallbackOffset: {x: 0, y: 0},
280-
supportPointer: Sortable.supportPointer !== false,
291+
supportPointer: Sortable.supportPointer !== false
281292
};
282293

283294

@@ -551,7 +562,7 @@
551562
var parent = target;
552563
var i = touchDragOverListeners.length;
553564

554-
if (target && target.shadowRoot) {
565+
while (target && target.shadowRoot) {
555566
target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY);
556567
parent = target;
557568
}
@@ -726,7 +737,7 @@
726737
canSort = options.sort;
727738

728739
if (evt.preventDefault !== void 0) {
729-
!passiveMode && evt.preventDefault();
740+
evt.preventDefault();
730741
!options.dragoverBubble && evt.stopPropagation();
731742
}
732743

@@ -888,7 +899,7 @@
888899
+ (prevRect.top - currentRect.top) + 'px,0)'
889900
);
890901

891-
target.offsetWidth; // repaint
902+
forRepaintDummy = target.offsetWidth; // repaint
892903

893904
_css(target, 'transition', 'all ' + ms + 'ms');
894905
_css(target, 'transform', 'translate3d(0,0,0)');
@@ -939,7 +950,7 @@
939950

940951
if (evt) {
941952
if (moved) {
942-
!passiveMode && evt.preventDefault();
953+
evt.preventDefault();
943954
!options.dropBubble && evt.stopPropagation();
944955
}
945956

@@ -963,21 +974,21 @@
963974
_toggleClass(dragEl, this.options.chosenClass, false);
964975

965976
// Drag stop event
966-
_dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex);
977+
_dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex, null, evt);
967978

968979
if (rootEl !== parentEl) {
969980
newIndex = _index(dragEl, options.draggable);
970981

971982
if (newIndex >= 0) {
972983
// Add event
973-
_dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex);
984+
_dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
974985

975986
// Remove event
976-
_dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex);
987+
_dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
977988

978989
// drag from one list and drop into another
979-
_dispatchEvent(null, parentEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
980-
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex);
990+
_dispatchEvent(null, parentEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
991+
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
981992
}
982993
}
983994
else {
@@ -987,8 +998,8 @@
987998

988999
if (newIndex >= 0) {
9891000
// drag & drop within the same list
990-
_dispatchEvent(this, rootEl, 'update', dragEl, parentEl, rootEl, oldIndex, newIndex);
991-
_dispatchEvent(this, rootEl, 'sort', dragEl, parentEl, 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);
9921003
}
9931004
}
9941005
}
@@ -999,7 +1010,7 @@
9991010
newIndex = oldIndex;
10001011
}
10011012

1002-
_dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex);
1013+
_dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex, evt);
10031014

10041015
// Save sorting
10051016
this.save();
@@ -1238,7 +1249,7 @@
12381249
if (evt.dataTransfer) {
12391250
evt.dataTransfer.dropEffect = 'move';
12401251
}
1241-
!passiveMode && evt.preventDefault();
1252+
evt.preventDefault();
12421253
}
12431254

12441255

@@ -1308,7 +1319,7 @@
13081319

13091320

13101321

1311-
function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex) {
1322+
function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex, originalEvt) {
13121323
sortable = (sortable || rootEl[expando]);
13131324

13141325
var evt = document.createEvent('Event'),
@@ -1325,6 +1336,8 @@
13251336
evt.oldIndex = startIndex;
13261337
evt.newIndex = newIndex;
13271338

1339+
evt.originalEvent = originalEvt;
1340+
13281341
rootEl.dispatchEvent(evt);
13291342

13301343
if (options[onName]) {
@@ -1350,6 +1363,8 @@
13501363
evt.relatedRect = targetRect || toEl.getBoundingClientRect();
13511364
evt.willInsertAfter = willInsertAfter;
13521365

1366+
evt.originalEvent = originalEvt;
1367+
13531368
fromEl.dispatchEvent(evt);
13541369

13551370
if (onMoveFn) {
@@ -1425,15 +1440,15 @@
14251440

14261441
function _matches(/**HTMLElement*/el, /**String*/selector) {
14271442
if (el) {
1428-
selector = selector.split('.');
1429-
1430-
var tag = selector.shift().toUpperCase(),
1431-
re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g');
1432-
1433-
return (
1434-
(tag === '' || el.nodeName.toUpperCase() == tag) &&
1435-
(!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length)
1436-
);
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+
}
14371452
}
14381453

14391454
return false;
@@ -1485,6 +1500,8 @@
14851500
}
14861501

14871502
function _saveInputCheckedState(root) {
1503+
savedInputChecked.length = 0;
1504+
14881505
var inputs = root.getElementsByTagName('input');
14891506
var idx = inputs.length;
14901507

@@ -1540,6 +1557,6 @@
15401557

15411558

15421559
// Export
1543-
Sortable.version = '1.6.1';
1560+
Sortable.version = '1.7.0';
15441561
return Sortable;
15451562
});

0 commit comments

Comments
 (0)