UNPKG

sortable-dnd

Version:

JS library for drag-and-drop lists, supports sortable and draggable

7 lines (6 loc) 20.8 kB
/*! * sortable-dnd v0.6.22 * open source under the MIT license * https://github.com/mfuu/sortable-dnd#readme */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Sortable=e()}(this,(function(){"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(){return e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t},e.apply(this,arguments)}var n={capture:!1,passive:!1},o=/\s+/g;function i(t){if("undefined"!=typeof window&&window.navigator)return!!navigator.userAgent.match(t)}var r=i(/(?:Trident.*rv[ :]?11\.|msie|iemobile|Windows Phone)/i),s=i(/Edge/i),l=i(/safari/i)&&!i(/chrome/i)&&!i(/android/i),a=function(){var t=!1;return document.addEventListener("checkIfSupportPassive",null,{get passive(){return t=!0,!0}}),t}();function c(t,e,o){window.addEventListener?t.addEventListener(e,o,!(!a&&r)&&n):window.attachEvent?t.attachEvent("on"+e,o):t["on"+e]=o}function h(t,e,o){window.removeEventListener?t.removeEventListener(e,o,!(!a&&r)&&n):window.detachEvent?t.detachEvent("on"+e,o):t["on"+e]=null}function u(){return document.scrollingElement||document.documentElement}function d(t,e,n){if(t.getBoundingClientRect||t===window){var o,i,r,s,l,a,c;if(t!==window&&t.parentNode&&t!==u()?(i=(o=t.getBoundingClientRect()).top,r=o.left,s=o.bottom,l=o.right,a=o.height,c=o.width):(i=0,r=0,s=window.innerHeight,l=window.innerWidth,a=window.innerHeight,c=window.innerWidth),e&&t!==window){n=n||t.parentNode;do{if(n&&n.getBoundingClientRect){var h=n.getBoundingClientRect();i-=h.top+parseInt(S(n,"border-top-width")),r-=h.left+parseInt(S(n,"border-left-width")),s=i+o.height,l=r+o.width;break}}while(n=n.parentNode)}return{top:i,left:r,bottom:s,right:l,width:c,height:a}}}function p(t,e,n,o){if(t){n=n||document;do{if(null!=e&&(">"===e[0]?t.parentNode===n&&b(t,e):b(t,e))||o&&t===n)return t;if(t===n)break}while(t=t.parentNode);return null}}function f(t,e){if(!t||!e)return!1;if(e.compareDocumentPosition)return!!(16&e.compareDocumentPosition(t));if(e.contains&&1===t.nodeType)return e.contains(t)&&e!==t;for(;t=t.parentNode;)if(t===e)return!0;return!1}function m(t,e){for(var n=t.lastElementChild;n&&(n===ot.ghost||"none"===S(n,"display")||e&&!b(n,e));)n=n.previousElementSibling;return n||null}function g(t,e){if(!t||!t.parentNode)return-1;for(var n=0;t=t.previousElementSibling;)"TEMPLATE"===t.nodeName.toUpperCase()||e&&!b(t,e)||"none"===S(t,"display")||n++;return n}function v(t,e,n,o){for(var i=0,r=0,s=t.children;i<s.length;){if(s[i]!==ot.ghost&&"none"!==S(s[i],"display")&&p(s[i],n,t,!1)&&(o||s[i]!==ot.dragged)){if(r===e)return s[i];r++}i++}return null}function y(t,e){var n=S(t),o=parseInt(n.width)-parseInt(n.paddingLeft)-parseInt(n.paddingRight)-parseInt(n.borderLeftWidth)-parseInt(n.borderRightWidth),i=v(t,0,e),l=v(t,1,e),a=i&&S(i),c=l&&S(l),h=a&&parseInt(a.marginLeft)+parseInt(a.marginRight)+d(i).width,u=c&&parseInt(c.marginLeft)+parseInt(c.marginRight)+d(l).width,p=s||r?"cssFloat":"float";if("flex"===n.display)return"column"===n.flexDirection||"column-reverse"===n.flexDirection?"vertical":"horizontal";if("grid"===n.display)return n.gridTemplateColumns.split(" ").length<=1?"vertical":"horizontal";if(i&&a.float&&"none"!==a.float){var f="left"===a.float?"left":"right";return!l||"both"!==c.clear&&c.clear!==f?"horizontal":"vertical"}return i&&("block"===a.display||"flex"===a.display||"table"===a.display||"grid"===a.display||h>=o&&"none"===n[p]||l&&"none"===n[p]&&h+u>o)?"vertical":"horizontal"}function w(t,e,n){if(t&&e)if(t.classList)t.classList[n?"add":"remove"](e);else{var i=(" "+t.className+" ").replace(o," ").replace(" "+e+" "," ");t.className=(i+(n?" "+e:"")).replace(o," ")}}function b(t,e){if(e){if(">"===e[0]&&(e=e.substring(1)),t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e);if(t.webkitMatchesSelector)return t.webkitMatchesSelector(e)}catch(t){return!1}return!1}}function S(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return document.defaultView&&document.defaultView.getComputedStyle?n=document.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in o||-1!==e.indexOf("webkit")||(e="-webkit-"+e),o[e]=n+("string"==typeof n?"":"px")}}function _(t,e){var n,o,i=(o=e,(n=t).compareDocumentPosition?n.compareDocumentPosition(o):n.contains?(n!=o&&n.contains(o)&&16)+(n!=o&&o.contains(n)&&8)+(n.sourceIndex>=0&&o.sourceIndex>=0?(n.sourceIndex<o.sourceIndex&&4)+(n.sourceIndex>o.sourceIndex&&2):1):0);return 2===i?1:4===i?-1:0}function x(t){void 0!==t.preventDefault&&t.cancelable&&t.preventDefault()}function C(t){var n=t.sortable,o=t.name,i=t.evt,r=n.options[o];"function"==typeof r&&r(e({},i))}!function(){if("undefined"==typeof window||"undefined"==typeof document)return"";var t=window.getComputedStyle(document.documentElement,"")||["-moz-hidden-iframe"],e=(Array.prototype.slice.call(t).join("").match(/-(moz|webkit|ms)-/)||""===t.OLink&&["","o"])[1];e&&"-".concat(e,"-")}();var D,E,I,M="Sortable"+Date.now();function T(t){this.options=t,this.scrollEl=null,this.autoScrollInterval=null}function N(t){this.options=t,this.stack=[]}function P(t){this.options=t||{},this.selects=[]}T.prototype={nulling:function(){this.autoScrollInterval&&(clearInterval(this.autoScrollInterval),this.autoScrollInterval=null)},onStarted:function(){var t=this;this.nulling(),this.autoScrollInterval=setInterval((function(){t.autoScroll()}))},onMove:function(t,e,n){this.options=n,this.scrollEl=t,this.moveEvent=e},autoScroll:function(){var t=this.moveEvent,e=this.scrollEl;if(e&&void 0!==t.clientX&&void 0!==t.clientY){var n=d(e);if(n){var o=t.clientX,i=t.clientY,r=n.top,s=n.right,l=n.bottom,a=n.left,c=n.height,h=n.width;if(!(i<r||o>s||i>l||o<a)){var u=this.options,p=u.scrollThreshold,f=u.scrollSpeed,m=e.scrollTop,g=e.scrollLeft,v=e.scrollHeight,y=m>0&&i>=r&&i<=r+p,w=g+h<e.scrollWidth&&o<=s&&o>=s-p,b=m+c<v&&i<=l&&i>=l-p;g>0&&o>=a&&o<=a+p&&(e.scrollLeft+=Math.floor(Math.max(-1,(o-a)/p-1)*f.x)),w&&(e.scrollLeft+=Math.ceil(Math.min(1,(o-s)/p+1)*f.x)),y&&(e.scrollTop+=Math.floor(Math.max(-1,(i-r)/p-1)*f.y)),b&&(e.scrollTop+=Math.ceil(Math.min(1,(i-l)/p+1)*f.y))}}}}},N.prototype={collect:function(t){if(t){for(var e=d(t),n=window.innerWidth||document.documentElement.clientWidth||document.body.clientWidth,o=window.innerHeight||document.documentElement.clientHeight||document.body.clientHeight,i=Math.min(e.right,n),r=Math.min(e.bottom,o),s=Array.prototype.slice.call(t.children),l=[],a=0,c=s.length;a<=c;a++){var h=s[a];if(h&&h!==ot.ghost&&"none"!==S(h,"display")){var u=d(h);if(!(u.bottom<0||u.right<0)){if(u.top-u.height>r||u.left-u.width>i)break;l.push({el:h,rect:u})}}}this.stack.push(l)}},animate:function(){var t=this.stack.pop();if(t&&this.options.animation)for(var e=0,n=t.length;e<n;e++){var o=t[e],i=o.el,r=o.rect;this.execute(i,r)}},execute:function(t,e){var n=d(t);if(n.top!==e.top||n.left!==e.left){var o=e.left-n.left,i=e.top-n.top;S(t,"transition",""),S(t,"transform","translate3d(".concat(o,"px, ").concat(i,"px, 0)")),this.repaintDummy=function(t){return t.offsetWidth}(t);var r=this.options,s=r.animation,l=r.easing;S(t,"transition","transform ".concat(s,"ms ").concat(l?" "+l:"")),S(t,"transform","translate3d(0px, 0px, 0px)"),"number"==typeof t.animated&&clearTimeout(t.animated),t.animated=setTimeout((function(){S(t,"transition",""),S(t,"transform",""),t.animated=null}),s)}}},P.prototype={eventProperties:function(){return{nodes:D||[],clones:E||[]}},isActive:function(){return!!D},nulling:function(){D=E=I=null},select:function(t){w(t,this.options.selectedClass,!0),this.selects.push(t),this.selects.sort((function(t,e){return _(t,e)}))},deselect:function(t){var e=this.selects.indexOf(t);e>-1&&(w(t,this.options.selectedClass,!1),this.selects.splice(e,1))},useSelectHandle:function(t,e){var n=this.options.selectHandle;return!!(I="function"==typeof n&&n(t)||"string"==typeof n&&b(e,n))},onChoose:function(){!this.options.multiple||0===this.selects.length||this.selects.indexOf(ot.dragged)<0||(this.selects.sort((function(t,e){return _(t,e)})),D=this.selects,this.toggleChosenClass(!0))},onDrop:function(t,e,n){if(D){var o=ot.dragged,i=ot.clone,r=D.indexOf(o);t!==e&&n?(S(i,"display","none"),this.toggleVisible(!0),E=D.map((function(t){return t.cloneNode(!0)})),this.sortElements(E,r,i)):this.sortElements(D,r,i),t!==e&&(e[M].multiplayer.toggleSelected(E||D,"add"),!n&&t[M].multiplayer.toggleSelected(D,"remove"))}},onSelect:function(t,e,n,o){var i=this.options,r=i.multiple,s=i.selectHandle;if(r&&(s&&I||!s&&!n)){var l=this.selects.indexOf(e);w(e,this.options.selectedClass,l<0);var a={from:o.el,event:t,node:e,index:g(e)};l<0?(this.selects.push(e),C({sortable:o,name:"onSelect",evt:a})):(this.selects.splice(l,1),C({sortable:o,name:"onDeselect",evt:a})),this.selects.sort((function(t,e){return _(t,e)}))}},toggleChosenClass:function(t){if(D)for(var e=0,n=D.length;e<n;e++)w(D[e],this.options.chosenClass,t)},toggleVisible:function(t){if(D)for(var e=0,n=D.length;e<n;e++)D[e]!=ot.dragged&&S(D[e],"display",t?"":"none")},toggleSelected:function(t,e){var n=this;"add"===e?t.forEach((function(t){return n.selects.push(t)})):this.selects=this.selects.filter((function(e){return t.indexOf(e)<0}))},sortElements:function(t,e,n){for(var o=0,i=t.length;o<i;o++)if(S(t[o],"display",""),o<e)n.parentNode.insertBefore(t[o],n);else{var r=o>0?t[o-1]:n;n.parentNode.insertBefore(t[o],r.nextSibling)}}};var O,H,k,L,X,Y,B,R,W,A,z,V,j,G,U,F,q,J,K,Q,Z,$,tt=[];function et(e){var n,o,i,r={},s=e.group;s&&"object"===t(s)||(s={name:s,pull:!0,put:!0,revertDrag:!0}),r.name=s.name,r.pull=null===(n=s.pull)||void 0===n||n,r.put=null===(o=s.put)||void 0===o||o,r.revertDrag=null===(i=s.revertDrag)||void 0===i||i,e.group=r}function nt(t){var e=F||U;return!(void 0!==t.clientX&&void 0!==t.clientY&&Math.abs(t.clientX-e.clientX)<=0&&Math.abs(t.clientY-e.clientY)<=0)}function ot(t,n){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable-dnd: `el` must be an HTMLElement, not ".concat({}.toString.call(t));t[M]=this,this.el=t,this.options=n=e({},n);var o={store:null,group:"",handle:null,sortable:!0,disabled:!1,multiple:!1,lockAxis:"",direction:"",animation:150,easing:"",draggable:">*",selectHandle:null,customGhost:null,autoScroll:!0,scrollThreshold:55,scrollSpeed:{x:10,y:10},delay:0,delayOnTouchOnly:!1,touchStartThreshold:(Number.parseInt?Number:window).parseInt(window.devicePixelRatio,10)||1,ghostClass:"",ghostStyle:{},chosenClass:"",selectedClass:"",placeholderClass:"",swapOnDrop:!0,removeCloneOnDrop:!0,fallbackOnBody:!1,supportTouch:"ontouchstart"in window,emptyInsertThreshold:-1};for(var i in o)!(i in this.options)&&(this.options[i]=o[i]);for(var r in et(n),this)"_"===r.charAt(0)&&"function"==typeof this[r]&&(this[r]=this[r].bind(this));c(t,this.options.supportTouch?"touchstart":"mousedown",this._onDrag),this.autoScroller=new T(this.options),this.multiplayer=new P(this.options),this.animator=new N(this.options),tt.push(t)}return ot.prototype={constructor:ot,_onDrag:function(t){var e=this;if(!k&&!this.options.disabled&&this.options.group.pull&&(!/mousedown|pointerdown/.test(t.type)||0===t.button)){var n=t.touches&&t.touches[0],o=(n||t).target;if(!l||!o||"SELECT"!==o.tagName.toUpperCase()){var i=p(o,this.options.draggable,this.el);if(i&&!i.animated&&(U={event:t,clientX:(n||t).clientX,clientY:(n||t).clientY},k=i,c(Q=n?k:document,"mouseup",this._onDrop),c(Q,"touchend",this._onDrop),c(Q,"touchcancel",this._onDrop),!this.multiplayer.useSelectHandle(t,o))){var a=this.options.handle;if(("function"!=typeof a||a(t))&&("string"!=typeof a||b(o,a))){var h=this.options,u=h.delay,d=h.delayOnTouchOnly;!u||d&&!n||s||r?this._onStart(n,t):(c(this.el.ownerDocument,"touchmove",this._delayMoveHandler),c(this.el.ownerDocument,"mousemove",this._delayMoveHandler),c(this.el.ownerDocument,"mouseup",this._cancelStart),c(this.el.ownerDocument,"touchend",this._cancelStart),c(this.el.ownerDocument,"touchcancel",this._cancelStart),$=setTimeout((function(){return e._onStart(n,t)}),u)),c(document,"selectstart",x),l&&S(document.body,"user-select","none")}}}}},_delayMoveHandler:function(t){var e=t.touches?t.touches[0]:t;Math.max(Math.abs(e.clientX-U.clientX),Math.abs(e.clientY-U.clientY))>=Math.floor(this.options.touchStartThreshold/(window.devicePixelRatio||1))&&this._cancelStart()},_cancelStart:function(){clearTimeout($),h(this.el.ownerDocument,"touchmove",this._delayMoveHandler),h(this.el.ownerDocument,"mousemove",this._delayMoveHandler),h(this.el.ownerDocument,"mouseup",this._cancelStart),h(this.el.ownerDocument,"touchend",this._cancelStart),h(this.el.ownerDocument,"touchcancel",this._cancelStart),h(document,"selectstart",x),l&&S(document.body,"user-select","")},_onStart:function(t,e){x(e);var n=g(k);O=this.el,H=this.el,W=k,V=n,j=n,G=n,J={to:this.el,target:k,newIndex:n,relative:0},K=k,R=this.el,Y=k.cloneNode(!0),A=k.parentNode,z=this.options.group.pull,ot.clone=Y,ot.active=this,ot.dragged=k,this.multiplayer.onChoose(),w(k,this.options.chosenClass,!0),C({sortable:this,name:"onChoose",evt:this._getEventProperties(e)}),c(Q,t?"touchmove":"mousemove",this._nearestSortable);try{document.selection?setTimeout((function(){return document.selection.empty()}),0):window.getSelection().removeAllRanges()}catch(t){}},_onStarted:function(){this.animator.collect(A),w(Y,this.options.chosenClass,!0),w(Y,this.options.placeholderClass,!0),this._appendGhost(),this.multiplayer.toggleVisible(!1),S(k,"display","none"),k.parentNode.insertBefore(Y,k),C({sortable:this,name:"onDrag",evt:this._getEventProperties(U.event)}),this.animator.animate(),this.autoScroller.onStarted()},_getGhostElement:function(){var t=this.options.customGhost;if("function"==typeof t){var e=this.multiplayer.selects;return t(this.multiplayer.isActive()?e:[k])}return k},_appendGhost:function(){if(!B){var t=this.options.fallbackOnBody?document.body:this.el,n=this._getGhostElement();w(B=n.cloneNode(!0),this.options.ghostClass,!0);var o=d(k),i=e({position:"fixed",top:o.top,left:o.left,width:o.width,height:o.height,zIndex:"100000",opacity:"0.8",overflow:"hidden",boxSizing:"border-box",transform:"",transition:"",pointerEvents:"none"},this.options.ghostStyle);for(var r in i)S(B,r,i[r]);ot.ghost=B,t.appendChild(B);var s=(U.clientX-o.left)/parseInt(B.style.width)*100,l=(U.clientY-o.top)/parseInt(B.style.height)*100;S(B,"transform-origin","".concat(s,"% ").concat(l,"%")),S(B,"will-change","transform")}},_nearestSortable:function(t){x(t);var e=t.touches&&t.touches[0]||t;if(k&&nt(e)){!F&&this._onStarted();var n=this.options.lockAxis,o="x"===n?U.clientX:e.clientX,i="y"===n?U.clientY:e.clientY,r=document.elementFromPoint(o,i),s=o-U.clientX,l=i-U.clientY;F={event:t,clientX:o,clientY:i},S(B,"transform","translate3d(".concat(s,"px, ").concat(l,"px, 0)"));var a,c,h,p=(a=o,c=i,tt.reduce((function(t,e){var n=e[M].options.emptyInsertThreshold;if(null!=n){var o=d(e),i=a>=o.left-n&&a<=o.right+n,r=c>=o.top-n&&c<=o.bottom+n;return i&&r&&(!h||h&&o.left>=h.left&&o.right<=h.right&&o.top>=h.top&&o.bottom<=h.bottom)&&(t=e,h=o),t}}),null));p&&p[M]._onMove(t,r);var f=p?p[M].options:null,m=null;(!p||f.autoScroll)&&U&&F&&(m=function(t,e){if(!t||!t.getBoundingClientRect)return u();var n=t,o=!1;do{if(n.clientWidth<n.scrollWidth||n.clientHeight<n.scrollHeight){var i=S(n);if(n.clientWidth<n.scrollWidth&&("auto"==i.overflowX||"scroll"==i.overflowX)||n.clientHeight<n.scrollHeight&&("auto"==i.overflowY||"scroll"==i.overflowY)){if(!n.getBoundingClientRect||n===document.body)return u();if(o||e)return n;o=!0}}}while(n=n.parentNode);return u()}(r,!0)),this.autoScroller.onMove(m,F,f||this.options)}},_allowPut:function(){if(R===this.el)return!0;if(!this.options.group.put)return!1;var t=this.options.group,e=t.name,n=t.put,o=R[M].options.group;return n.join&&n.indexOf(o.name)>-1||o.name&&e&&o.name===e},_getDirection:function(){var t=this.options,e=t.draggable,n=t.direction;return n?"function"==typeof n?n.call(F.event,Y,this):n:y(A,e)},_allowSwap:function(){var t=d(L),e="vertical"===this._getDirection(),n=e?"top":"left",o=e?"bottom":"right",i=L[e?"offsetHeight":"offsetWidth"],r=e?F.clientY:F.clientX,s=r>=t[n]&&r<t[o]-i/2?-1:1,l=v(A,0,this.options.draggable),a=m(A),c=d(l),h=d(a);if(L===A||f(A,L))return Y===l&&r<c[n]?(X=L,!0):Y===a&&r>h[o]&&(X=L.nextSibling,!0);var u=_(Y,L);return X=u<0?L.nextSibling:L,q!==L?(Z=s,!0):Z!==s&&(Z=s,s<0?u>0:u<0)},_onMove:function(t,e){if(!this.options.disabled&&this._allowPut()){if(L=p(e,this.options.draggable,this.el),C({sortable:this,name:"onMove",evt:this._getEventProperties(t,{target:L})}),this.options.sortable||this.el!==R)return this.el===H||e!==this.el&&m(this.el)?void(L&&!L.animated&&!f(L,Y)&&this._allowSwap()&&(L!==Y&&X!==Y?(this.el!==H?this._onInsert(t):L!==k&&this._onChange(t),q=L):q=L)):(L=q=null,void this._onInsert(t));H!==R&&(L=q=k,Z=0,this._onInsert(t))}},_onInsert:function(t){var e=L||Y,n="clone"===z&&this.el!==R&&H===R,o="clone"===z&&this.el===R&&H!==R,i=f(L,document),r=L===k&&!i,s=H[M],l=R[M];O=this.el,V=g(Y),W=e,A=i?L.parentNode:this.el,s.animator.collect(Y.parentNode),this.animator.collect(A),n&&(J.target=K,J.newIndex=V,J.relative=K===k?0:_(Y,K),S(k,"display",""),l.multiplayer.toggleVisible(!0),l.options.group.revertDrag||Y.parentNode.insertBefore(k,Y)),o&&(V=g(k),S(k,"display","none"),this.multiplayer.toggleVisible(!1)),S(Y,"display",r?"none":""),L&&i?A.insertBefore(Y,Z<0?L:L.nextSibling):A.appendChild(Y),j=r?G:g(Y),n&&l.options.group.revertDrag&&(J.target=k,J.newIndex=G,J.relative=0,C({sortable:l,name:"onChange",evt:this._getEventProperties(t,{to:R,target:k,newIndex:G,revertDrag:!0})})),n||C({sortable:s,name:"onRemove",evt:this._getEventProperties(t,{newIndex:-1})}),o&&e!==k&&(K=e,C({sortable:this,name:"onChange",evt:this._getEventProperties(t,{from:R,backToOrigin:!0})})),o||C({sortable:this,name:"onAdd",evt:this._getEventProperties(t,{oldIndex:-1})}),s.animator.animate(),this.animator.animate(),H=this.el},_onChange:function(t){this.animator.collect(A),V=g(Y),A=L.parentNode,W=L,this.el===R&&(K=L),A.insertBefore(Y,X),j=g(Y),C({sortable:this,name:"onChange",evt:this._getEventProperties(t)}),this.animator.animate(),H=this.el},_onDrop:function(t){this._cancelStart(),h(Q,"touchmove",this._nearestSortable),h(Q,"mousemove",this._nearestSortable),h(Q,"mouseup",this._onDrop),h(Q,"touchend",this._onDrop),h(Q,"touchcancel",this._onDrop),R&&(H=R,V=G,W===Y&&(W=k),this.animator.collect(A),this.multiplayer.toggleChosenClass(!1),w(k,this.options.chosenClass,!1),C({sortable:this,name:"onUnchoose",evt:this._getEventProperties(t)}),F&&this._onEnd(t),!F&&this.animator.animate()),!nt(t.changedTouches?t.changedTouches[0]:t)&&this.multiplayer.onSelect(t,k,R,this),B&&B.parentNode&&B.parentNode.removeChild(B),this._nulling()},_onEnd:function(t){w(Y,this.options.chosenClass,!1),w(Y,this.options.placeholderClass,!1);var n="clone"===z;this.multiplayer.onDrop(H,O,n);var o=this._getEventProperties(t),i=this.options,r=i.swapOnDrop,s=i.removeCloneOnDrop;n&&H!==O||!("function"==typeof r?r(o):r)||A.insertBefore(k,Y),n&&H!==O&&!this.multiplayer.isActive()||!("function"==typeof s?s(o):s)||Y&&Y.parentNode&&Y.parentNode.removeChild(Y),S(k,"display",""),this.animator.animate(),H!==O&&C({sortable:H[M],name:"onDrop",evt:e({},o,n?J:{newIndex:-1})}),C({sortable:O[M],name:"onDrop",evt:e({},o,H===O?{}:{oldIndex:-1})})},_getEventProperties:function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},o={};return o.event=t,o.to=O,o.from=H,o.node=k,o.clone=Y,o.target=W,o.oldIndex=V,o.newIndex=j,o.pullMode=z,e(o,this.multiplayer.eventProperties(),n),o.relative=W===k?0:_(Y,W),o},_nulling:function(){O=H=k=L=X=Y=B=R=W=A=z=V=j=G=U=F=q=J=K=Q=Z=$=ot.clone=ot.ghost=ot.active=ot.dragged=null,this.multiplayer.nulling(),this.autoScroller.nulling()},destroy:function(){this._cancelStart(),this._nulling(),h(this.el,"touchstart",this._onDrag),h(this.el,"mousedown",this._onDrag);var t=tt.indexOf(this.el);t>-1&&tt.splice(t,1),this.el[M]=this.animator=this.multiplayer=this.autoScroller=null},option:function(t,e){if(void 0===e)return this.options[t];this.options[t]=e,this.animator.options[t]=e,this.multiplayer.options[t]=e,this.autoScroller.options[t]=e,"group"===t&&et(this.options)},select:function(t){this.multiplayer.select(t)},deselect:function(t){this.multiplayer.deselect(t)},getSelectedElements:function(){return this.multiplayer.selects}},ot.utils={on:c,off:h,css:S,index:g,closest:p,getRect:d,toggleClass:w,detectDirection:y},ot.get=function(t){return t[M]},ot.create=function(t,e){return new ot(t,e)},ot}));