|
23 | 23 | } |
24 | 24 | })(function () { |
25 | 25 | "use strict"; |
| 26 | + |
| 27 | + if (typeof window == "undefined" || typeof window.document == "undefined") { |
| 28 | + return function() { |
| 29 | + throw new Error( "Sortable.js requires a window with a document" ); |
| 30 | + } |
| 31 | + } |
26 | 32 |
|
27 | 33 | var dragEl, |
28 | 34 | parentEl, |
|
273 | 279 | } |
274 | 280 |
|
275 | 281 | // get the index of the dragged element within its parent |
276 | | - oldIndex = _index(target); |
| 282 | + oldIndex = _index(target, options.draggable); |
277 | 283 |
|
278 | 284 | // Check filter |
279 | 285 | if (typeof filter === 'function') { |
|
769 | 775 | _toggleClass(dragEl, this.options.chosenClass, false); |
770 | 776 |
|
771 | 777 | if (rootEl !== parentEl) { |
772 | | - newIndex = _index(dragEl); |
| 778 | + newIndex = _index(dragEl, options.draggable); |
773 | 779 |
|
774 | 780 | if (newIndex >= 0) { |
775 | 781 | // drag from one list and drop into another |
|
789 | 795 |
|
790 | 796 | if (dragEl.nextSibling !== nextEl) { |
791 | 797 | // Get the index of the dragged element within its parent |
792 | | - newIndex = _index(dragEl); |
| 798 | + newIndex = _index(dragEl, options.draggable); |
793 | 799 |
|
794 | 800 | if (newIndex >= 0) { |
795 | 801 | // drag & drop within the same list |
|
811 | 817 | } |
812 | 818 | } |
813 | 819 |
|
814 | | - // Nulling |
815 | | - rootEl = |
816 | | - dragEl = |
817 | | - parentEl = |
818 | | - ghostEl = |
819 | | - nextEl = |
820 | | - cloneEl = |
| 820 | + } |
| 821 | + this._nulling(); |
| 822 | + }, |
821 | 823 |
|
822 | | - scrollEl = |
823 | | - scrollParentEl = |
| 824 | + _nulling: function() { |
| 825 | + // Nulling |
| 826 | + rootEl = |
| 827 | + dragEl = |
| 828 | + parentEl = |
| 829 | + ghostEl = |
| 830 | + nextEl = |
| 831 | + cloneEl = |
824 | 832 |
|
825 | | - tapEvt = |
826 | | - touchEvt = |
| 833 | + scrollEl = |
| 834 | + scrollParentEl = |
827 | 835 |
|
828 | | - moved = |
829 | | - newIndex = |
| 836 | + tapEvt = |
| 837 | + touchEvt = |
830 | 838 |
|
831 | | - lastEl = |
832 | | - lastCSS = |
| 839 | + moved = |
| 840 | + newIndex = |
833 | 841 |
|
834 | | - activeGroup = |
835 | | - Sortable.active = null; |
836 | | - } |
837 | | - }, |
| 842 | + lastEl = |
| 843 | + lastCSS = |
838 | 844 |
|
| 845 | + activeGroup = |
| 846 | + Sortable.active = null; |
| 847 | + }, |
839 | 848 |
|
840 | 849 | handleEvent: function (/**Event*/evt) { |
841 | 850 | var type = evt.type; |
|
982 | 991 | function _closest(/**HTMLElement*/el, /**String*/selector, /**HTMLElement*/ctx) { |
983 | 992 | if (el) { |
984 | 993 | ctx = ctx || document; |
985 | | - selector = selector.split('.'); |
986 | | - |
987 | | - var tag = selector.shift().toUpperCase(), |
988 | | - re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g'); |
989 | 994 |
|
990 | 995 | do { |
991 | 996 | if ( |
992 | | - (tag === '>*' && el.parentNode === ctx) || ( |
993 | | - (tag === '' || el.nodeName.toUpperCase() == tag) && |
994 | | - (!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length) |
995 | | - ) |
| 997 | + (selector === '>*' && el.parentNode === ctx) |
| 998 | + || _matches(el, selector) |
996 | 999 | ) { |
997 | 1000 | return el; |
998 | 1001 | } |
|
1165 | 1168 | } |
1166 | 1169 |
|
1167 | 1170 | /** |
1168 | | - * Returns the index of an element within its parent |
| 1171 | + * Returns the index of an element within its parent for a selected set of |
| 1172 | + * elements |
1169 | 1173 | * @param {HTMLElement} el |
| 1174 | + * @param {selector} selector |
1170 | 1175 | * @return {number} |
1171 | 1176 | */ |
1172 | | - function _index(el) { |
| 1177 | + function _index(el, selector) { |
1173 | 1178 | var index = 0; |
1174 | 1179 |
|
1175 | 1180 | if (!el || !el.parentNode) { |
1176 | 1181 | return -1; |
1177 | 1182 | } |
1178 | 1183 |
|
1179 | 1184 | while (el && (el = el.previousElementSibling)) { |
1180 | | - if (el.nodeName.toUpperCase() !== 'TEMPLATE') { |
| 1185 | + if (el.nodeName.toUpperCase() !== 'TEMPLATE' |
| 1186 | + && _matches(el, selector)) { |
1181 | 1187 | index++; |
1182 | 1188 | } |
1183 | 1189 | } |
1184 | 1190 |
|
1185 | 1191 | return index; |
1186 | 1192 | } |
1187 | 1193 |
|
| 1194 | + function _matches(/**HTMLElement*/el, /**String*/selector) { |
| 1195 | + if (el) { |
| 1196 | + selector = selector.split('.'); |
| 1197 | + |
| 1198 | + var tag = selector.shift().toUpperCase(), |
| 1199 | + re = new RegExp('\\s(' + selector.join('|') + ')(?=\\s)', 'g'); |
| 1200 | + |
| 1201 | + return ( |
| 1202 | + (tag === '' || el.nodeName.toUpperCase() == tag) && |
| 1203 | + (!selector.length || ((' ' + el.className + ' ').match(re) || []).length == selector.length) |
| 1204 | + ); |
| 1205 | + } |
| 1206 | + |
| 1207 | + return false; |
| 1208 | + } |
| 1209 | + |
1188 | 1210 | function _throttle(callback, ms) { |
1189 | 1211 | var args, _this; |
1190 | 1212 |
|
|
0 commit comments