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.
 
 
 

2 lines
14 KiB

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