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