diff --git a/README.md b/README.md index c33a67a..4252a2f 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ Sortable is a minimalist JavaScript library for reorderable drag-and-drop lists. * Supports touch devices and [modern](http://caniuse.com/#search=drag) browsers * Can drag from one list to another or within the same list * Animation moving items when sorting (css animation) + * Smart auto-scrolling * Built using native HTML5 drag and drop API * Support [AngularJS](#ng) * Simple API @@ -36,6 +37,9 @@ var sortabel = new Sortable(el, { group: "name", // or { name: "..", pull: [true, false, clone], put: [true, false, array] } sort: true, // sorting inside list store: null, // @see Store + scroll: true, // or HTMLElement + scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. + scrollSpeed: 10, // px animation: 150, // ms, animation speed moving items when sorting, `0` — without animation handle: ".my-handle", // Restricts sort start click/touch to the specified element filter: ".ignor-elements", // Selectors that do not lead to dragging (String or Function) diff --git a/Sortable.js b/Sortable.js index d5d5817..0b6ccde 100644 --- a/Sortable.js +++ b/Sortable.js @@ -28,6 +28,7 @@ ghostEl, cloneEl, rootEl, + scrollEl, nextEl, lastEl, @@ -60,6 +61,8 @@ _customEvents = 'onAdd onUpdate onRemove onStart onEnd onFilter onSort'.split(' '), noop = function () {}, + + abs = Math.abs, slice = [].slice, touchDragOverListeners = [] @@ -83,6 +86,9 @@ sort: true, store: null, handle: null, + scroll: true, + scrollSensitivity: 30, + scrollSpeed: 10, draggable: el.children[0] && el.children[0].nodeName || (/[uo]l/i.test(el.nodeName) ? 'li' : '*'), ghostClass: 'sortable-ghost', ignore: 'a, img', @@ -229,8 +235,9 @@ _on(document, 'touchend', this._onDrop); _on(document, 'touchcancel', this._onDrop); - _on(this.el, 'dragstart', this._onDragStart); - _on(this.el, 'dragend', this._onDrop); + _on(rootEl, 'dragstart', this._onDragStart); + _on(rootEl, 'dragend', this._onDrop); + _on(document, 'dragover', _globalDragOver); @@ -351,10 +358,58 @@ _on(document, 'drop', this._onDrop); } - setTimeout(this._applyEffects); + setTimeout(this._applyEffects, 0); + + scrollEl = options.scroll; + + if (scrollEl === true) { + scrollEl = dragEl; + + do { + if ((scrollEl.offsetWidth < scrollEl.scrollWidth) || + (scrollEl.offsetHeight < scrollEl.scrollHeight) + ) { + break; + } + /* jshint boss:true */ + } while (scrollEl = scrollEl.parentNode); + } }, + _onDrag: _throttle(function (/**Event*/evt) { + if (rootEl && this.options.scroll) { + var options = this.options, + sens = options.scrollSensitivity, + speed = options.scrollSpeed, + rect = rootEl.getBoundingClientRect(), + + x = evt.clientX, + y = evt.clientY, + + winWidth = window.innerWidth, + winHeight = window.innerHeight, + + vx = (winWidth - x <= sens) ? (rect.right > winWidth) : -(rect.left < 0 && x <= sens), + vy = (winHeight - y <= sens) ? (rect.bottom > winHeight) : -(rect.top < 0 && y <= sens) + ; + + + if (vx || vy) { + win.scrollTo(win.scrollX + vx * speed, win.scrollY + vy * speed); + } + else if (scrollEl) { + rect = scrollEl.getBoundingClientRect(); + vx = (abs(rect.right - x) <= sens) - (abs(rect.left - x) <= sens); + vy = (abs(rect.bottom - y) <= sens) - (abs(rect.top - y) <= sens); + + vy && (scrollEl.scrollTop += vy * speed); + vx && (scrollEl.scrollLeft += vx * speed); + } + } + }, 30), + + _onDragOver: function (/**Event*/evt) { var el = this.el, target, @@ -365,6 +420,9 @@ groupPut = group.put, isOwner = (activeGroup === group); + // Because bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521 + this._onDrag(evt); + if (!_silent && (activeGroup.name === group.name || groupPut && groupPut.indexOf && groupPut.indexOf(activeGroup.name) > -1) && (isOwner && (options.sort || (revert = !rootEl.contains(dragEl))) || groupPut && activeGroup.pull) && @@ -476,9 +534,9 @@ _off(document, 'drop', this._onDrop); _off(document, 'dragover', _globalDragOver); - _off(this.el, 'dragend', this._onDrop); - _off(this.el, 'dragstart', this._onDragStart); - _off(this.el, 'selectstart', this._onTapStart); + _off(rootEl, 'dragend', this._onDrop); + _off(rootEl, 'dragstart', this._onDragStart); + _off(rootEl, 'selectstart', this._onTapStart); this._offUpEvents(); @@ -764,6 +822,28 @@ } + function _throttle(callback, ms) { + var args, _this; + + return function () { + if (args === void 0) { + args = arguments; + _this = this; + + setTimeout(function () { + if (args.length === 1) { + callback.call(_this, args[0]); + } else { + callback.apply(_this, args); + } + + args = void 0; + }, ms); + } + }; + } + + // Export utils Sortable.utils = { on: _on, @@ -771,6 +851,7 @@ css: _css, find: _find, bind: _bind, + throttle: _throttle, closest: _closest, toggleClass: _toggleClass, dispatchEvent: _dispatchEvent diff --git a/Sortable.min.js b/Sortable.min.js index 0421e4b..660798f 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 0.6.0 - 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,c){this.el=a,this.options=c=c||{};var d={group:Math.random(),sort:!0,store:null,handle:null,draggable:a.children[0]&&a.children[0].nodeName||(/[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)}};for(var f in d)!(f in c)&&(c[f]=d[f]);c.group.name||(c.group={name:c.group}),["pull","put"].forEach(function(a){a in c.group||(c.group[a]=!0)}),E.forEach(function(d){c[d]=b(this,c[d]||F),e(a,d.substr(2).toLowerCase(),c[d])},this),a[x]=c.group.name;for(var g in this)"_"===g.charAt(0)&&(this[g]=b(this,this[g]));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),B&&e(a,"selectstart",this._onTapStart),e(a,"dragover",this._onDragOver),e(a,"dragenter",this._onDragOver),H.push(this._onDragOver),c.store&&this.sort(c.store.get(this))}function b(a,b){var c=G.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(G.call(arguments)))}}function c(a,b,c){if("*"===b)return a;if(a){c=c||z,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(!(""!==d&&a.nodeName!=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(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return z.defaultView&&z.defaultView.getComputedStyle?c=z.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){a.draggable=!1}function k(){C=!1}function l(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function m(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)}var n,o,p,q,r,s,t,u,v,w,x="Sortable"+(new Date).getTime(),y=window,z=y.document,A=y.parseInt,B=!!z.createElement("div").dragDrop,C=!1,D=function(a,b,c,d){var e=z.createEvent("Event");e.initEvent(b,!0,!0),e.item=c||a,e.from=d||a,a.dispatchEvent(e)},E="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),F=function(){},G=[].slice,H=[];return a.prototype={constructor:a,_applyEffects:function(){g(n,this.options.ghostClass,!0)},_onTapStart:function(a){var b=a.touches&&a.touches[0],f=(b||a).target,g=this.options,k=this.el,l=g.filter;if("mousedown"!==a.type||0===a.button){if("function"==typeof l){if(l.call(this,f,this))return D(k,"filter",f),void 0}else if(l&&(l=l.split(",").filter(function(a){return c(f,a.trim(),k)}),l.length))return D(k,"filter",f),void 0;if(g.handle&&(f=c(f,g.handle,k)),f=c(f,g.draggable,k),f&&"selectstart"==a.type&&"A"!=f.tagName&&"IMG"!=f.tagName&&f.dragDrop(),f&&!n&&f.parentNode===k){v=a,q=this.el,n=f,r=n.nextSibling,u=this.options.group,n.draggable=!0,g.ignore.split(",").forEach(function(a){i(f,a.trim(),j)}),b&&(v={target:f,clientX:b.clientX,clientY:b.clientY},this._onDragStart(v,!0),a.preventDefault()),e(z,"mouseup",this._onDrop),e(z,"touchend",this._onDrop),e(z,"touchcancel",this._onDrop),e(this.el,"dragstart",this._onDragStart),e(this.el,"dragend",this._onDrop),e(z,"dragover",d);try{z.selection?z.selection.empty():window.getSelection().removeAllRanges()}catch(m){}D(n,"start"),"clone"==u.pull&&(p=n.cloneNode(!0),h(p,"display","none"),q.insertBefore(p,n))}}},_emulateDragOver:function(){if(w){h(o,"display","none");var a=z.elementFromPoint(w.clientX,w.clientY),b=a,c=this.options.group.name,d=H.length;if(b)do{if(b[x]===c){for(;d--;)H[d]({clientX:w.clientX,clientY:w.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(o,"display","")}},_onTouchMove:function(a){if(v){var b=a.touches[0],c=b.clientX-v.clientX,d=b.clientY-v.clientY,e="translate3d("+c+"px,"+d+"px,0)";w=b,h(o,"webkitTransform",e),h(o,"mozTransform",e),h(o,"msTransform",e),h(o,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),b){var f,g=n.getBoundingClientRect(),i=h(n);o=n.cloneNode(!0),h(o,"top",g.top-A(i.marginTop,10)),h(o,"left",g.left-A(i.marginLeft,10)),h(o,"width",g.width),h(o,"height",g.height),h(o,"opacity","0.8"),h(o,"position","fixed"),h(o,"zIndex","100000"),q.appendChild(o),f=o.getBoundingClientRect(),h(o,"width",2*g.width-f.width),h(o,"height",2*g.height-f.height),e(z,"touchmove",this._onTouchMove),e(z,"touchend",this._onDrop),e(z,"touchcancel",this._onDrop),this._loopId=setInterval(this._emulateDragOver,150)}else c.effectAllowed="move",d.setData&&d.setData.call(this,c,n),e(z,"drop",this._onDrop);setTimeout(this._applyEffects)},_onDragOver:function(a){var b,d,e,f=this.el,g=this.options,i=g.group,j=i.put,m=u===i;if(!C&&(u.name===i.name||j&&j.indexOf&&j.indexOf(u.name)>-1)&&(m&&(g.sort||(e=!q.contains(n)))||j&&u.pull)&&(void 0===a.rootEl||a.rootEl===this.el)){if(b=c(a.target,g.draggable,f),d=n.getBoundingClientRect(),p&&p.state!==m&&(h(p,"display",m?"none":""),!m&&p.state&&q.insertBefore(p,n),p.state=m),e&&p)return q.insertBefore(n,p),void 0;if(0===f.children.length||f.children[0]===o||f===a.target&&(b=l(f,a))){if(b){if(b.animated)return;v=b.getBoundingClientRect()}f.appendChild(n),this._animate(d,n),b&&this._animate(v,b)}else if(b&&!b.animated&&b!==n&&void 0!==b.parentNode[x]){s!==b&&(s=b,t=h(b));var r,v=b.getBoundingClientRect(),w=v.right-v.left,y=v.bottom-v.top,z=/left|right|inline/.test(t.cssFloat+t.display),A=b.offsetWidth>n.offsetWidth,B=b.offsetHeight>n.offsetHeight,D=(z?(a.clientX-v.left)/w:(a.clientY-v.top)/y)>.5,E=b.nextElementSibling;C=!0,setTimeout(k,30),r=z?b.previousElementSibling===n&&!A||D&&A:E!==n&&!B||D&&B,r&&!E?f.appendChild(n):b.parentNode.insertBefore(n,r?E:b),this._animate(d,n),this._animate(v,b)}}},_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",""),b.animated=!1},c)}},_offUpEvents:function(){f(z,"mouseup",this._onDrop),f(z,"touchmove",this._onTouchMove),f(z,"touchend",this._onDrop),f(z,"touchcancel",this._onDrop)},_onDrop:function(a){clearInterval(this._loopId),f(z,"drop",this._onDrop),f(z,"dragover",d),f(this.el,"dragend",this._onDrop),f(this.el,"dragstart",this._onDragStart),f(this.el,"selectstart",this._onTapStart),this._offUpEvents(),a&&(a.preventDefault(),a.stopPropagation(),o&&o.parentNode.removeChild(o),n&&(j(n),g(n,this.options.ghostClass,!1),q.contains(n)?n.nextSibling!==r&&(D(n,"update"),D(n,"sort"),p&&p.parentNode.removeChild(p)):(D(n,"sort"),D(q,"sort"),D(n,"add",n,q),D(q,"remove",n)),D(q,"end")),q=n=o=r=p=v=w=s=t=u=null,this.options.store&&this.options.store.set(this))},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length;f>e;e++)a=d[e],c(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||m(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]))})},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},destroy:function(){var a=this.el,b=this.options;E.forEach(function(c){f(a,c.substr(2).toLowerCase(),b[c])}),f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"selectstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),H.splice(H.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:e,off:f,css:h,find:i,bind:b,closest:c,toggleClass:g,dispatchEvent:D},a.version="0.6.0",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,c){this.el=a,this.options=c=c||{};var d={group:Math.random(),sort:!0,store:null,handle:null,scroll:!0,scrollSensitivity:30,scrollSpeed:10,draggable:a.children[0]&&a.children[0].nodeName||(/[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)}};for(var f in d)!(f in c)&&(c[f]=d[f]);c.group.name||(c.group={name:c.group}),["pull","put"].forEach(function(a){a in c.group||(c.group[a]=!0)}),G.forEach(function(d){c[d]=b(this,c[d]||H),e(a,d.substr(2).toLowerCase(),c[d])},this),a[z]=c.group.name;for(var g in this)"_"===g.charAt(0)&&(this[g]=b(this,this[g]));e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),D&&e(a,"selectstart",this._onTapStart),e(a,"dragover",this._onDragOver),e(a,"dragenter",this._onDragOver),K.push(this._onDragOver),c.store&&this.sort(c.store.get(this))}function b(a,b){var c=J.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(J.call(arguments)))}}function c(a,b,c){if("*"===b)return a;if(a){c=c||B,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\s("+b.join("|")+")\\s","g");do if(!(""!==d&&a.nodeName!=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(/\s+/g," ").replace(" "+b+" ","");a.className=d+(c?" "+b:"")}}function h(a,b,c){var d=a&&a.style;if(d){if(void 0===c)return B.defaultView&&B.defaultView.getComputedStyle?c=B.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){a.draggable=!1}function k(){E=!1}function l(a,b){var c=a.lastElementChild,d=c.getBoundingClientRect();return b.clientY-(d.top+d.height)>5&&c}function m(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 n(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))}}var o,p,q,r,s,t,u,v,w,x,y,z="Sortable"+(new Date).getTime(),A=window,B=A.document,C=A.parseInt,D=!!B.createElement("div").dragDrop,E=!1,F=function(a,b,c,d){var e=B.createEvent("Event");e.initEvent(b,!0,!0),e.item=c||a,e.from=d||a,a.dispatchEvent(e)},G="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),H=function(){},I=Math.abs,J=[].slice,K=[];return a.prototype={constructor:a,_applyEffects:function(){g(o,this.options.ghostClass,!0)},_onTapStart:function(a){var b=a.touches&&a.touches[0],f=(b||a).target,g=this.options,k=this.el,l=g.filter;if("mousedown"!==a.type||0===a.button){if("function"==typeof l){if(l.call(this,f,this))return F(k,"filter",f),void 0}else if(l&&(l=l.split(",").filter(function(a){return c(f,a.trim(),k)}),l.length))return F(k,"filter",f),void 0;if(g.handle&&(f=c(f,g.handle,k)),f=c(f,g.draggable,k),f&&"selectstart"==a.type&&"A"!=f.tagName&&"IMG"!=f.tagName&&f.dragDrop(),f&&!o&&f.parentNode===k){x=a,r=this.el,o=f,t=o.nextSibling,w=this.options.group,o.draggable=!0,g.ignore.split(",").forEach(function(a){i(f,a.trim(),j)}),b&&(x={target:f,clientX:b.clientX,clientY:b.clientY},this._onDragStart(x,!0),a.preventDefault()),e(B,"mouseup",this._onDrop),e(B,"touchend",this._onDrop),e(B,"touchcancel",this._onDrop),e(r,"dragstart",this._onDragStart),e(r,"dragend",this._onDrop),e(B,"dragover",d);try{B.selection?B.selection.empty():window.getSelection().removeAllRanges()}catch(m){}F(o,"start"),"clone"==w.pull&&(q=o.cloneNode(!0),h(q,"display","none"),r.insertBefore(q,o))}}},_emulateDragOver:function(){if(y){h(p,"display","none");var a=B.elementFromPoint(y.clientX,y.clientY),b=a,c=this.options.group.name,d=K.length;if(b)do{if(b[z]===c){for(;d--;)K[d]({clientX:y.clientX,clientY:y.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(p,"display","")}},_onTouchMove:function(a){if(x){var b=a.touches[0],c=b.clientX-x.clientX,d=b.clientY-x.clientY,e="translate3d("+c+"px,"+d+"px,0)";y=b,h(p,"webkitTransform",e),h(p,"mozTransform",e),h(p,"msTransform",e),h(p,"transform",e),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),b){var f,g=o.getBoundingClientRect(),i=h(o);p=o.cloneNode(!0),h(p,"top",g.top-C(i.marginTop,10)),h(p,"left",g.left-C(i.marginLeft,10)),h(p,"width",g.width),h(p,"height",g.height),h(p,"opacity","0.8"),h(p,"position","fixed"),h(p,"zIndex","100000"),r.appendChild(p),f=p.getBoundingClientRect(),h(p,"width",2*g.width-f.width),h(p,"height",2*g.height-f.height),e(B,"touchmove",this._onTouchMove),e(B,"touchend",this._onDrop),e(B,"touchcancel",this._onDrop),this._loopId=setInterval(this._emulateDragOver,150)}else c.effectAllowed="move",d.setData&&d.setData.call(this,c,o),e(B,"drop",this._onDrop);if(setTimeout(this._applyEffects,0),s=d.scroll,s===!0){s=o;do if(s.offsetWidth=h-f?e.right>h:-(e.left<0&&c>=f),k=c>=i-g?e.bottom>i:-(e.top<0&&c>=g);j||k?A.scrollTo(A.scrollX+j*d,A.scrollY+k*d):s&&(e=s.getBoundingClientRect(),j=(I(e.right-f)<=c)-(I(e.left-f)<=c),k=(I(e.bottom-g)<=c)-(I(e.top-g)<=c),k&&(s.scrollTop+=k*d),j&&(s.scrollLeft+=j*d))}},30),_onDragOver:function(a){var b,d,e,f=this.el,g=this.options,i=g.group,j=i.put,m=w===i;if(this._onDrag(a),!E&&(w.name===i.name||j&&j.indexOf&&j.indexOf(w.name)>-1)&&(m&&(g.sort||(e=!r.contains(o)))||j&&w.pull)&&(void 0===a.rootEl||a.rootEl===this.el)){if(b=c(a.target,g.draggable,f),d=o.getBoundingClientRect(),q&&q.state!==m&&(h(q,"display",m?"none":""),!m&&q.state&&r.insertBefore(q,o),q.state=m),e&&q)return r.insertBefore(o,q),void 0;if(0===f.children.length||f.children[0]===p||f===a.target&&(b=l(f,a))){if(b){if(b.animated)return;s=b.getBoundingClientRect()}f.appendChild(o),this._animate(d,o),b&&this._animate(s,b)}else if(b&&!b.animated&&b!==o&&void 0!==b.parentNode[z]){u!==b&&(u=b,v=h(b));var n,s=b.getBoundingClientRect(),t=s.right-s.left,x=s.bottom-s.top,y=/left|right|inline/.test(v.cssFloat+v.display),A=b.offsetWidth>o.offsetWidth,B=b.offsetHeight>o.offsetHeight,C=(y?(a.clientX-s.left)/t:(a.clientY-s.top)/x)>.5,D=b.nextElementSibling;E=!0,setTimeout(k,30),n=y?b.previousElementSibling===o&&!A||C&&A:D!==o&&!B||C&&B,n&&!D?f.appendChild(o):b.parentNode.insertBefore(o,n?D:b),this._animate(d,o),this._animate(s,b)}}},_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",""),b.animated=!1},c)}},_offUpEvents:function(){f(B,"mouseup",this._onDrop),f(B,"touchmove",this._onTouchMove),f(B,"touchend",this._onDrop),f(B,"touchcancel",this._onDrop)},_onDrop:function(a){clearInterval(this._loopId),f(B,"drop",this._onDrop),f(B,"dragover",d),f(r,"dragend",this._onDrop),f(r,"dragstart",this._onDragStart),f(r,"selectstart",this._onTapStart),this._offUpEvents(),a&&(a.preventDefault(),a.stopPropagation(),p&&p.parentNode.removeChild(p),o&&(j(o),g(o,this.options.ghostClass,!1),r.contains(o)?o.nextSibling!==t&&(F(o,"update"),F(o,"sort"),q&&q.parentNode.removeChild(q)):(F(o,"sort"),F(r,"sort"),F(o,"add",o,r),F(r,"remove",o)),F(r,"end")),r=o=p=t=q=x=y=u=v=w=null,this.options.store&&this.options.store.set(this))},toArray:function(){for(var a,b=[],d=this.el.children,e=0,f=d.length;f>e;e++)a=d[e],c(a,this.options.draggable,this.el)&&b.push(a.getAttribute("data-id")||m(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]))})},closest:function(a,b){return c(a,b||this.options.draggable,this.el)},destroy:function(){var a=this.el,b=this.options;G.forEach(function(c){f(a,c.substr(2).toLowerCase(),b[c])}),f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"selectstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),Array.prototype.forEach.call(a.querySelectorAll("[draggable]"),function(a){a.removeAttribute("draggable")}),K.splice(K.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:e,off:f,css:h,find:i,bind:b,throttle:n,closest:c,toggleClass:g,dispatchEvent:F},a.version="0.6.0",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file