|
55 | 55 |
|
56 | 56 | moved, |
57 | 57 |
|
| 58 | + forRepaintDummy, |
| 59 | + |
58 | 60 | /** @const */ |
59 | 61 | R_SPACE = /\s+/g, |
60 | 62 | R_FLOAT = /left|right|inline/, |
|
91 | 93 | savedInputChecked = [], |
92 | 94 | touchDragOverListeners = [], |
93 | 95 |
|
| 96 | + alwaysFalse = function () { return false; }, |
| 97 | + |
94 | 98 | _autoScroll = _throttle(function (/**Event*/evt, /**Object*/options, /**HTMLElement*/rootEl) { |
95 | 99 | // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521 |
96 | 100 | if (rootEl && options.scroll) { |
|
163 | 167 | scrollOffsetX = vx ? vx * speed : 0; |
164 | 168 |
|
165 | 169 | 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 | + } |
167 | 173 | } |
168 | 174 |
|
169 | 175 | if (el === win) { |
|
180 | 186 |
|
181 | 187 | _prepareGroup = function (options) { |
182 | 188 | function toFn(value, pull) { |
183 | | - if (value === void 0 || value === true) { |
| 189 | + if (value == null || value === true) { |
184 | 190 | value = group.name; |
| 191 | + if (value == null) { |
| 192 | + return alwaysFalse; |
| 193 | + } |
185 | 194 | } |
186 | 195 |
|
187 | 196 | if (typeof value === 'function') { |
|
220 | 229 | try { |
221 | 230 | window.addEventListener('test', null, Object.defineProperty({}, 'passive', { |
222 | 231 | 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; |
224 | 235 | captureMode = { |
225 | 236 | capture: false, |
226 | 237 | passive: passiveMode |
|
248 | 259 |
|
249 | 260 | // Default options |
250 | 261 | var defaults = { |
251 | | - group: Math.random(), |
| 262 | + group: null, |
252 | 263 | sort: true, |
253 | 264 | disabled: false, |
254 | 265 | store: null, |
255 | 266 | handle: null, |
256 | | - scroll: true, |
| 267 | + scroll: true, |
257 | 268 | scrollSensitivity: 30, |
258 | 269 | scrollSpeed: 10, |
259 | 270 | draggable: /[uo]l/i.test(el.nodeName) ? 'li' : '>*', |
|
277 | 288 | fallbackOnBody: false, |
278 | 289 | fallbackTolerance: 0, |
279 | 290 | fallbackOffset: {x: 0, y: 0}, |
280 | | - supportPointer: Sortable.supportPointer !== false, |
| 291 | + supportPointer: Sortable.supportPointer !== false |
281 | 292 | }; |
282 | 293 |
|
283 | 294 |
|
|
551 | 562 | var parent = target; |
552 | 563 | var i = touchDragOverListeners.length; |
553 | 564 |
|
554 | | - if (target && target.shadowRoot) { |
| 565 | + while (target && target.shadowRoot) { |
555 | 566 | target = target.shadowRoot.elementFromPoint(touchEvt.clientX, touchEvt.clientY); |
556 | 567 | parent = target; |
557 | 568 | } |
|
726 | 737 | canSort = options.sort; |
727 | 738 |
|
728 | 739 | if (evt.preventDefault !== void 0) { |
729 | | - !passiveMode && evt.preventDefault(); |
| 740 | + evt.preventDefault(); |
730 | 741 | !options.dragoverBubble && evt.stopPropagation(); |
731 | 742 | } |
732 | 743 |
|
|
888 | 899 | + (prevRect.top - currentRect.top) + 'px,0)' |
889 | 900 | ); |
890 | 901 |
|
891 | | - target.offsetWidth; // repaint |
| 902 | + forRepaintDummy = target.offsetWidth; // repaint |
892 | 903 |
|
893 | 904 | _css(target, 'transition', 'all ' + ms + 'ms'); |
894 | 905 | _css(target, 'transform', 'translate3d(0,0,0)'); |
|
939 | 950 |
|
940 | 951 | if (evt) { |
941 | 952 | if (moved) { |
942 | | - !passiveMode && evt.preventDefault(); |
| 953 | + evt.preventDefault(); |
943 | 954 | !options.dropBubble && evt.stopPropagation(); |
944 | 955 | } |
945 | 956 |
|
|
963 | 974 | _toggleClass(dragEl, this.options.chosenClass, false); |
964 | 975 |
|
965 | 976 | // Drag stop event |
966 | | - _dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex); |
| 977 | + _dispatchEvent(this, rootEl, 'unchoose', dragEl, parentEl, rootEl, oldIndex, null, evt); |
967 | 978 |
|
968 | 979 | if (rootEl !== parentEl) { |
969 | 980 | newIndex = _index(dragEl, options.draggable); |
970 | 981 |
|
971 | 982 | if (newIndex >= 0) { |
972 | 983 | // Add event |
973 | | - _dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex); |
| 984 | + _dispatchEvent(null, parentEl, 'add', dragEl, parentEl, rootEl, oldIndex, newIndex, evt); |
974 | 985 |
|
975 | 986 | // Remove event |
976 | | - _dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex); |
| 987 | + _dispatchEvent(this, rootEl, 'remove', dragEl, parentEl, rootEl, oldIndex, newIndex, evt); |
977 | 988 |
|
978 | 989 | // 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); |
981 | 992 | } |
982 | 993 | } |
983 | 994 | else { |
|
987 | 998 |
|
988 | 999 | if (newIndex >= 0) { |
989 | 1000 | // 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); |
992 | 1003 | } |
993 | 1004 | } |
994 | 1005 | } |
|
999 | 1010 | newIndex = oldIndex; |
1000 | 1011 | } |
1001 | 1012 |
|
1002 | | - _dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex); |
| 1013 | + _dispatchEvent(this, rootEl, 'end', dragEl, parentEl, rootEl, oldIndex, newIndex, evt); |
1003 | 1014 |
|
1004 | 1015 | // Save sorting |
1005 | 1016 | this.save(); |
|
1238 | 1249 | if (evt.dataTransfer) { |
1239 | 1250 | evt.dataTransfer.dropEffect = 'move'; |
1240 | 1251 | } |
1241 | | - !passiveMode && evt.preventDefault(); |
| 1252 | + evt.preventDefault(); |
1242 | 1253 | } |
1243 | 1254 |
|
1244 | 1255 |
|
|
1308 | 1319 |
|
1309 | 1320 |
|
1310 | 1321 |
|
1311 | | - function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex) { |
| 1322 | + function _dispatchEvent(sortable, rootEl, name, targetEl, toEl, fromEl, startIndex, newIndex, originalEvt) { |
1312 | 1323 | sortable = (sortable || rootEl[expando]); |
1313 | 1324 |
|
1314 | 1325 | var evt = document.createEvent('Event'), |
|
1325 | 1336 | evt.oldIndex = startIndex; |
1326 | 1337 | evt.newIndex = newIndex; |
1327 | 1338 |
|
| 1339 | + evt.originalEvent = originalEvt; |
| 1340 | + |
1328 | 1341 | rootEl.dispatchEvent(evt); |
1329 | 1342 |
|
1330 | 1343 | if (options[onName]) { |
|
1350 | 1363 | evt.relatedRect = targetRect || toEl.getBoundingClientRect(); |
1351 | 1364 | evt.willInsertAfter = willInsertAfter; |
1352 | 1365 |
|
| 1366 | + evt.originalEvent = originalEvt; |
| 1367 | + |
1353 | 1368 | fromEl.dispatchEvent(evt); |
1354 | 1369 |
|
1355 | 1370 | if (onMoveFn) { |
|
1425 | 1440 |
|
1426 | 1441 | function _matches(/**HTMLElement*/el, /**String*/selector) { |
1427 | 1442 | 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 | + } |
1437 | 1452 | } |
1438 | 1453 |
|
1439 | 1454 | return false; |
|
1485 | 1500 | } |
1486 | 1501 |
|
1487 | 1502 | function _saveInputCheckedState(root) { |
| 1503 | + savedInputChecked.length = 0; |
| 1504 | + |
1488 | 1505 | var inputs = root.getElementsByTagName('input'); |
1489 | 1506 | var idx = inputs.length; |
1490 | 1507 |
|
|
1540 | 1557 |
|
1541 | 1558 |
|
1542 | 1559 | // Export |
1543 | | - Sortable.version = '1.6.1'; |
| 1560 | + Sortable.version = '1.7.0'; |
1544 | 1561 | return Sortable; |
1545 | 1562 | }); |
0 commit comments