diff --git a/README.md b/README.md index 0e6b659..b58b94a 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ Demo: http://rubaxa.github.io/Sortable/ * Can drag from one list to another or within the same list * CSS animation when moving items * Supports drag handles *and selectable text* (better than voidberg's html5sortable) + * Smart auto-scrolling * Built using native HTML5 drag and drop API * Supports [AngularJS](#ng) and and any CSS library, e.g. [Bootstrap](#bs) * Simple API @@ -48,6 +49,11 @@ var sortable = new Sortable(el, { filter: ".ignore-elements", // Selectors that do not lead to dragging (String or Function) draggable: ".item", // Specifies which items inside the element should be sortable ghostClass: "sortable-ghost", // Class name for the drop placeholder - jsbin.com/luxero/3 + + scroll: true, // or HTMLElement + scrollSensitivity: 30, // px, how near the mouse must be to an edge to start scrolling. + scrollSpeed: 10, // px + setData: function (dataTransfer, dragEl) { dataTransfer.setData('Text', dragEl.textContent); }, diff --git a/Sortable.js b/Sortable.js index 201df15..ea51817 100644 --- a/Sortable.js +++ b/Sortable.js @@ -29,12 +29,14 @@ ghostEl, cloneEl, rootEl, + scrollEl, nextEl, lastEl, lastCSS, activeGroup, + autoScroll = {}, tapEvt, touchEvt, @@ -65,6 +67,8 @@ _customEvents = 'onAdd onUpdate onRemove onStart onEnd onFilter onSort'.split(' '), noop = function () {}, + + abs = Math.abs, slice = [].slice, touchDragOverListeners = [] @@ -89,6 +93,9 @@ disabled: false, 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', @@ -242,9 +249,10 @@ _on(document, 'touchend', this._onDrop); _on(document, 'touchcancel', this._onDrop); - _on(this.el, 'dragstart', this._onDragStart); - _on(this.el, 'dragend', this._onDrop); - _on(document, 'dragover', _globalDragOver); + _on(rootEl, 'dragstart', this._onDragStart); + _on(rootEl, 'dragend', this._onDrop); + + _on(document, 'dragover', this); try { @@ -318,6 +326,7 @@ _css(ghostEl, 'msTransform', translate3d); _css(ghostEl, 'transform', translate3d); + this._onDrag(touch); evt.preventDefault(); } }, @@ -362,12 +371,77 @@ dataTransfer.effectAllowed = 'move'; options.setData && options.setData.call(this, dataTransfer, dragEl); - _on(document, 'drop', this._onDrop); + _on(document, 'drop', this); } - setTimeout(this._applyEffects); + setTimeout(this._applyEffects, 0); + + scrollEl = options.scroll; + + if (scrollEl === true) { + scrollEl = rootEl; + + do { + if ((scrollEl.offsetWidth < scrollEl.scrollWidth) || + (scrollEl.offsetHeight < scrollEl.scrollHeight) + ) { + break; + } + /* jshint boss:true */ + } while (scrollEl = scrollEl.parentNode); + } }, + _onDrag: _throttle(function (/**Event*/evt) { + // Bug: https://bugzilla.mozilla.org/show_bug.cgi?id=505521 + if (rootEl && this.options.scroll) { + var el, + rect, + options = this.options, + sens = options.scrollSensitivity, + speed = options.scrollSpeed, + + x = evt.clientX, + y = evt.clientY, + + winWidth = window.innerWidth, + winHeight = window.innerHeight, + + vx = (winWidth - x <= sens) - (x <= sens), + vy = (winHeight - y <= sens) - (y <= sens) + ; + + if (vx || vy) { + el = win; + } + else if (scrollEl) { + el = 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); + } + + if (autoScroll.vx !== vx || autoScroll.vy !== vy || autoScroll.el !== el) { + autoScroll.el = el; + autoScroll.vx = vx; + autoScroll.vy = vy; + + clearInterval(autoScroll.pid); + + if (el) { + autoScroll.pid = setInterval(function () { + if (el === win) { + win.scrollTo(win.scrollX + vx * speed, win.scrollY + vy * speed); + } else { + vy && (el.scrollTop += vy * speed); + vx && (el.scrollLeft += vx * speed); + } + }, 24); + } + } + } + }, 30), + _onDragOver: function (/**Event*/evt) { var el = this.el, @@ -496,15 +570,17 @@ }, _onDrop: function (/**Event*/evt) { + var el = this.el; + clearInterval(this._loopId); + clearInterval(autoScroll.pid); // Unbind events - _off(document, 'drop', this._onDrop); - _off(document, 'dragover', _globalDragOver); + _off(document, 'drop', this); + _off(document, 'dragover', this); - _off(this.el, 'dragend', this._onDrop); - _off(this.el, 'dragstart', this._onDragStart); - _off(this.el, 'selectstart', this._onTapStart); + _off(el, 'dragend', this._onDrop); + _off(el, 'dragstart', this._onDragStart); this._offUpEvents(); @@ -564,6 +640,19 @@ }, + handleEvent: function (/**Event*/evt) { + var type = evt.type; + + if (type === 'dragover') { + this._onDrag(evt); + _globalDragOver(evt); + } + else if (type === 'drop') { + this._onDrop(evt); + } + }, + + /** * Serializes the item into an array of string. * @returns {String[]} @@ -824,6 +913,28 @@ return index; } + 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, @@ -834,6 +945,7 @@ is: function (el, selector) { return !!_closest(el, selector, el); }, + throttle: _throttle, closest: _closest, toggleClass: _toggleClass, dispatchEvent: _dispatchEvent, diff --git a/Sortable.min.js b/Sortable.min.js index 824d55d..8815673 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 0.7.2 - 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,disabled:!1,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)}),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),J.push(this._onDragOver),c.store&&this.sort(c.store.get(this))}function b(a,b){var c=I.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(I.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){for(var b=0;a=a.previousElementSibling;)b++;return 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,e,f){var g=B.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,void 0!==e&&(g.oldIndex=e),void 0!==f&&(g.newIndex=f),a.dispatchEvent(g)},G="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),H=function(){},I=[].slice,J=[];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(p=n(f),!("mousedown"===a.type&&0!==a.button||g.disabled)){if("function"==typeof l){if(l.call(this,f,this))return void F(k,"filter",f)}else if(l&&(l=l.split(",").filter(function(a){return c(f,a.trim(),k)}),l.length))return void F(k,"filter",f);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,s=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(this.el,"dragstart",this._onDragStart),e(this.el,"dragend",this._onDrop),e(B,"dragover",d);try{B.selection?B.selection.empty():window.getSelection().removeAllRanges()}catch(m){}F(o,"start",void 0,void 0,p),"clone"==w.pull&&(r=o.cloneNode(!0),h(r,"display","none"),s.insertBefore(r,o))}}},_emulateDragOver:function(){if(y){h(q,"display","none");var a=B.elementFromPoint(y.clientX,y.clientY),b=a,c=this.options.group.name,d=J.length;if(b)do{if(b[z]===c){for(;d--;)J[d]({clientX:y.clientX,clientY:y.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(q,"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(q,"webkitTransform",e),h(q,"mozTransform",e),h(q,"msTransform",e),h(q,"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);q=o.cloneNode(!0),h(q,"top",g.top-C(i.marginTop,10)),h(q,"left",g.left-C(i.marginLeft,10)),h(q,"width",g.width),h(q,"height",g.height),h(q,"opacity","0.8"),h(q,"position","fixed"),h(q,"zIndex","100000"),s.appendChild(q),f=q.getBoundingClientRect(),h(q,"width",2*g.width-f.width),h(q,"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);setTimeout(this._applyEffects)},_onDragOver:function(a){var b,d,e,f=this.el,g=this.options,i=g.group,j=i.put,m=w===i,n=g.sort;if(!E&&(m?n||(e=!s.contains(o)):w.pull&&j&&(w.name===i.name||j.indexOf&&~j.indexOf(w.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(b=c(a.target,g.draggable,f),d=o.getBoundingClientRect(),r&&r.state!==m&&(h(r,"display",m?"none":""),!m&&r.state&&s.insertBefore(r,o),r.state=m),e)return void(r||t?s.insertBefore(o,r||t):n||s.appendChild(o));if(0===f.children.length||f.children[0]===q||f===a.target&&(b=l(f,a))){if(b){if(b.animated)return;x=b.getBoundingClientRect()}f.appendChild(o),this._animate(d,o),b&&this._animate(x,b)}else if(b&&!b.animated&&b!==o&&void 0!==b.parentNode[z]){u!==b&&(u=b,v=h(b));var p,x=b.getBoundingClientRect(),y=x.right-x.left,A=x.bottom-x.top,B=/left|right|inline/.test(v.cssFloat+v.display),C=b.offsetWidth>o.offsetWidth,D=b.offsetHeight>o.offsetHeight,F=(B?(a.clientX-x.left)/y:(a.clientY-x.top)/A)>.5,G=b.nextElementSibling;E=!0,setTimeout(k,30),p=B?b.previousElementSibling===o&&!C||F&&C:G!==o&&!D||F&&D,p&&!G?f.appendChild(o):b.parentNode.insertBefore(o,p?G:b),this._animate(d,o),this._animate(x,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){if(clearInterval(this._loopId),f(B,"drop",this._onDrop),f(B,"dragover",d),f(this.el,"dragend",this._onDrop),f(this.el,"dragstart",this._onDragStart),f(this.el,"selectstart",this._onTapStart),this._offUpEvents(),a){if(a.preventDefault(),a.stopPropagation(),q&&q.parentNode.removeChild(q),o){var b=n(o);j(o),g(o,this.options.ghostClass,!1),s.contains(o)?o.nextSibling!==t&&(F(o,"update",void 0,void 0,p,b),F(o,"sort",void 0,void 0,p,b),r&&r.parentNode.removeChild(r)):(F(o,"sort",o,o.parentNode,p,b),F(s,"sort",o,void 0,p,b),F(o,"add",o,s,p,b),F(s,"remove",o,void 0,p,b)),F(s,"end",void 0,void 0,p,b)}s=o=q=t=r=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)},option:function(a,b){var c=this.options;return void 0===b?c[a]:void(c[a]=b)},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")}),J.splice(J.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:F,index:n},a.version="0.7.2",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,disabled:!1,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)}),J.forEach(function(d){c[d]=b(this,c[d]||K),e(a,d.substr(2).toLowerCase(),c[d])},this),a[C]=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),G&&e(a,"selectstart",this._onTapStart),e(a,"dragover",this._onDragOver),e(a,"dragenter",this._onDragOver),N.push(this._onDragOver),c.store&&this.sort(c.store.get(this))}function b(a,b){var c=M.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(M.call(arguments)))}}function c(a,b,c){if("*"===b)return a;if(a){c=c||E,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 E.defaultView&&E.defaultView.getComputedStyle?c=E.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(){H=!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){for(var b=0;a&&(a=a.previousElementSibling);)b++;return b}function o(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 p,q,r,s,t,u,v,w,x,y,z,A,B={},C="Sortable"+(new Date).getTime(),D=window,E=D.document,F=D.parseInt,G=!!E.createElement("div").dragDrop,H=!1,I=function(a,b,c,d,e,f){var g=E.createEvent("Event");g.initEvent(b,!0,!0),g.item=c||a,g.from=d||a,g.oldIndex=e,g.newIndex=f,a.dispatchEvent(g)},J="onAdd onUpdate onRemove onStart onEnd onFilter onSort".split(" "),K=function(){},L=Math.abs,M=[].slice,N=[];return a.prototype={constructor:a,_applyEffects:function(){g(p,this.options.ghostClass,!0)},_onTapStart:function(a){var b=a.touches&&a.touches[0],d=(b||a).target,f=d,g=this.options,k=this.el,l=g.filter;if(!("mousedown"===a.type&&0!==a.button||g.disabled)){if(g.handle&&(d=c(d,g.handle,k)),d=c(d,g.draggable,k),q=n(d),"function"==typeof l){if(l.call(this,a,d,this))return I(f,"filter",d,k,q),void 0}else if(l&&(l=l.split(",").some(function(a){return a=c(f,a.trim(),k),a?(I(a,"filter",d,k,q),!0):void 0}),l.length))return;if(d&&"selectstart"==a.type&&"A"!=d.tagName&&"IMG"!=d.tagName&&d.dragDrop(),d&&!p&&d.parentNode===k){z=a,t=this.el,p=d,v=p.nextSibling,y=this.options.group,p.draggable=!0,g.ignore.split(",").forEach(function(a){i(d,a.trim(),j)}),b&&(z={target:d,clientX:b.clientX,clientY:b.clientY},this._onDragStart(z,!0),a.preventDefault()),e(E,"mouseup",this._onDrop),e(E,"touchend",this._onDrop),e(E,"touchcancel",this._onDrop),e(t,"dragstart",this._onDragStart),e(t,"dragend",this._onDrop),e(E,"dragover",this);try{E.selection?E.selection.empty():window.getSelection().removeAllRanges()}catch(m){}I(t,"start",p,t,q),"clone"==y.pull&&(s=p.cloneNode(!0),h(s,"display","none"),t.insertBefore(s,p))}}},_emulateDragOver:function(){if(A){h(r,"display","none");var a=E.elementFromPoint(A.clientX,A.clientY),b=a,c=this.options.group.name,d=N.length;if(b)do{if(b[C]===c){for(;d--;)N[d]({clientX:A.clientX,clientY:A.clientY,target:a,rootEl:b});break}a=b}while(b=b.parentNode);h(r,"display","")}},_onTouchMove:function(a){if(z){var b=a.touches[0],c=b.clientX-z.clientX,d=b.clientY-z.clientY,e="translate3d("+c+"px,"+d+"px,0)";A=b,h(r,"webkitTransform",e),h(r,"mozTransform",e),h(r,"msTransform",e),h(r,"transform",e),this._onDrag(b),a.preventDefault()}},_onDragStart:function(a,b){var c=a.dataTransfer,d=this.options;if(this._offUpEvents(),b){var f,g=p.getBoundingClientRect(),i=h(p);r=p.cloneNode(!0),h(r,"top",g.top-F(i.marginTop,10)),h(r,"left",g.left-F(i.marginLeft,10)),h(r,"width",g.width),h(r,"height",g.height),h(r,"opacity","0.8"),h(r,"position","fixed"),h(r,"zIndex","100000"),t.appendChild(r),f=r.getBoundingClientRect(),h(r,"width",2*g.width-f.width),h(r,"height",2*g.height-f.height),e(E,"touchmove",this._onTouchMove),e(E,"touchend",this._onDrop),e(E,"touchcancel",this._onDrop),this._loopId=setInterval(this._emulateDragOver,150)}else c.effectAllowed="move",d.setData&&d.setData.call(this,c,p),e(E,"drop",this);if(setTimeout(this._applyEffects,0),u=d.scroll,u===!0){u=t;do if(u.offsetWidth=i-g)-(e>=g),l=(e>=j-h)-(e>=h);k||l?b=D:u&&(b=u,c=u.getBoundingClientRect(),k=(L(c.right-g)<=e)-(L(c.left-g)<=e),l=(L(c.bottom-h)<=e)-(L(c.top-h)<=e)),(B.vx!==k||B.vy!==l||B.el!==b)&&(B.el=b,B.vx=k,B.vy=l,clearInterval(B.pid),b&&(B.pid=setInterval(function(){b===D?D.scrollTo(D.scrollX+k*f,D.scrollY+l*f):(l&&(b.scrollTop+=l*f),k&&(b.scrollLeft+=k*f))},24)))}},30),_onDragOver:function(a){var b,d,e,f=this.el,g=this.options,i=g.group,j=i.put,m=y===i,n=g.sort;if(!H&&(m?n||(e=!t.contains(p)):y.pull&&j&&(y.name===i.name||j.indexOf&&~j.indexOf(y.name)))&&(void 0===a.rootEl||a.rootEl===this.el)){if(b=c(a.target,g.draggable,f),d=p.getBoundingClientRect(),s&&s.state!==m&&(h(s,"display",m?"none":""),!m&&s.state&&t.insertBefore(s,p),s.state=m),e)return s||v?t.insertBefore(p,s||v):n||t.appendChild(p),void 0;if(0===f.children.length||f.children[0]===r||f===a.target&&(b=l(f,a))){if(b){if(b.animated)return;q=b.getBoundingClientRect()}f.appendChild(p),this._animate(d,p),b&&this._animate(q,b)}else if(b&&!b.animated&&b!==p&&void 0!==b.parentNode[C]){w!==b&&(w=b,x=h(b));var o,q=b.getBoundingClientRect(),u=q.right-q.left,z=q.bottom-q.top,A=/left|right|inline/.test(x.cssFloat+x.display),B=b.offsetWidth>p.offsetWidth,D=b.offsetHeight>p.offsetHeight,E=(A?(a.clientX-q.left)/u:(a.clientY-q.top)/z)>.5,F=b.nextElementSibling;H=!0,setTimeout(k,30),o=A?b.previousElementSibling===p&&!B||E&&B:F!==p&&!D||E&&D,o&&!F?f.appendChild(p):b.parentNode.insertBefore(p,o?F:b),this._animate(d,p),this._animate(q,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(E,"mouseup",this._onDrop),f(E,"touchmove",this._onTouchMove),f(E,"touchend",this._onDrop),f(E,"touchcancel",this._onDrop)},_onDrop:function(a){var b=this.el;if(clearInterval(this._loopId),clearInterval(B.pid),f(E,"drop",this),f(E,"dragover",this),f(b,"dragend",this._onDrop),f(b,"dragstart",this._onDragStart),this._offUpEvents(),a){if(a.preventDefault(),a.stopPropagation(),r&&r.parentNode.removeChild(r),p){var c=n(p);j(p),g(p,this.options.ghostClass,!1),t.contains(p)?p.nextSibling!==v&&(I(t,"update",p,t,q,c),I(t,"sort",p,t,q,c),s&&s.parentNode.removeChild(s)):(I(p.parentNode,"sort",p,t,q,c),I(t,"sort",p,t,q,c),I(p,"add",p,t,q,c),I(t,"remove",p,t,q,c)),I(t,"end",p,t,q,c)}t=p=r=v=s=z=A=w=x=y=null,this.options.store&&this.options.store.set(this)}},handleEvent:function(a){var b=a.type;"dragover"===b?(this._onDrag(a),d(a)):"drop"===b&&this._onDrop(a)},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)},option:function(a,b){var c=this.options;return void 0===b?c[a]:(c[a]=b,void 0)},destroy:function(){var a=this.el,b=this.options;J.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")}),N.splice(N.indexOf(this._onDragOver),1),this._onDrop(),this.el=null}},a.utils={on:e,off:f,css:h,find:i,bind:b,is:function(a,b){return!!c(a,b,a)},throttle:o,closest:c,toggleClass:g,dispatchEvent:I,index:n},a.version="0.7.2",a.create=function(b,c){return new a(b,c)},a}); \ No newline at end of file