You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

3 lines
16 KiB

/*! Sortable 1.7.0 - MIT | git://github.com/rubaxa/Sortable.git */
!function(t){"use strict";"function"==typeof define&&define.amd?define(t):"undefined"!=typeof module&&void 0!==module.exports?module.exports=t():window.Sortable=t()}(function(){"use strict";if("undefined"==typeof window||!window.document)return function(){throw new Error("Sortable.js requires a window with a document")};var t,e,n,o,i,r,a,l,s,c,d,h,u,f,p,g,v,m,_,b,D,y={},w=/\s+/g,T=/left|right|inline/,S="Sortable"+(new Date).getTime(),E=window,C=E.document,x=E.parseInt,N=E.setTimeout,k=E.jQuery||E.Zepto,P=E.Polymer,Y=!1,X="draggable"in C.createElement("div"),M=!navigator.userAgent.match(/(?:Trident.*rv[ :]?11\.|msie)/i)&&((D=C.createElement("x")).style.cssText="pointer-events:auto","auto"===D.style.pointerEvents),I=!1,O=Math.abs,A=Math.min,B=[],H=[],L=function(){return!1},R=ot(function(t,e,n){if(n&&e.scroll){var o,i,r,a,d,h,u=n[S],f=e.scrollSensitivity,p=e.scrollSpeed,g=t.clientX,v=t.clientY,m=window.innerWidth,b=window.innerHeight;if(s!==n&&(l=e.scroll,s=n,c=e.scrollFn,!0===l)){l=n;do{if(l.offsetWidth<l.scrollWidth||l.offsetHeight<l.scrollHeight)break}while(l=l.parentNode)}l&&(o=l,i=st(l),r=(O(i.right-g)<=f)-(O(i.left-g)<=f),a=(O(i.bottom-v)<=f)-(O(i.top-v)<=f)),r||a||(a=(b-v<=f)-(v<=f),((r=(m-g<=f)-(g<=f))||a)&&(o=E)),y.vx===r&&y.vy===a&&y.el===o||(y.el=o,y.vx=r,y.vy=a,clearInterval(y.pid),o&&(y.pid=setInterval(function(){h=a?a*p:0,d=r?r*p:0,"function"==typeof c&&"continue"!==c.call(u,d,h,t,_,o)||(o===E?E.scrollTo(E.pageXOffset+d,E.pageYOffset+h):(o.scrollTop+=h,o.scrollLeft+=d))},24)))}},30),F=function(t){function e(t,e){return null!=t&&!0!==t||null!=(t=n.name)?"function"==typeof t?t:function(n,o){var i=o.options.group.name;return e?t:t&&(t.join?t.indexOf(i)>-1:i==t)}:L}var n={},o=t.group;o&&"object"==typeof o||(o={name:o}),n.name=o.name,n.checkPull=e(o.pull,!0),n.checkPut=e(o.put),n.revertClone=o.revertClone,t.group=n};try{window.addEventListener("test",null,Object.defineProperty({},"passive",{get:function(){Y={capture:!1,passive:!1}}}))}catch(t){}function q(t,e){if(!t||!t.nodeType||1!==t.nodeType)throw"Sortable: `el` must be HTMLElement, and not "+{}.toString.call(t);this.el=t,this.options=e=it({},e),t[S]=this;var n={group:null,sort:!0,disabled:!1,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,swap:!1,draggable:/[uo]l/i.test(t.nodeName)?"li":">*",ghostClass:"sortable-ghost",chosenClass:"sortable-chosen",dragClass:"sortable-drag",swapClass:"sortable-swap-highlight",ignore:"a, img",filter:null,preventOnFilter:!0,animation:0,setData:function(t,e){t.setData("Text",e.textContent)},dropBubble:!1,dragoverBubble:!1,dataIdAttr:"data-id",delay:0,touchStartThreshold:x(window.devicePixelRatio,10)||1,forceFallback:!1,fallbackClass:"sortable-fallback",fallbackOnBody:!1,fallbackTolerance:0,fallbackOffset:{x:0,y:0},supportPointer:!1!==q.supportPointer};for(var o in n)!(o in e)&&(e[o]=n[o]);F(e);for(var i in this)"_"===i.charAt(0)&&"function"==typeof this[i]&&(this[i]=this[i].bind(this));this.nativeDraggable=!e.forceFallback&&X,U(t,"mousedown",this._onTapStart),U(t,"touchstart",this._onTapStart),e.supportPointer&&U(t,"pointerdown",this._onTapStart),this.nativeDraggable&&(U(t,"dragover",this),U(t,"dragenter",this)),H.push(this._onDragOver),e.store&&this.sort(e.store.get(this))}function W(e,n){"clone"!==e.lastPullMode&&(n=!0),o&&o.state!==n&&(G(o,"display",n?"none":""),n||o.state&&(e.options.group.revertClone?(ct(i,o,r),e._animate(t,o)):ct(i,o,t)),o.state=n)}function j(t,e,n){if(t){n=n||C;do{if(">*"===e&&t.parentNode===n||nt(t,e))return t}while(void 0,t=(i=(o=t).host)&&i.nodeType?i:o.parentNode)}var o,i;return null}function U(t,e,n){t.addEventListener(e,n,Y)}function V(t,e,n){t.removeEventListener(e,n,Y)}function z(t,e,n){if(t)if(t.classList)t.classList[n?"add":"remove"](e);else{var o=(" "+t.className+" ").replace(w," ").replace(" "+e+" "," ");t.className=(o+(n?" "+e:"")).replace(w," ")}}function G(t,e,n){var o=t&&t.style;if(o){if(void 0===n)return C.defaultView&&C.defaultView.getComputedStyle?n=C.defaultView.getComputedStyle(t,""):t.currentStyle&&(n=t.currentStyle),void 0===e?n:n[e];e in o||(e="-webkit-"+e),o[e]=n+("string"==typeof n?"":"px")}}function Q(t,e,n){if(t){var o=t.getElementsByTagName(e),i=0,r=o.length;if(n)for(;i<r;i++)n(o[i],i);return o}return[]}function Z(t,e,n,i,r,a,l,s,c,d){t=t||e[S];var h=C.createEvent("Event"),u=t.options,f="on"+n.charAt(0).toUpperCase()+n.substr(1);if(h.initEvent(n,!0,!0),h.to=r||e,h.from=a||e,h.item=i||e,h.clone=o,h.oldIndex=l,h.newIndex=s,h.originalEvent=c,d)for(var p in d)h[p]=d[p];e.dispatchEvent(h),u[f]&&u[f].call(t,h)}function J(t,e,n,o,i,r,a,l){var s,c,d=t[S],h=d.options.onMove;return(s=C.createEvent("Event")).initEvent("move",!0,!0),s.to=e,s.from=t,s.dragged=n,s.draggedRect=o,s.related=i||e,s.relatedRect=r||st(e),s.willInsertAfter=l,s.originalEvent=a,t.dispatchEvent(s),h&&(c=h.call(d,s,a)),c}function K(t){t.draggable=!1}function $(){I=!1}function tt(t){for(var e=t.tagName+t.className+t.src+t.href+t.textContent,n=e.length,o=0;n--;)o+=e.charCodeAt(n);return o.toString(36)}function et(t,e){var n=0;if(!t||!t.parentNode)return-1;for(;t&&(t=t.previousElementSibling);)"TEMPLATE"===t.nodeName.toUpperCase()||">*"!==e&&!nt(t,e)||n++;return n}function nt(t,e){if(t)try{if(t.matches)return t.matches(e);if(t.msMatchesSelector)return t.msMatchesSelector(e)}catch(t){return!1}return!1}function ot(t,e){var n,o;return function(){void 0===n&&(n=arguments,o=this,N(function(){1===n.length?t.call(o,n[0]):t.apply(o,n),n=void 0},e))}}function it(t,e){if(t&&e)for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n]);return t}function rt(t){return P&&P.dom?P.dom(t).cloneNode(!0):k?k(t).clone(!0)[0]:t.cloneNode(!0)}function at(t){return N(t,0)}function lt(t){return clearTimeout(t)}function st(t){return t.getBoundingClientRect()}function ct(t,e,n){null===t&&(t=n.parentNode),t.insertBefore(e,n)}return q.prototype={constructor:q,_onTapStart:function(e){var n,o=this,i=this.el,r=this.options,l=r.preventOnFilter,s=e.type,c=e.touches&&e.touches[0],d=(c||e).target,h=e.target.shadowRoot&&e.path&&e.path[0]||d,u=r.filter;if(function(t){B.length=0;var e=t.getElementsByTagName("input"),n=e.length;for(;n--;){var o=e[n];o.checked&&B.push(o)}}(i),!t&&!(/mousedown|pointerdown/.test(s)&&0!==e.button||r.disabled)&&!h.isContentEditable&&(d=j(d,r.draggable,i))&&a!==d){if(n=et(d,r.draggable),"function"==typeof u){if(u.call(this,e,d,this))return Z(o,h,"filter",d,i,i,n),void(l&&e.preventDefault())}else if(u&&(u=u.split(",").some(function(t){if(t=j(h,t.trim(),i))return Z(o,t,"filter",d,i,i,n),!0})))return void(l&&e.preventDefault());r.handle&&!j(h,r.handle,i)||this._prepareDragStart(e,c,d,n)}},_prepareDragStart:function(n,o,l,s){var c,d=this,h=d.el,u=d.options,p=h.ownerDocument;l&&!t&&l.parentNode===h&&(m=n,i=h,e=(t=l).parentNode,r=t.nextSibling,a=l,g=u.group,f=s,this._lastX=(o||n).clientX,this._lastY=(o||n).clientY,t.style["will-change"]="all",c=function(){d._disableDelayedDrag(),t.draggable=d.nativeDraggable,z(t,u.chosenClass,!0),d._triggerDragStart(n,o),Z(d,i,"choose",t,i,i,f)},u.ignore.split(",").forEach(function(e){Q(t,e.trim(),K)}),U(p,"mouseup",d._onDrop),U(p,"touchend",d._onDrop),U(p,"touchcancel",d._onDrop),U(p,"selectstart",d),u.supportPointer&&U(p,"pointercancel",d._onDrop),u.delay?(U(p,"mouseup",d._disableDelayedDrag),U(p,"touchend",d._disableDelayedDrag),U(p,"touchcancel",d._disableDelayedDrag),U(p,"mousemove",d._disableDelayedDrag),U(p,"touchmove",d._delayedDragTouchMoveHandler),u.supportPointer&&U(p,"pointermove",d._delayedDragTouchMoveHandler),d._dragStartTimer=N(c,u.delay)):c())},_delayedDragTouchMoveHandler:function(t){A(O(t.clientX-this._lastX),O(t.clientY-this._lastY))>=this.options.touchStartThreshold&&this._disableDelayedDrag()},_disableDelayedDrag:function(){var t=this.el.ownerDocument;clearTimeout(this._dragStartTimer),V(t,"mouseup",this._disableDelayedDrag),V(t,"touchend",this._disableDelayedDrag),V(t,"touchcancel",this._disableDelayedDrag),V(t,"mousemove",this._disableDelayedDrag),V(t,"touchmove",this._disableDelayedDrag),V(t,"pointermove",this._disableDelayedDrag)},_triggerDragStart:function(e,n){(n=n||("touch"==e.pointerType?e:null))?(m={target:t,clientX:n.clientX,clientY:n.clientY},this._onDragStart(m,"touch")):this.nativeDraggable?(U(t,"dragend",this),U(i,"dragstart",this._onDragStart)):this._onDragStart(m,!0);try{C.selection?at(function(){C.selection.empty()}):window.getSelection().removeAllRanges()}catch(t){}},_dragStarted:function(){if(i&&t){var e=this.options;z(t,e.ghostClass,!0),z(t,e.dragClass,!1),q.active=this,Z(this,i,"start",t,i,i,f)}else this._nulling()},_emulateDragOver:function(){if(_){if(this._lastX===_.clientX&&this._lastY===_.clientY)return;this._lastX=_.clientX,this._lastY=_.clientY,M||G(n,"display","none");for(var t=C.elementFromPoint(_.clientX,_.clientY),e=t,o=H.length;t&&t.shadowRoot;)e=t=t.shadowRoot.elementFromPoint(_.clientX,_.clientY);if(e)do{if(e[S]){for(;o--;)H[o]({clientX:_.clientX,clientY:_.clientY,target:t,rootEl:e});break}t=e}while(e=e.parentNode);M||G(n,"display","")}},_onTouchMove:function(t){if(m){var e=this.options,o=e.fallbackTolerance,i=e.fallbackOffset,r=t.touches?t.touches[0]:t,a=r.clientX-m.clientX+i.x,l=r.clientY-m.clientY+i.y,s=t.touches?"translate3d("+a+"px,"+l+"px,0)":"translate("+a+"px,"+l+"px)";if(!q.active){if(o&&A(O(r.clientX-this._lastX),O(r.clientY-this._lastY))<o)return;this._dragStarted()}this._appendGhost(),b=!0,_=r,G(n,"webkitTransform",s),G(n,"mozTransform",s),G(n,"msTransform",s),G(n,"transform",s),t.preventDefault()}},_appendGhost:function(){if(!n){var e,o=st(t),r=G(t),a=this.options;z(n=t.cloneNode(!0),a.ghostClass,!1),z(n,a.fallbackClass,!0),z(n,a.dragClass,!0),G(n,"top",o.top-x(r.marginTop,10)),G(n,"left",o.left-x(r.marginLeft,10)),G(n,"width",o.width),G(n,"height",o.height),G(n,"opacity","0.8"),G(n,"position","fixed"),G(n,"zIndex","100000"),G(n,"pointerEvents","none"),a.fallbackOnBody?ct(C.body,n,null):ct(i,n,null),e=st(n),G(n,"width",2*o.width-e.width),G(n,"height",2*o.height-e.height)}},_onDragStart:function(e,n){var r=this,a=e.dataTransfer,l=r.options;r._offUpEvents(),g.checkPull(r,r,t,e)&&((o=rt(t)).draggable=!1,o.style["will-change"]="",G(o,"display","none"),z(o,r.options.chosenClass,!1),r._cloneId=at(function(){ct(i,o,t),Z(r,i,"clone",t)})),z(t,l.dragClass,!0),n?("touch"===n?(U(C,"touchmove",r._onTouchMove),U(C,"touchend",r._onDrop),U(C,"touchcancel",r._onDrop),l.supportPointer&&(U(C,"pointermove",r._onTouchMove),U(C,"pointerup",r._onDrop))):(U(C,"mousemove",r._onTouchMove),U(C,"mouseup",r._onDrop)),r._loopId=setInterval(r._emulateDragOver,50)):(a&&(a.effectAllowed="move",l.setData&&l.setData.call(r,a,t)),U(C,"drop",r),r._dragStartId=at(r._dragStarted))},_onDragOver:function(a){var l,s,c,f,p,m,_=this.el,D=this.options,y=D.group,w=q.active,E=g===y,C=!1,x=D.sort;if((void 0!==a.preventDefault&&(a.preventDefault(),!D.dragoverBubble&&a.stopPropagation()),!t.animated)&&(b=!0,w&&!D.disabled&&(E?x||(f=!i.contains(t)):v===this||(w.lastPullMode=g.checkPull(this,w,t,a))&&y.checkPut(this,w,t,a))&&(void 0===a.rootEl||a.rootEl===this.el))){if(R(a,D,this.el),I)return;if(l=j(a.target,D.draggable,_),s=st(t),v!==this&&(v=this,C=!0),D.swap)return void(l&&(d&&z(d,D.swapClass,!1),z(l,D.swapClass,!0),d=l));if(f)return W(w,!0),e=i,void(o||r?ct(i,t,o||r):x||ct(i,t,null));if(0===_.children.length||_.children[0]===n||_===a.target&&(p=a,m=st(_.lastElementChild),p.clientY-(m.top+m.height)>5||p.clientX-(m.left+m.width)>5)){if(0!==_.children.length&&_.children[0]!==n&&_===a.target&&(l=_.lastElementChild),l){if(l.animated)return;c=st(l)}W(w,E),!1!==J(i,_,t,s,l,c,a)&&(t.contains(_)||(ct(_,t,null),e=_),this._animate(s,t),l&&this._animate(c,l))}else if(l&&!l.animated&&l!==t&&void 0!==l.parentNode[S]){d!==l&&(d=l,h=G(l),u=G(l.parentNode));var k=(c=st(l)).right-c.left,P=c.bottom-c.top,Y=T.test(h.cssFloat+h.display)||"flex"==u.display&&0===u["flex-direction"].indexOf("row"),X=l.offsetWidth>t.offsetWidth,M=l.offsetHeight>t.offsetHeight,O=(Y?(a.clientX-c.left)/k:(a.clientY-c.top)/P)>.5,A=l.nextElementSibling,B=!1;if(Y){var H=t.offsetTop,L=l.offsetTop;B=H===L?l.previousElementSibling===t&&!X||O&&X:l.previousElementSibling===t||t.previousElementSibling===l?(a.clientY-c.top)/P>.5:L>H}else C||(B=A!==t&&!M||O&&M);var F=J(i,_,t,s,l,c,a,B);!1!==F&&(1!==F&&-1!==F||(B=1===F),I=!0,N($,30),W(w,E),t.contains(_)||(B&&!A?ct(_,t,null):ct(null,t,B?A:l)),e=t.parentNode,this._animate(s,t),this._animate(c,l))}}},_animate:function(t,e){var n=this.options.animation;if(n){var o=st(e);1===t.nodeType&&(t=st(t)),G(e,"transition","none"),G(e,"transform","translate3d("+(t.left-o.left)+"px,"+(t.top-o.top)+"px,0)"),e.offsetWidth,G(e,"transition","all "+n+"ms"),G(e,"transform","translate3d(0,0,0)"),clearTimeout(e.animated),e.animated=N(function(){G(e,"transition",""),G(e,"transform",""),e.animated=!1},n)}},_offUpEvents:function(){var t=this.el.ownerDocument;V(C,"touchmove",this._onTouchMove),V(C,"pointermove",this._onTouchMove),V(t,"mouseup",this._onDrop),V(t,"touchend",this._onDrop),V(t,"pointerup",this._onDrop),V(t,"touchcancel",this._onDrop),V(t,"pointercancel",this._onDrop),V(t,"selectstart",this)},_onDrop:function(a){var l=this.el,s=this.options;if(clearInterval(this._loopId),clearInterval(y.pid),clearTimeout(this._dragStartTimer),lt(this._cloneId),lt(this._dragStartId),V(C,"mouseover",this),V(C,"mousemove",this._onTouchMove),this.nativeDraggable&&(V(C,"drop",this),V(l,"dragstart",this._onDragStart)),this._offUpEvents(),d&&s.swap&&(z(d,s.swapClass,!1),t!==d)){var c=st(t),h=st(d);!function(t,e){var n,o,i=t.parentNode,r=e.parentNode;if(!i||!r||i.isEqualNode(e)||r.isEqualNode(t))return;for(var a=0;a<i.children.length;a++)i.children[a].isEqualNode(t)&&(n=a);for(var a=0;a<r.children.length;a++)r.children[a].isEqualNode(e)&&(o=a);i.isEqualNode(r)&&n<o&&o++;i.insertBefore(e,i.children[n]),r.insertBefore(t,r.children[o])}(t,d),this._animate(c,t),this._animate(h,d)}a&&(b&&(a.preventDefault(),!s.dropBubble&&a.stopPropagation()),n&&n.parentNode&&n.parentNode.removeChild(n),i!==e&&"clone"===q.active.lastPullMode||o&&o.parentNode&&o.parentNode.removeChild(o),t&&(this.nativeDraggable&&V(t,"dragend",this),K(t),t.style["will-change"]="",z(t,this.options.ghostClass,!1),z(t,this.options.chosenClass,!1),Z(this,i,"unchoose",t,e,i,f,null,a),i!==e?(p=et(t,s.draggable))>=0&&(Z(null,e,"add",t,e,i,f,p,a),Z(this,i,"remove",t,e,i,f,p,a),Z(null,e,"sort",t,e,i,f,p,a),Z(this,i,"sort",t,e,i,f,p,a)):t.nextSibling!==r&&(p=et(t,s.draggable))>=0&&(Z(this,i,"update",t,e,i,f,p,a),Z(this,i,"sort",t,e,i,f,p,a)),q.active&&(null!=p&&-1!==p||(p=f),s.swap&&d?t!==d&&Z(this,i,"end",t,e,i,f,p,a,{swapItem:d}):Z(this,i,"end",t,e,i,f,p,a),this.save()))),this._nulling()},_nulling:function(){i=t=e=n=r=o=a=l=s=m=_=b=p=d=h=v=g=q.active=null,B.forEach(function(t){t.checked=!0}),B.length=0},handleEvent:function(e){switch(e.type){case"drop":case"dragend":this._onDrop(e);break;case"dragover":case"dragenter":t&&(this._onDragOver(e),function(t){t.dataTransfer&&(t.dataTransfer.dropEffect="move");t.preventDefault()}(e));break;case"mouseover":this._onDrop(e);break;case"selectstart":e.preventDefault()}},toArray:function(){for(var t,e=[],n=this.el.children,o=0,i=n.length,r=this.options;o<i;o++)j(t=n[o],r.draggable,this.el)&&e.push(t.getAttribute(r.dataIdAttr)||tt(t));return e},sort:function(t){var e={},n=this.el;this.toArray().forEach(function(t,o){var i=n.children[o];j(i,this.options.draggable,n)&&(e[t]=i)},this),t.forEach(function(t){e[t]&&(n.removeChild(e[t]),ct(n,e[t],null))})},save:function(){var t=this.options.store;t&&t.set(this)},closest:function(t,e){return j(t,e||this.options.draggable,this.el)},option:function(t,e){var n=this.options;if(void 0===e)return n[t];n[t]=e,"group"===t&&F(n)},destroy:function(){var t=this.el;t[S]=null,V(t,"mousedown",this._onTapStart),V(t,"touchstart",this._onTapStart),V(t,"pointerdown",this._onTapStart),this.nativeDraggable&&(V(t,"dragover",this),V(t,"dragenter",this)),Array.prototype.forEach.call(t.querySelectorAll("[draggable]"),function(t){t.removeAttribute("draggable")}),H.splice(H.indexOf(this._onDragOver),1),this._onDrop(),this.el=t=null}},U(C,"touchmove",function(t){q.active&&t.preventDefault()}),q.utils={on:U,off:V,css:G,find:Q,is:function(t,e){return!!j(t,e,t)},extend:it,throttle:ot,closest:j,toggleClass:z,clone:rt,index:et,nextTick:at,cancelNextTick:lt,getBoundingClientRect:st,insertBefore:ct},q.create=function(t,e){return new q(t,e)},q.version="1.7.0",q});