diff --git a/Sortable.js b/Sortable.js index 8dad392..6f24472 100644 --- a/Sortable.js +++ b/Sortable.js @@ -25,6 +25,7 @@ "use strict"; var dragEl, + parentEl, ghostEl, cloneEl, rootEl, @@ -303,6 +304,7 @@ rootEl = el; dragEl = target; + parentEl = target.parentNode; nextEl = dragEl.nextSibling; activeGroup = options.group; @@ -706,18 +708,19 @@ _disableDraggable(dragEl); _toggleClass(dragEl, this.options.ghostClass, false); - if (rootEl !== dragEl.parentNode) { + if (rootEl !== parentEl) { newIndex = _index(dragEl); + if (newIndex != -1) { + // drag from one list and drop into another + _dispatchEvent(null, parentEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); - // drag from one list and drop into another - _dispatchEvent(null, dragEl.parentNode, 'sort', dragEl, rootEl, oldIndex, newIndex); - _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); - - // Add event - _dispatchEvent(null, dragEl.parentNode, 'add', dragEl, rootEl, oldIndex, newIndex); + // Add event + _dispatchEvent(null, parentEl, 'add', dragEl, rootEl, oldIndex, newIndex); - // Remove event - _dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); + // Remove event + _dispatchEvent(this, rootEl, 'remove', dragEl, rootEl, oldIndex, newIndex); + } } else { // Remove clone @@ -726,10 +729,11 @@ if (dragEl.nextSibling !== nextEl) { // Get the index of the dragged element within its parent newIndex = _index(dragEl); - - // drag & drop within the same list - _dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); - _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + if (newIndex != -1) { + // drag & drop within the same list + _dispatchEvent(this, rootEl, 'update', dragEl, rootEl, oldIndex, newIndex); + _dispatchEvent(this, rootEl, 'sort', dragEl, rootEl, oldIndex, newIndex); + } } } @@ -741,10 +745,11 @@ this.save(); } } - + // Nulling rootEl = dragEl = + parentEl = ghostEl = nextEl = cloneEl = @@ -1092,6 +1097,9 @@ * @private */ function _index(/**HTMLElement*/el) { + if (!el || !el.parentNode) { + return -1; + } var index = 0; while (el && (el = el.previousElementSibling)) { if (el.nodeName.toUpperCase() !== 'TEMPLATE') { @@ -1152,9 +1160,6 @@ }; - Sortable.version = '1.2.2'; - - /** * Create sortable instance * @param {HTMLElement} el @@ -1163,7 +1168,9 @@ Sortable.create = function (el, options) { return new Sortable(el, options); }; + // Export + Sortable.version = '1.2.2'; return Sortable; }); diff --git a/Sortable.min.js b/Sortable.min.js index 2b332d2..29cb545 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 1.2.2 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[J]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this),e(a,"dragenter",this),Q.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){u&&u.state!==a&&(h(u,"display",a?"none":""),!a&&u.state&&v.insertBefore(u,s),u.state=a)}function c(a,b,c){if(a){c=c||L,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(I," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(I," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return L.defaultView&&L.defaultView.getComputedStyle?c=L.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=L.createEvent("Event"),i=(a||b[J]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=u,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[J],j=i.options.onMove;return g=L.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){O=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H={},I=/\s+/g,J="Sortable"+(new Date).getTime(),K=window,L=K.document,M=K.parseInt,N=!!("draggable"in L.createElement("div")),O=!1,P=Math.abs,Q=([].slice,[]),R=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(y!==c&&(x=b.scroll,y=c,x===!0)){x=c;do if(x.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=K)),(H.vx!==f||H.vy!==g||H.el!==d)&&(H.el=d,H.vx=f,H.vy=g,clearInterval(H.pid),d&&(H.pid=setInterval(function(){d===K?K.scrollTo(K.pageXOffset+f*i,K.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(B=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,B),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,B),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(E=a,v=g,s=c,w=s.nextSibling,D=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(E={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(E,"touch")):!N||this.options.forceFallback?this._onDragStart(E,!0):(e(s,"dragend",this),e(v,"dragstart",this._onDragStart));try{L.selection?L.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){v&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,v,"start",s,v,B))},_emulateDragOver:function(){if(F){h(t,"display","none");var a=L.elementFromPoint(F.clientX,F.clientY),b=a,c=" "+this.options.group.name,d=Q.length;if(b)do{if(b[J]&&b[J].options.groups.indexOf(c)>-1){for(;d--;)Q[d]({clientX:F.clientX,clientY:F.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(t,"display","")}},_onTouchMove:function(b){if(E){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-E.clientX,e=c.clientY-E.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";F=c,G=!0,h(t,"webkitTransform",f),h(t,"mozTransform",f),h(t,"msTransform",f),h(t,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!t){var a,b=s.getBoundingClientRect(),c=h(s);t=s.cloneNode(!0),g(t,this.options.ghostClass,!1),g(t,this.options.fallbackClass,!0),h(t,"top",b.top-M(c.marginTop,10)),h(t,"left",b.left-M(c.marginLeft,10)),h(t,"width",b.width),h(t,"height",b.height),h(t,"opacity","0.8"),h(t,"position","fixed"),h(t,"zIndex","100000"),this.options.fallbackOnBody&&L.body.appendChild(t)||v.appendChild(t),a=t.getBoundingClientRect(),h(t,"width",2*b.width-a.width),h(t,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==D.pull&&(u=s.cloneNode(!0),h(u,"display","none"),v.insertBefore(u,s)),b?("touch"===b?(e(L,"touchmove",this._onTouchMove),e(L,"touchend",this._onDrop),e(L,"touchcancel",this._onDrop)):(e(L,"mousemove",this._onTouchMove),e(L,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(L,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=D===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),D&&!i.disabled&&(o?p||(f=!v.contains(s)):D.pull&&l&&(D.name===j.name||l.indexOf&&~l.indexOf(D.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(R(a,i,this.el),O)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(u||w?v.insertBefore(s,u||w):p||v.appendChild(s));if(0===g.children.length||g.children[0]===t||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(v,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[J]){z!==d&&(z=d,A=h(d));var q,r=d.getBoundingClientRect(),x=r.right-r.left,y=r.bottom-r.top,B=/left|right|inline/.test(A.cssFloat+A.display),C=d.offsetWidth>s.offsetWidth,E=d.offsetHeight>s.offsetHeight,F=(B?(a.clientX-r.left)/x:(a.clientY-r.top)/y)>.5,G=d.nextElementSibling,H=k(v,g,s,e,d,r);H!==!1&&(O=!0,setTimeout(m,30),b(o),q=1===H||-1===H?1===H:B?d.previousElementSibling===s&&!C||F&&C:G!==s&&!E||F&&E,q&&!G?g.appendChild(s):d.parentNode.insertBefore(s,q?G:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(L,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(H.pid),clearTimeout(this._dragStartTimer),f(L,"drop",this),f(L,"mousemove",this._onTouchMove),f(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(G&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),t&&t.parentNode.removeChild(t),s&&(f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),v!==s.parentNode?(C=p(s),j(null,s.parentNode,"sort",s,v,B,C),j(this,v,"sort",s,v,B,C),j(null,s.parentNode,"add",s,v,B,C),j(this,v,"remove",s,v,B,C)):(u&&u.parentNode.removeChild(u),s.nextSibling!==w&&(C=p(s),j(this,v,"update",s,v,B,C),j(this,v,"sort",s,v,B,C))),a.active&&(j(this,v,"end",s,v,B,C),this.save())),v=s=t=w=u=x=y=E=F=G=z=A=D=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[J]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),Q.splice(Q.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.version="1.2.2",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define(a):"undefined"!=typeof module&&"undefined"!=typeof module.exports?module.exports=a():"undefined"!=typeof Package?Sortable=a():window.Sortable=a()}(function(){"use strict";function a(a,b){this.el=a,this.options=b=r({},b),a[K]=this;var c={group:Math.random(),sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:/[uo]l/i.test(a.nodeName)?"li":">*",ghostClass:"sortable-ghost",ignore:"a, img",filter:null,animation:0,setData:function(a,b){a.setData("Text",b.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1};for(var d in c)!(d in b)&&(b[d]=c[d]);var f=b.group;f&&"object"==typeof f||(f=b.group={name:f}),["pull","put"].forEach(function(a){a in f||(f[a]=!0)}),b.groups=" "+f.name+(f.put.join?" "+f.put.join(" "):"")+" ";for(var g in this)"_"===g.charAt(0)&&(this[g]=this[g].bind(this));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this),e(a,"dragenter",this),R.push(this._onDragOver),b.store&&this.sort(b.store.get(this))}function b(a){v&&v.state!==a&&(h(v,"display",a?"none":""),!a&&v.state&&w.insertBefore(v,s),v.state=a)}function c(a,b,c){if(a){c=c||M,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")(?=\\s)","g");do if(">*"===d&&a.parentNode===c||(""===d||a.nodeName.toUpperCase()==d)&&(!b.length||((" "+a.className+" ").match(e)||[]).length==b.length))return a;while(a!==c&&(a=a.parentNode))}return null}function d(a){a.dataTransfer.dropEffect="move",a.preventDefault()}function e(a,b,c){a.addEventListener(b,c,!1)}function f(a,b,c){a.removeEventListener(b,c,!1)}function g(a,b,c){if(a)if(a.classList)a.classList[c?"add":"remove"](b);else{var d=(" "+a.className+" ").replace(J," ").replace(" "+b+" "," ");a.className=(d+(c?" "+b:"")).replace(J," ")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return M.defaultView&&M.defaultView.getComputedStyle?c=M.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];b in d||(b="-webkit-"+b),d[b]=c+("string"==typeof c?"":"px")}}function i(a,b,c){if(a){var d=a.getElementsByTagName(b),e=0,f=d.length;if(c)for(;f>e;e++)c(d[e],e);return d}return[]}function j(a,b,c,d,e,f,g){var h=M.createEvent("Event"),i=(a||b[K]).options,j="on"+c.charAt(0).toUpperCase()+c.substr(1);h.initEvent(c,!0,!0),h.to=b,h.from=e||b,h.item=d||b,h.clone=v,h.oldIndex=f,h.newIndex=g,b.dispatchEvent(h),i[j]&&i[j].call(a,h)}function k(a,b,c,d,e,f){var g,h,i=a[K],j=i.options.onMove;return g=M.createEvent("Event"),g.initEvent("move",!0,!0),g.to=b,g.from=a,g.dragged=c,g.draggedRect=d,g.related=e||b,g.relatedRect=f||b.getBoundingClientRect(),a.dispatchEvent(g),j&&(h=j.call(i,g)),h}function l(a){a.draggable=!1}function m(){P=!1}function n(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function o(a){for(var b=a.tagName+a.className+a.src+a.href+a.textContent,c=b.length,d=0;c--;)d+=b.charCodeAt(c);return d.toString(36)}function p(a){if(!a||!a.parentNode)return-1;for(var b=0;a&&(a=a.previousElementSibling);)"TEMPLATE"!==a.nodeName.toUpperCase()&&b++;return b}function q(a,b){var c,d;return function(){void 0===c&&(c=arguments,d=this,setTimeout(function(){1===c.length?a.call(d,c[0]):a.apply(d,c),c=void 0},b))}}function r(a,b){if(a&&b)for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}var s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I={},J=/\s+/g,K="Sortable"+(new Date).getTime(),L=window,M=L.document,N=L.parseInt,O=!!("draggable"in M.createElement("div")),P=!1,Q=Math.abs,R=([].slice,[]),S=q(function(a,b,c){if(c&&b.scroll){var d,e,f,g,h=b.scrollSensitivity,i=b.scrollSpeed,j=a.clientX,k=a.clientY,l=window.innerWidth,m=window.innerHeight;if(z!==c&&(y=b.scroll,z=c,y===!0)){y=c;do if(y.offsetWidth=l-j)-(h>=j),g=(h>=m-k)-(h>=k),(f||g)&&(d=L)),(I.vx!==f||I.vy!==g||I.el!==d)&&(I.el=d,I.vx=f,I.vy=g,clearInterval(I.pid),d&&(I.pid=setInterval(function(){d===L?L.scrollTo(L.pageXOffset+f*i,L.pageYOffset+g*i):(g&&(d.scrollTop+=g*i),f&&(d.scrollLeft+=f*i))},24)))}},30);return a.prototype={constructor:a,_onTapStart:function(a){var b=this,d=this.el,e=this.options,f=a.type,g=a.touches&&a.touches[0],h=(g||a).target,i=h,k=e.filter;if(!("mousedown"===f&&0!==a.button||e.disabled)&&(h=c(h,e.draggable,d))){if(C=p(h),"function"==typeof k){if(k.call(this,a,h,this))return j(b,i,"filter",h,d,C),void a.preventDefault()}else if(k&&(k=k.split(",").some(function(a){return a=c(i,a.trim(),d),a?(j(b,a,"filter",h,d,C),!0):void 0})))return void a.preventDefault();(!e.handle||c(i,e.handle,d))&&this._prepareDragStart(a,g,h)}},_prepareDragStart:function(a,b,c){var d,f=this,g=f.el,h=f.options,j=g.ownerDocument;c&&!s&&c.parentNode===g&&(F=a,w=g,s=c,t=c.parentNode,x=s.nextSibling,E=h.group,d=function(){f._disableDelayedDrag(),s.draggable=!0,h.ignore.split(",").forEach(function(a){i(s,a.trim(),l)}),f._triggerDragStart(b)},e(j,"mouseup",f._onDrop),e(j,"touchend",f._onDrop),e(j,"touchcancel",f._onDrop),h.delay?(e(j,"mouseup",f._disableDelayedDrag),e(j,"touchend",f._disableDelayedDrag),e(j,"touchcancel",f._disableDelayedDrag),e(j,"mousemove",f._disableDelayedDrag),e(j,"touchmove",f._disableDelayedDrag),f._dragStartTimer=setTimeout(d,h.delay)):d())},_disableDelayedDrag:function(){var a=this.el.ownerDocument;clearTimeout(this._dragStartTimer),f(a,"mouseup",this._disableDelayedDrag),f(a,"touchend",this._disableDelayedDrag),f(a,"touchcancel",this._disableDelayedDrag),f(a,"mousemove",this._disableDelayedDrag),f(a,"touchmove",this._disableDelayedDrag)},_triggerDragStart:function(a){a?(F={target:s,clientX:a.clientX,clientY:a.clientY},this._onDragStart(F,"touch")):!O||this.options.forceFallback?this._onDragStart(F,!0):(e(s,"dragend",this),e(w,"dragstart",this._onDragStart));try{M.selection?M.selection.empty():window.getSelection().removeAllRanges()}catch(b){}},_dragStarted:function(){w&&s&&(g(s,this.options.ghostClass,!0),a.active=this,j(this,w,"start",s,w,C))},_emulateDragOver:function(){if(G){h(u,"display","none");var a=M.elementFromPoint(G.clientX,G.clientY),b=a,c=" "+this.options.group.name,d=R.length;if(b)do{if(b[K]&&b[K].options.groups.indexOf(c)>-1){for(;d--;)R[d]({clientX:G.clientX,clientY:G.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(u,"display","")}},_onTouchMove:function(b){if(F){a.active||this._dragStarted(),this._appendGhost();var c=b.touches?b.touches[0]:b,d=c.clientX-F.clientX,e=c.clientY-F.clientY,f=b.touches?"translate3d("+d+"px,"+e+"px,0)":"translate("+d+"px,"+e+"px)";G=c,H=!0,h(u,"webkitTransform",f),h(u,"mozTransform",f),h(u,"msTransform",f),h(u,"transform",f),b.preventDefault()}},_appendGhost:function(){if(!u){var a,b=s.getBoundingClientRect(),c=h(s);u=s.cloneNode(!0),g(u,this.options.ghostClass,!1),g(u,this.options.fallbackClass,!0),h(u,"top",b.top-N(c.marginTop,10)),h(u,"left",b.left-N(c.marginLeft,10)),h(u,"width",b.width),h(u,"height",b.height),h(u,"opacity","0.8"),h(u,"position","fixed"),h(u,"zIndex","100000"),this.options.fallbackOnBody&&M.body.appendChild(u)||w.appendChild(u),a=u.getBoundingClientRect(),h(u,"width",2*b.width-a.width),h(u,"height",2*b.height-a.height)}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;this._offUpEvents(),"clone"==E.pull&&(v=s.cloneNode(!0),h(v,"display","none"),w.insertBefore(v,s)),b?("touch"===b?(e(M,"touchmove",this._onTouchMove),e(M,"touchend",this._onDrop),e(M,"touchcancel",this._onDrop)):(e(M,"mousemove",this._onTouchMove),e(M,"mouseup",this._onDrop)),this._loopId=setInterval(this._emulateDragOver,150)):(c&&(c.effectAllowed="move",d.setData&&d.setData.call(this,c,s)),e(M,"drop",this),setTimeout(this._dragStarted,0))},_onDragOver:function(a){var d,e,f,g=this.el,i=this.options,j=i.group,l=j.put,o=E===j,p=i.sort;if(void 0!==a.preventDefault&&(a.preventDefault(),!i.dragoverBubble&&a.stopPropagation()),E&&!i.disabled&&(o?p||(f=!w.contains(s)):E.pull&&l&&(E.name===j.name||l.indexOf&&~l.indexOf(E.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(S(a,i,this.el),P)return;if(d=c(a.target,i.draggable,g),e=s.getBoundingClientRect(),f)return b(!0),void(v||x?w.insertBefore(s,v||x):p||w.appendChild(s));if(0===g.children.length||g.children[0]===u||g===a.target&&(d=n(g,a))){if(d){if(d.animated)return;r=d.getBoundingClientRect()}b(o),k(w,g,s,e,d,r)!==!1&&(g.appendChild(s),this._animate(e,s),d&&this._animate(r,d))}else if(d&&!d.animated&&d!==s&&void 0!==d.parentNode[K]){A!==d&&(A=d,B=h(d));var q,r=d.getBoundingClientRect(),t=r.right-r.left,y=r.bottom-r.top,z=/left|right|inline/.test(B.cssFloat+B.display),C=d.offsetWidth>s.offsetWidth,D=d.offsetHeight>s.offsetHeight,F=(z?(a.clientX-r.left)/t:(a.clientY-r.top)/y)>.5,G=d.nextElementSibling,H=k(w,g,s,e,d,r);H!==!1&&(P=!0,setTimeout(m,30),b(o),q=1===H||-1===H?1===H:z?d.previousElementSibling===s&&!C||F&&C:G!==s&&!D||F&&D,q&&!G?g.appendChild(s):d.parentNode.insertBefore(s,q?G:d),this._animate(e,s),this._animate(r,d))}}},_animate:function(a,b){var c=this.options.animation;if(c){var d=b.getBoundingClientRect();h(b,"transition","none"),h(b,"transform","translate3d("+(a.left-d.left)+"px,"+(a.top-d.top)+"px,0)"),b.offsetWidth,h(b,"transition","all "+c+"ms"),h(b,"transform","translate3d(0,0,0)"),clearTimeout(b.animated),b.animated=setTimeout(function(){h(b,"transition",""),h(b,"transform",""),b.animated=!1},c)}},_offUpEvents:function(){var a=this.el.ownerDocument;f(M,"touchmove",this._onTouchMove),f(a,"mouseup",this._onDrop),f(a,"touchend",this._onDrop),f(a,"touchcancel",this._onDrop)},_onDrop:function(b){var c=this.el,d=this.options;clearInterval(this._loopId),clearInterval(I.pid),clearTimeout(this._dragStartTimer),f(M,"drop",this),f(M,"mousemove",this._onTouchMove),f(c,"dragstart",this._onDragStart),this._offUpEvents(),b&&(H&&(b.preventDefault(),!d.dropBubble&&b.stopPropagation()),u&&u.parentNode.removeChild(u),s&&(f(s,"dragend",this),l(s),g(s,this.options.ghostClass,!1),w!==t?(D=p(s),-1!=D&&(j(null,t,"sort",s,w,C,D),j(this,w,"sort",s,w,C,D),j(null,t,"add",s,w,C,D),j(this,w,"remove",s,w,C,D))):(v&&v.parentNode.removeChild(v),s.nextSibling!==x&&(D=p(s),-1!=D&&(j(this,w,"update",s,w,C,D),j(this,w,"sort",s,w,C,D)))),a.active&&(j(this,w,"end",s,w,C,D),this.save())),w=s=t=u=x=v=y=z=F=G=H=A=B=E=a.active=null)},handleEvent:function(a){var b=a.type;"dragover"===b||"dragenter"===b?s&&(this._onDragOver(a),d(a)):("drop"===b||"dragend"===b)&&this._onDrop(a)},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length,g=this.options;f>e;e++)a=d[e],c(a,g.draggable,this.el)&&b.push(a.getAttribute(g.dataIdAttr)||o(a));return b},sort:function(a){var b={},d=this.el;this.toArray().forEach(function(a,e){var f=d.children[e];c(f,this.options.draggable,d)&&(b[a]=f)},this),a.forEach(function(a){b[a]&&(d.removeChild(b[a]),d.appendChild(b[a]))})},save:function(){var a=this.options.store;a&&a.set(this)},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},destroy:function(){var a=this.el;a[K]=null,f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this),f(a,"dragenter",this),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),R.splice(R.indexOf(this._onDragOver),1),this._onDrop(),this.el=a=null}},a.utils={on:e,off:f,css:h,find:i,is:function(a,b){return!!c(a,b,a)},extend:r,throttle:q,closest:c,toggleClass:g,index:p},a.create=function(b,c){return new a(b,c)},a.version="1.2.2",a}); \ No newline at end of file