diff --git a/Sortable.js b/Sortable.js index 246b1e7..ccfe920 100644 --- a/Sortable.js +++ b/Sortable.js @@ -36,7 +36,18 @@ , win = window , document = win.document , parseInt = win.parseInt - , Event = win.CustomEvent + + , Event = (function (){ + function CustomEvent(event, params){ + var evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); + return evt; + } + + CustomEvent.prototype = win.CustomEvent.prototype; + + return CustomEvent; + })() , noop = function (){} , slice = [].slice diff --git a/Sortable.min.js b/Sortable.min.js index 7d3fda7..24fd87b 100644 --- a/Sortable.min.js +++ b/Sortable.min.js @@ -1,2 +1,2 @@ /*! Sortable 0.1.0 - MIT | git://github.com/rubaxa/Sortable.git */ -!function(a){"use strict";"function"==typeof define&&define.amd?define("Sortable",[],a):window.Sortable=a()}(function(){"use strict";function a(a,c){this.el=a,this.options=c=c||{},c.group=c.group||Math.random(),c.handle=c.handle||null,c.draggable=c.draggable||a.children[0]&&a.children[0].nodeName||"li",c.ghostClass=c.ghostClass||"sortable-ghost",c.onAdd=b(this,c.onAdd||y),c.onUpdate=b(this,c.onUpdate||y),c.onRemove=b(this,c.onRemove||y),a[t]=c.group;for(var d in this)"_"===d.charAt(0)&&(this[d]=b(this,this[d]));e(a,"add",c.onAdd),e(a,"update",c.onUpdate),e(a,"remove",c.onRemove),e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this._onDragOver),e(a,"dragenter",this._onDragOver),A.push(this._onDragOver)}function b(a,b){var c=z.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(z.call(arguments)))}}function c(a,b,c){if(a&&c){c=c||v,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\b("+b.join("|")+")\\b","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){if(a&&a.style){if(void 0===c)return v.defaultView&&v.defaultView.getComputedStyle?c=v.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];a.style[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){return a.draggable=!1}var k,l,m,n,o,p,q,r,s,t="Sortable"+(new Date).getTime(),u=window,v=u.document,w=u.parseInt,x=u.CustomEvent,y=function(){},z=[].slice,A=[];return a.prototype={constructor:a,_applyEffects:function(){g(k,this.options.ghostClass,!0)},_onTapStart:function(a){var b=a.touches&&a.touches[0],f=(b||a).target,g=this.options;if(g.handle&&(f=c(f,g.handle,this.el)),f=c(f,g.draggable,this.el),f&&!k){r=a,f.draggable=!0,i(f,"a",j),i(f,"img",j),b&&(r={target:f,clientX:b.clientX,clientY:b.clientY},this._onDragStart(r,!0),a.preventDefault()),e(this.el,"dragstart",this._onDragStart),e(this.el,"dragend",this._onDrop),e(v,"dragover",d);try{v.selection?v.selection.empty():window.getSelection().removeAllRanges()}catch(h){}}},_emulateDragOver:function(){if(s){h(l,"display","none");var a=v.elementFromPoint(s.clientX,s.clientY),b=a,c=this.options.group,d=A.length;do if(b[t]===c){for(;d--;)A[d]({clientX:s.clientX,clientY:s.clientY,target:a,rootEl:b});break}while(b=b.parentNode);h(l,"display","")}},_onTouchMove:function(a){if(r){var b=a.touches[0],c=b.clientX-r.clientX,d=b.clientY-r.clientY;s=b,h(l,"webkitTransform","translate3d("+c+"px,"+d+"px,0)")}},_onDragStart:function(a,b){var c=a.target,d=a.dataTransfer;if(m=this.el,k=c,n=c.nextSibling,q=this.options.group,b){var f=c.getBoundingClientRect(),g=h(c);l=c.cloneNode(!0),h(l,"top",f.top-w(g.marginTop,10)),h(l,"left",f.left-w(g.marginLeft,10)),h(l,"width",f.right-f.left),h(l,"height",f.bottom-f.top),h(l,"opacity","0.8"),h(l,"position","fixed"),h(l,"zIndex","100000"),c.parentNode.insertBefore(l,c),e(v,"touchmove",this._onTouchMove),e(v,"touchend",this._onDrop),this._loopId=setInterval(this._emulateDragOver,100)}else d.effectAllowed="move",d.setData("Text",c.textContent),e(v,"drop",this._onDrop);setTimeout(this._applyEffects)},_onDragOver:function(a){if(q===this.options.group&&(void 0===a.rootEl||a.rootEl===this.el)){var b=this.el,d=c(a.target,this.options.draggable,b);if(0===b.children.length)b.appendChild(k);else if(d&&d!==k){o!==d&&(o=d,p=h(d));var e=d.getBoundingClientRect(),f=e.right-e.left,g=e.bottom-e.top,i=/left|right|inline/.test(p.cssFloat+p.display),j=!i&&(a.clientY-e.top)/g>.5||i&&(a.clientX-e.left)/f>.5,l=d.nextSibling;j&&!l?b.appendChild(k):d.parentNode.insertBefore(k,j?l:d)}}},_onDrop:function(a){if(clearInterval(this._loopId),f(v,"drop",this._onDrop),f(v,"dragover",d),f(this.el,"dragend",this._onDrop),f(this.el,"dragstart",this._onDragStart),f(v,"touchmove",this._onTouchMove),f(v,"touchend",this._onDrop),a){if(a.preventDefault(),l&&l.parentNode.removeChild(l),k){var b={bubbles:!0,cancelable:!0,detail:k};g(k,this.options.ghostClass,!1),m.contains(k)?k.nextSibling!==n&&k.dispatchEvent(new x("update",b)):(m.dispatchEvent(new x("remove",b)),k.dispatchEvent(new x("add",b)))}m=k=l=n=r=s=o=p=q=null}},destroy:function(){var a=this.el,b=this.options;f(a,"add",b.onAdd),f(a,"update",b.onUpdate),f(a,"remove",b.onRemove),f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),A.splice(A.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},a.version="0.1.0",a}); \ No newline at end of file +!function(a){"use strict";"function"==typeof define&&define.amd?define("Sortable",[],a):window.Sortable=a()}(function(){"use strict";function a(a,c){this.el=a,this.options=c=c||{},c.group=c.group||Math.random(),c.handle=c.handle||null,c.draggable=c.draggable||a.children[0]&&a.children[0].nodeName||"li",c.ghostClass=c.ghostClass||"sortable-ghost",c.onAdd=b(this,c.onAdd||y),c.onUpdate=b(this,c.onUpdate||y),c.onRemove=b(this,c.onRemove||y),a[t]=c.group;for(var d in this)"_"===d.charAt(0)&&(this[d]=b(this,this[d]));e(a,"add",c.onAdd),e(a,"update",c.onUpdate),e(a,"remove",c.onRemove),e(a,"mousedown",this._onTapStart),e(a,"touchstart",this._onTapStart),e(a,"dragover",this._onDragOver),e(a,"dragenter",this._onDragOver),A.push(this._onDragOver)}function b(a,b){var c=z.call(arguments,2);return b.bind?b.bind.apply(b,[a].concat(c)):function(){return b.apply(a,c.concat(z.call(arguments)))}}function c(a,b,c){if(a&&c){c=c||v,b=b.split(".");var d=b.shift().toUpperCase(),e=new RegExp("\\b("+b.join("|")+")\\b","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){if(a&&a.style){if(void 0===c)return v.defaultView&&v.defaultView.getComputedStyle?c=v.defaultView.getComputedStyle(a,""):a.currentStyle&&(c=a.currentStyle),void 0===b?c:c[b];a.style[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){return a.draggable=!1}var k,l,m,n,o,p,q,r,s,t="Sortable"+(new Date).getTime(),u=window,v=u.document,w=u.parseInt,x=function(){function a(a,b){var c=v.createEvent("CustomEvent");return c.initCustomEvent(a,b.bubbles,b.cancelable,b.detail),c}return a.prototype=u.CustomEvent.prototype,a}(),y=function(){},z=[].slice,A=[];return a.prototype={constructor:a,_applyEffects:function(){g(k,this.options.ghostClass,!0)},_onTapStart:function(a){var b=a.touches&&a.touches[0],f=(b||a).target,g=this.options;if(g.handle&&(f=c(f,g.handle,this.el)),f=c(f,g.draggable,this.el),f&&!k){r=a,f.draggable=!0,i(f,"a",j),i(f,"img",j),b&&(r={target:f,clientX:b.clientX,clientY:b.clientY},this._onDragStart(r,!0),a.preventDefault()),e(this.el,"dragstart",this._onDragStart),e(this.el,"dragend",this._onDrop),e(v,"dragover",d);try{v.selection?v.selection.empty():window.getSelection().removeAllRanges()}catch(h){}}},_emulateDragOver:function(){if(s){h(l,"display","none");var a=v.elementFromPoint(s.clientX,s.clientY),b=a,c=this.options.group,d=A.length;do if(b[t]===c){for(;d--;)A[d]({clientX:s.clientX,clientY:s.clientY,target:a,rootEl:b});break}while(b=b.parentNode);h(l,"display","")}},_onTouchMove:function(a){if(r){var b=a.touches[0],c=b.clientX-r.clientX,d=b.clientY-r.clientY;s=b,h(l,"webkitTransform","translate3d("+c+"px,"+d+"px,0)")}},_onDragStart:function(a,b){var c=a.target,d=a.dataTransfer;if(m=this.el,k=c,n=c.nextSibling,q=this.options.group,b){var f=c.getBoundingClientRect(),g=h(c);l=c.cloneNode(!0),h(l,"top",f.top-w(g.marginTop,10)),h(l,"left",f.left-w(g.marginLeft,10)),h(l,"width",f.right-f.left),h(l,"height",f.bottom-f.top),h(l,"opacity","0.8"),h(l,"position","fixed"),h(l,"zIndex","100000"),c.parentNode.insertBefore(l,c),e(v,"touchmove",this._onTouchMove),e(v,"touchend",this._onDrop),this._loopId=setInterval(this._emulateDragOver,100)}else d.effectAllowed="move",d.setData("Text",c.textContent),e(v,"drop",this._onDrop);setTimeout(this._applyEffects)},_onDragOver:function(a){if(q===this.options.group&&(void 0===a.rootEl||a.rootEl===this.el)){var b=this.el,d=c(a.target,this.options.draggable,b);if(0===b.children.length)b.appendChild(k);else if(d&&d!==k){o!==d&&(o=d,p=h(d));var e=d.getBoundingClientRect(),f=e.right-e.left,g=e.bottom-e.top,i=/left|right|inline/.test(p.cssFloat+p.display),j=!i&&(a.clientY-e.top)/g>.5||i&&(a.clientX-e.left)/f>.5,l=d.nextSibling;j&&!l?b.appendChild(k):d.parentNode.insertBefore(k,j?l:d)}}},_onDrop:function(a){if(clearInterval(this._loopId),f(v,"drop",this._onDrop),f(v,"dragover",d),f(this.el,"dragend",this._onDrop),f(this.el,"dragstart",this._onDragStart),f(v,"touchmove",this._onTouchMove),f(v,"touchend",this._onDrop),a){if(a.preventDefault(),l&&l.parentNode.removeChild(l),k){var b={bubbles:!0,cancelable:!0,detail:k};g(k,this.options.ghostClass,!1),m.contains(k)?k.nextSibling!==n&&k.dispatchEvent(new x("update",b)):(m.dispatchEvent(new x("remove",b)),k.dispatchEvent(new x("add",b)))}m=k=l=n=r=s=o=p=q=null}},destroy:function(){var a=this.el,b=this.options;f(a,"add",b.onAdd),f(a,"update",b.onUpdate),f(a,"remove",b.onRemove),f(a,"mousedown",this._onTapStart),f(a,"touchstart",this._onTapStart),f(a,"dragover",this._onDragOver),f(a,"dragenter",this._onDragOver),A.splice(A.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},a.version="0.1.0",a}); \ No newline at end of file diff --git a/package.json b/package.json index 492f9c1..684e555 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "sortable", "exportName": "Sortable", - "version": "0.1.0", + "version": "0.1.1", "devDependencies": { "grunt": "*", "grunt-version": "*",