diff --git a/package.json b/package.json index b75f909..21a2386 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "name": "Markus Ast", "email": "npm.m@rkusa.st" }, - "version": "0.2.2", + "version": "0.3.0", "homepage": "http://ma.rkusa.st/touch-dnd/", "devDependencies": { "uglify-js": "2.x.x" diff --git a/touch-dnd.min.js b/touch-dnd.min.js index a42de37..eb04bd6 100644 --- a/touch-dnd.min.js +++ b/touch-dnd.min.js @@ -1,2 +1,2 @@ -!function($){var START_EVENT="mousedown touchstart MSPointerDown pointerdown",END_EVENT="mouseup touchend MSPointerUp pointerup";function translate(el,x,y){vendorify("transform",el,"translate("+x+"px, "+y+"px)")}function transition(el,val){vendorify("transition",el,val)}function vendorify(property,el,val){property=property.toLowerCase();var titleCased=property.charAt(0).toUpperCase()+property.substr(1);var vendorPrefixes=["webkit","Moz","ms","O"];var properties=vendorPrefixes.map(function(prefix){return prefix+titleCased}).concat("transform");for(var i=0,len=properties.length;i");this.parent=this.el=this.handle=null;this.origin={x:0,y:0,transition:null,translate:null,offset:{x:0,y:0}};this.lastEntered=this.currentTarget=null;this.lastX=this.lastY=this.lastDirection=null;var placeholder;Object.defineProperty(this,"placeholder",{get:function(){return placeholder},set:function(val){if(placeholder===val)return;if(placeholder)placeholder.remove();placeholder=val}})};Dragging.prototype.on=function(){this.eventHandler.on.apply(this.eventHandler,Array.prototype.slice.call(arguments));return this};Dragging.prototype.off=function(){this.eventHandler.off.apply(this.eventHandler,Array.prototype.slice.call(arguments));return this};Dragging.prototype.start=function(parent,el,e,handle){this.parent=parent;this.el=el;this.handle=handle;var el=this.handle||this.el;el.css("-ms-touch-action","none").css("touch-action","none");this.origin.x=window.event&&window.event.changedTouches&&event.changedTouches[0].pageX||e.pageX;this.origin.y=window.event&&window.event.changedTouches&&event.changedTouches[0].pageY||e.pageY;this.origin.transform=vendorify("transform",this.el[0]);this.origin.transition=vendorify("transition",this.el[0]);var rect=this.el[0].getBoundingClientRect();this.origin.offset.x=rect.left-this.origin.x;this.origin.offset.y=rect.top-this.origin.y;el[0].style.pointerEvents="none";$(document).on("mousemove touchmove MSPointerMove pointermove",$.proxy(this.move,this));transition(el[0],"");this.eventHandler.trigger("dragging:start");return this.el};Dragging.prototype.stop=function(e,revert){if(this.last){var last=this.last;this.last=null;$(last).trigger("dragging:drop",e)}if(!this.el)return;var el=this.handle||this.el;if(revert===undefined)revert=true;if(revert){transition(el[0],"all 0.5s ease-in-out 0s");setTimeout(vendorify.bind(null,"transition",el[0],this.origin.transition),500)}vendorify("transform",el[0],this.origin.transform||"translate(0, 0)");el[0].style.pointerEvents="auto";$(document).off("mousemove touchmove MSPointerMove pointermove",this.move);this.eventHandler.trigger("dragging:stop");if(this.handle)setTimeout(this.handle.remove.bind(this.handle),500);this.parent=this.el=this.placeholder=this.handle=null};Dragging.prototype.move=function(e){if(!this.el)return;var clientX=e.clientX||window.event.touches[0].clientX,clientY=e.clientY||window.event.touches[0].clientY;var over=document.elementFromPoint(clientX,clientY);var deltaX=this.lastX-clientX,deltaY=this.lastY-clientY,direction=Math.abs(deltaX)>Math.abs(deltaY)&&deltaX>0&&"left"||Math.abs(deltaX)>Math.abs(deltaY)&&deltaX<0&&"right"||Math.abs(deltaY)>Math.abs(deltaX)&&deltaY>0&&"up"||"down";if(over!==this.last&&$(over).trigger("dragging:identify")&&this.lastEntered!==this.currentTarget){$(this.currentTarget).trigger("dragging:enter");$(this.lastEntered).trigger("dragging:leave");this.lastEntered=this.currentTarget}else if(direction!==this.lastDirection){if(!this.currentTarget)$(over).trigger("dragging:identify");$(this.currentTarget).trigger("dragging:diverted")}this.last=over;this.currentTarget=null;this.lastDirection=direction;this.lastX=clientX;this.lastY=clientY;var deltaX=(window.event&&window.event.changedTouches&&event.changedTouches[0].pageX||e.pageX)-this.origin.x,deltaY=(window.event&&window.event.changedTouches&&event.changedTouches[0].pageY||e.pageY)-this.origin.y;var el=this.handle||this.el;translate(el[0],deltaX,deltaY)};Dragging.prototype.setCurrent=function(target){this.currentTarget=target};var dragging=$.dragging=parent.$.dragging||new Dragging;var MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;var Observer=function(target,selector,onAdded,onRemoved){var self=this;this.target=target;var childsOnly=selector[0]===">",search=childsOnly?selector.substr(1):selector;function apply(nodes,callback){Array.prototype.slice.call(nodes).forEach(function(node){if(childsOnly&&self.target[0]!==$(node).parent()[0])return;if($(node).is(search))callback.call(node);if(childsOnly)return;$(selector,node).each(function(){callback.call(this)})})}this.observer=new MutationObserver(function(mutations){self.disconnect();mutations.forEach(function(mutation){if(onAdded)apply(mutation.addedNodes,onAdded);if(onRemoved)apply(mutation.removedNodes,onRemoved)});self.observe()});$(selector,target).each(function(){onAdded.call(this)});this.observe()};Observer.prototype.disconnect=function(){this.observer.disconnect()};Observer.prototype.observe=function(){this.observer.observe(this.target[0],{childList:true,subtree:true})};var Draggable=function(element,opts){this.id=nextId++;this.el=$(element);this.opts=opts;this.cancel=opts.handle!==false;this.connectedWith=[];if(this.opts.connectWith){this.connectWith(this.opts.connectWith)}};Draggable.prototype.connectWith=function(connectWith){var self=this;$(connectWith).each(function(){var el=$(this);if(el[0]===self.el[0])return;var instance=el.data("sortable")||el.data("droppable");if(instance)instance.connectedWith.push(self.id);else{el.one("sortable:create droppable:create",function(e,instance){instance.connectedWith.push(self.id)})}})};Draggable.prototype.create=function(){this.el.on(START_EVENT,$.proxy(this.start,this));var self=this;setTimeout(function(){self.el.trigger("draggable:create",self)})};Draggable.prototype.destroy=function(){this.el.off(START_EVENT,this.start)};Draggable.prototype.enable=function(){this.opts.disabled=false};Draggable.prototype.disable=function(){this.opts.disabled=true};Draggable.prototype.start=function(e){if(this.opts.disabled)return false;e=e.originalEvent||e;e.preventDefault();if(this.opts.cancel){var target=$(e.target);while(target[0]!==this.el[0]){if(target.is(this.opts.cancel))return false;target=target.parent()}}if(this.opts.handle){var target=$(e.target),isHandle=false;while(target[0]!==this.el[0]){if(target.is(this.opts.handle)){isHandle=true;break}target=target.parent()}if(!isHandle)return false}var el=this.el,handle;if(this.opts.clone){el=this.el.clone();handle=this.el.clone();var position=this.el.position();handle.css("position","absolute").css("left",position.left).css("top",position.top).width(this.el.width()).height(this.el.height());handle.insertAfter(this.el)}dragging.start(this,el,e,handle);$(document).on(END_EVENT,$.proxy(this.end,this))};Draggable.prototype.end=function(e){$(document).off(END_EVENT,this.end);dragging.stop(e)};var Droppable=function(element,opts){this.id=nextId++;this.el=$(element);this.opts=opts;this.accept=false;this.connectedWith=[]};Droppable.prototype.create=function(){this.el.on("dragging:enter",$.proxy(this.enter,this)).on("dragging:leave",$.proxy(this.leave,this)).on("dragging:drop",$.proxy(this.drop,this));dragging.on("dragging:start",$.proxy(this.activate,this)).on("dragging:stop",$.proxy(this.reset,this));var self=this;setTimeout(function(){self.el.trigger("droppable:create",self)})};Droppable.prototype.destroy=function(){this.el.off("dragging:enter",this.enter).off("dragging:leave",this.leave).off("dragging:drop",this.drop)};Droppable.prototype.enable=function(){this.opts.disabled=false};Droppable.prototype.disable=function(){this.opts.disabled=true};Droppable.prototype.activate=function(e){this.accept=this.connectedWith.indexOf(dragging.parent.id)!==-1;if(!this.accept){var accept=this.opts.accept==="*"||(typeof this.opts.accept==="function"?this.opts.accept.call(this.el[0],dragging.el):dragging.el.is(this.opts.accept));if(this.opts.scope!=="default"){this.accept=dragging.parent.opts.scope===this.opts.scope;if(!this.accept&&this.opts.accept!=="*")this.accept=accept}else this.accept=accept}if(!this.accept)return;if(this.opts.activeClass)this.el.addClass(this.opts.activeClass);this.el.trigger("droppable:activate",{item:dragging.el})};Droppable.prototype.reset=function(e){if(!this.accept)return;if(this.opts.activeClass)this.el.removeClass(this.opts.activeClass);if(this.opts.hoverClass)this.el.removeClass(this.opts.hoverClass);this.el.trigger("droppable:deactivate",{item:dragging.el})};Droppable.prototype.enter=function(e){if(this.opts.disabled)return false;e.stopPropagation();if(dragging.placeholder)dragging.placeholder.hide();if(!this.accept)return;if(this.opts.hoverClass)this.el.addClass(this.opts.hoverClass);this.el.trigger("droppable:over",{item:dragging.el})};Droppable.prototype.leave=function(e){if(this.opts.disabled)return false;if(this.opts.hoverClass&&this.accept)this.el.removeClass(this.opts.hoverClass);this.el.trigger("droppable:out",{item:dragging.el})};Droppable.prototype.drop=function(e,originalEvent){if(this.opts.disabled||!this.accept)return false;if(!dragging.el)return;var el=dragging.el;dragging.stop(originalEvent,false);$(this.el).append(el);this.el.trigger("droppable:drop",{item:el})};var Sortable=function(element,opts){this.id=nextId++;this.el=element;this.opts=opts;var tag;try{tag=this.el.find(this.opts.items)[0].tagName}catch(e){tag=/^ul|ol$/i.test(this.el.tagName)?"li":"div"}this.placeholder=$("<"+tag+' class="'+this.opts.placeholder+'" />');this.accept=this.index=this.direction=null;this.connectedWith=[];if(this.opts.connectWith){this.connectWith(this.opts.connectWith)}};Sortable.prototype.connectWith=Draggable.prototype.connectWith;Sortable.prototype.create=function(){this.el.on(START_EVENT,this.opts.items,$.proxy(this.start,this)).on("dragging:identify",this.opts.items,$.proxy(this.identify,this)).on("dragging:enter",this.opts.items,$.proxy(this.enter,this)).on("dragging:diverted",this.opts.items,$.proxy(this.diverted,this)).on("dragging:drop",this.opts.items,$.proxy(this.drop,this));this.el.on("dragging:identify",$.proxy(this.identify,this)).on("dragging:enter",$.proxy(this.enter,this)).on("dragging:diverted",$.proxy(this.diverted,this)).on("dragging:drop",$.proxy(this.drop,this));dragging.on("dragging:start",$.proxy(this.activate,this)).on("dragging:stop",$.proxy(this.reset,this));var self=this;setTimeout(function(){self.el.trigger("sortable:create",self)});this.observer=new Observer(this.el,this.opts.items,function(){},function(){if(this===self.placeholder[0]||dragging.el&&this===dragging.el[0])return;var item=$(this);self.el.trigger("sortable:change",{item:item});self.el.trigger("sortable:update",{item:item,index:-1})})};Sortable.prototype.destroy=function(){this.el.off(START_EVENT,this.opts.items,this.start).off("dragging:identify",this.opts.items,this.identify).off("dragging:enter",this.opts.items,this.enter).off("dragging:diverted",this.opts.items,this.diverted).off("dragging:drop",this.opts.items,this.drop);this.el.off("dragging:identify",this.identify).off("dragging:enter",this.enter).off("dragging:diverted",this.diverted).off("dragging:drop",this.drop);this.observer.disconnect()};Sortable.prototype.enable=function(){this.opts.disabled=false};Sortable.prototype.disable=function(){this.opts.disabled=true};Sortable.prototype.activate=function(e){this.accept=dragging.parent.id===this.id||!!~this.connectedWith.indexOf(dragging.parent.id);this.isEmpty=this.el.find(this.opts.items).length===0;if(!this.accept)return;this.accept=dragging.parent.id===this.id||this.opts.accept==="*"||(typeof this.opts.accept==="function"?this.opts.accept.call(this.el[0],dragging.el):dragging.el.is(this.opts.accept));if(!this.accept)return;if(this.opts.activeClass)this.el.addClass(this.opts.activeClass);this.el.trigger("sortable:activate",dragging.el)};Sortable.prototype.reset=function(e){if(!this.accept)return;if(this.opts.activeClass)this.el.removeClass(this.opts.activeClass);this.el.trigger("sortable:deactivate",dragging.el)};Sortable.prototype.start=function(e){if(this.opts.disabled)return;if(this.opts.cancel){var target=$(e.target);while(target[0]!==this.el[0]){if(target.is(this.opts.cancel))return;target=target.parent()}}if(this.opts.handle){var target=$(e.target),isHandle=false;while(target[0]!==this.el[0]){if(target.is(this.opts.handle)){isHandle=true;break}target=target.parent()}if(!isHandle)return}e.stopPropagation();e.preventDefault();dragging.start(this,$(e.currentTarget),e);$(document).on(END_EVENT,$.proxy(this.end,this));this.index=dragging.el.index();if(this.opts.forcePlaceholderSize){this.placeholder.height(dragging.el.height());this.placeholder.width(dragging.el.width())}this.el.trigger("sortable:start",{item:dragging.el})};Sortable.prototype.identify=function(e){if(dragging.currentTarget)return;dragging.setCurrent(e.currentTarget)};Sortable.prototype.enter=function(e){if(!this.accept||this.opts.disabled)return;e.stopPropagation();var child=e.currentTarget,isContainer=child===this.el[0];if(child===this.placeholder[0])return;child=$(child);if(isContainer&&!this.isEmpty&&this.placeholder.parent().length)return;if(this.opts.forcePlaceholderSize){this.placeholder.height(dragging.el.height())}var initialized=true;if(!this.placeholder.parent().length){initialized=false;this.el.append(dragging.placeholder=this.placeholder);if(this.index!==null){this.el.append(dragging.el)}}if(!isContainer){this.direction=this.placeholder.show().index()");this.parent=this.el=this.handle=null;this.origin={x:0,y:0,transition:null,translate:null,offset:{x:0,y:0}};this.lastEntered=this.currentTarget=null;this.lastX=this.lastY=this.lastDirection=null;var placeholder;Object.defineProperty(this,"placeholder",{get:function(){return placeholder},set:function(val){if(placeholder===val)return;if(placeholder)placeholder.remove();placeholder=val}})};Dragging.prototype.on=function(){this.eventHandler.on.apply(this.eventHandler,Array.prototype.slice.call(arguments));return this};Dragging.prototype.off=function(){this.eventHandler.off.apply(this.eventHandler,Array.prototype.slice.call(arguments));return this};Dragging.prototype.start=function(parent,el,e,handle){this.parent=parent;this.el=el;this.handle=handle;var el=this.handle||this.el;el.css("-ms-touch-action","none").css("touch-action","none");this.origin.x=window.event&&window.event.changedTouches&&event.changedTouches[0].pageX||e.pageX;this.origin.y=window.event&&window.event.changedTouches&&event.changedTouches[0].pageY||e.pageY;this.origin.transform=vendorify("transform",this.el[0]);this.origin.transition=vendorify("transition",this.el[0]);var rect=this.el[0].getBoundingClientRect();this.origin.offset.x=rect.left-this.origin.x;this.origin.offset.y=rect.top-this.origin.y;el[0].style.pointerEvents="none";$(document).on("mousemove touchmove MSPointerMove pointermove",$.proxy(this.move,this));transition(el[0],"");this.eventHandler.trigger("dragging:start");return this.el};Dragging.prototype.stop=function(e,revert){if(this.last){var last=this.last;this.last=null;$(last).trigger("dragging:drop",e)}if(!this.el)return;var transform=this.origin.transform||"translate(0, 0)";var el=this.handle||this.el,self=this;if(revert===undefined)revert=true;if(this.handle){transition(this.handle[0],"all 0.5s ease-in-out 0s");if(revert){vendorify("transform",this.handle[0],transform);setTimeout(this.handle.remove.bind(this.handle),500)}else{this.handle.remove()}}else{if(revert){transition(this.el[0],"all 0.5s ease-in-out 0s");setTimeout(vendorify.bind(null,"transition",this.el[0],this.origin.transition),500)}vendorify("transform",this.el[0],transform);this.el[0].style.pointerEvents="auto"}$(document).off("mousemove touchmove MSPointerMove pointermove",this.move);this.eventHandler.trigger("dragging:stop");this.parent=this.el=this.placeholder=this.handle=null};Dragging.prototype.move=function(e){if(!this.el)return;var clientX=e.clientX||window.event.touches[0].clientX,clientY=e.clientY||window.event.touches[0].clientY;var over=document.elementFromPoint(clientX,clientY);var deltaX=this.lastX-clientX,deltaY=this.lastY-clientY,direction=Math.abs(deltaX)>Math.abs(deltaY)&&deltaX>0&&"left"||Math.abs(deltaX)>Math.abs(deltaY)&&deltaX<0&&"right"||Math.abs(deltaY)>Math.abs(deltaX)&&deltaY>0&&"up"||"down";if(over!==this.last&&$(over).trigger("dragging:identify")&&this.lastEntered!==this.currentTarget){$(this.currentTarget).trigger("dragging:enter");$(this.lastEntered).trigger("dragging:leave");this.lastEntered=this.currentTarget}else if(direction!==this.lastDirection){if(!this.currentTarget)$(over).trigger("dragging:identify");$(this.currentTarget).trigger("dragging:diverted")}this.last=over;this.currentTarget=null;this.lastDirection=direction;this.lastX=clientX;this.lastY=clientY;var deltaX=(window.event&&window.event.changedTouches&&event.changedTouches[0].pageX||e.pageX)-this.origin.x,deltaY=(window.event&&window.event.changedTouches&&event.changedTouches[0].pageY||e.pageY)-this.origin.y;var el=this.handle||this.el;translate(el[0],deltaX,deltaY)};Dragging.prototype.setCurrent=function(target){this.currentTarget=target};var dragging=$.dragging=parent.$.dragging||new Dragging;var MutationObserver=window.MutationObserver||window.WebKitMutationObserver||window.MozMutationObserver;var Observer=function(target,selector,onAdded,onRemoved){var self=this;this.target=target;var childsOnly=selector[0]===">",search=childsOnly?selector.substr(1):selector;function apply(nodes,callback){Array.prototype.slice.call(nodes).forEach(function(node){if(childsOnly&&self.target[0]!==$(node).parent()[0])return;if($(node).is(search))callback.call(node);if(childsOnly)return;$(selector,node).each(function(){callback.call(this)})})}this.observer=new MutationObserver(function(mutations){self.disconnect();mutations.forEach(function(mutation){if(onAdded)apply(mutation.addedNodes,onAdded);if(onRemoved)apply(mutation.removedNodes,onRemoved)});self.observe()});$(selector,target).each(function(){onAdded.call(this)});this.observe()};Observer.prototype.disconnect=function(){this.observer.disconnect()};Observer.prototype.observe=function(){this.observer.observe(this.target[0],{childList:true,subtree:true})};var Draggable=function(element,opts){this.id=nextId++;this.el=$(element);this.opts=opts;this.cancel=opts.handle!==false;this.connectedWith=[];if(this.opts.connectWith){this.connectWith(this.opts.connectWith)}};Draggable.prototype.connectWith=function(connectWith){var self=this;$(connectWith).each(function(){var el=$(this);if(el[0]===self.el[0])return;var instance=el.data("sortable")||el.data("droppable");if(instance)instance.connectedWith.push(self.id);else{el.one("sortable:create droppable:create",function(e,instance){instance.connectedWith.push(self.id)})}})};Draggable.prototype.create=function(){this.el.on(START_EVENT,$.proxy(this.start,this));var self=this;setTimeout(function(){self.el.trigger("draggable:create",self)})};Draggable.prototype.destroy=function(){this.el.off(START_EVENT,this.start)};Draggable.prototype.enable=function(){this.opts.disabled=false};Draggable.prototype.disable=function(){this.opts.disabled=true};Draggable.prototype.start=function(e){if(this.opts.disabled)return false;e=e.originalEvent||e;e.preventDefault();if(this.opts.cancel){var target=$(e.target);while(target[0]!==this.el[0]){if(target.is(this.opts.cancel))return false;target=target.parent()}}if(this.opts.handle){var target=$(e.target),isHandle=false;while(target[0]!==this.el[0]){if(target.is(this.opts.handle)){isHandle=true;break}target=target.parent()}if(!isHandle)return false}var el=this.el,handle;if(this.opts.clone){el=this.el.clone();handle=this.el.clone();var position=this.el.position();handle.css("position","absolute").css("left",position.left).css("top",position.top).width(this.el.width()).height(this.el.height());handle.insertAfter(this.el)}dragging.start(this,el,e,handle);$(document).on(END_EVENT,$.proxy(this.end,this))};Draggable.prototype.end=function(e){$(document).off(END_EVENT,this.end);dragging.stop(e)};var Droppable=function(element,opts){this.id=nextId++;this.el=$(element);this.opts=opts;this.accept=false;this.connectedWith=[]};Droppable.prototype.create=function(){this.el.on("dragging:enter",$.proxy(this.enter,this)).on("dragging:leave",$.proxy(this.leave,this)).on("dragging:drop",$.proxy(this.drop,this));dragging.on("dragging:start",$.proxy(this.activate,this)).on("dragging:stop",$.proxy(this.reset,this));var self=this;setTimeout(function(){self.el.trigger("droppable:create",self)})};Droppable.prototype.destroy=function(){this.el.off("dragging:enter",this.enter).off("dragging:leave",this.leave).off("dragging:drop",this.drop)};Droppable.prototype.enable=function(){this.opts.disabled=false};Droppable.prototype.disable=function(){this.opts.disabled=true};Droppable.prototype.activate=function(e){this.accept=this.connectedWith.indexOf(dragging.parent.id)!==-1;if(!this.accept){var accept=this.opts.accept==="*"||(typeof this.opts.accept==="function"?this.opts.accept.call(this.el[0],dragging.el):dragging.el.is(this.opts.accept));if(this.opts.scope!=="default"){this.accept=dragging.parent.opts.scope===this.opts.scope;if(!this.accept&&this.opts.accept!=="*")this.accept=accept}else this.accept=accept}if(!this.accept)return;if(this.opts.activeClass)this.el.addClass(this.opts.activeClass);this.el.trigger("droppable:activate",{item:dragging.el})};Droppable.prototype.reset=function(e){if(!this.accept)return;if(this.opts.activeClass)this.el.removeClass(this.opts.activeClass);if(this.opts.hoverClass)this.el.removeClass(this.opts.hoverClass);this.el.trigger("droppable:deactivate",{item:dragging.el})};Droppable.prototype.enter=function(e){if(this.opts.disabled)return false;e.stopPropagation();if(dragging.placeholder)dragging.placeholder.hide();if(!this.accept)return;if(this.opts.hoverClass)this.el.addClass(this.opts.hoverClass);this.el.trigger("droppable:over",{item:dragging.el})};Droppable.prototype.leave=function(e){if(this.opts.disabled)return false;if(this.opts.hoverClass&&this.accept)this.el.removeClass(this.opts.hoverClass);this.el.trigger("droppable:out",{item:dragging.el})};Droppable.prototype.drop=function(e,originalEvent){if(this.opts.disabled||!this.accept)return false;if(!dragging.el)return;var el=dragging.el;dragging.stop(originalEvent,false);$(this.el).append(el);this.el.trigger("droppable:drop",{item:el})};var Sortable=function(element,opts){this.id=nextId++;this.el=element;this.opts=opts;var tag;try{tag=this.el.find(this.opts.items)[0].tagName}catch(e){tag=/^ul|ol$/i.test(this.el.tagName)?"li":"div"}this.placeholder=$("<"+tag+' class="'+this.opts.placeholder+'" />');this.accept=this.index=this.direction=null;this.connectedWith=[];if(this.opts.connectWith){this.connectWith(this.opts.connectWith)}};Sortable.prototype.connectWith=Draggable.prototype.connectWith;Sortable.prototype.create=function(){this.el.on(START_EVENT,this.opts.items,$.proxy(this.start,this)).on("dragging:identify",this.opts.items,$.proxy(this.identify,this)).on("dragging:enter",this.opts.items,$.proxy(this.enter,this)).on("dragging:diverted",this.opts.items,$.proxy(this.diverted,this)).on("dragging:drop",this.opts.items,$.proxy(this.drop,this));this.el.on("dragging:identify",$.proxy(this.identify,this)).on("dragging:enter",$.proxy(this.enter,this)).on("dragging:diverted",$.proxy(this.diverted,this)).on("dragging:drop",$.proxy(this.drop,this));dragging.on("dragging:start",$.proxy(this.activate,this)).on("dragging:stop",$.proxy(this.reset,this));var self=this;setTimeout(function(){self.el.trigger("sortable:create",self)});this.observer=new Observer(this.el,this.opts.items,function(){},function(){if(this===self.placeholder[0]||dragging.el&&this===dragging.el[0])return;var item=$(this);self.el.trigger("sortable:change",{item:item});self.el.trigger("sortable:update",{item:item,index:-1})})};Sortable.prototype.destroy=function(){this.el.off(START_EVENT,this.opts.items,this.start).off("dragging:identify",this.opts.items,this.identify).off("dragging:enter",this.opts.items,this.enter).off("dragging:diverted",this.opts.items,this.diverted).off("dragging:drop",this.opts.items,this.drop);this.el.off("dragging:identify",this.identify).off("dragging:enter",this.enter).off("dragging:diverted",this.diverted).off("dragging:drop",this.drop);this.observer.disconnect()};Sortable.prototype.enable=function(){this.opts.disabled=false};Sortable.prototype.disable=function(){this.opts.disabled=true};Sortable.prototype.activate=function(e){this.accept=dragging.parent.id===this.id||!!~this.connectedWith.indexOf(dragging.parent.id);this.isEmpty=this.el.find(this.opts.items).length===0;if(!this.accept)return;this.accept=dragging.parent.id===this.id||this.opts.accept==="*"||(typeof this.opts.accept==="function"?this.opts.accept.call(this.el[0],dragging.el):dragging.el.is(this.opts.accept));if(!this.accept)return;if(this.opts.activeClass)this.el.addClass(this.opts.activeClass);this.el.trigger("sortable:activate",dragging.el)};Sortable.prototype.reset=function(e){if(!this.accept)return;if(this.opts.activeClass)this.el.removeClass(this.opts.activeClass);this.el.trigger("sortable:deactivate",dragging.el)};Sortable.prototype.start=function(e){if(this.opts.disabled)return;if(this.opts.cancel){var target=$(e.target);while(target[0]!==this.el[0]){if(target.is(this.opts.cancel))return;target=target.parent()}}if(this.opts.handle){var target=$(e.target),isHandle=false;while(target[0]!==this.el[0]){if(target.is(this.opts.handle)){isHandle=true;break}target=target.parent()}if(!isHandle)return}e.stopPropagation();e.preventDefault();dragging.start(this,$(e.currentTarget),e);$(document).on(END_EVENT,$.proxy(this.end,this));this.index=dragging.el.index();if(this.opts.forcePlaceholderSize){this.placeholder.height(dragging.el.height());this.placeholder.width(dragging.el.width())}this.el.trigger("sortable:start",{item:dragging.el})};Sortable.prototype.identify=function(e){if(dragging.currentTarget)return;dragging.setCurrent(e.currentTarget)};Sortable.prototype.enter=function(e){if(!this.accept||this.opts.disabled)return;e.stopPropagation();var child=e.currentTarget,isContainer=child===this.el[0];if(child===this.placeholder[0])return;child=$(child);if(isContainer&&!this.isEmpty&&this.placeholder.parent().length)return;if(this.opts.forcePlaceholderSize){this.placeholder.height(dragging.el.height())}var initialized=true;if(!this.placeholder.parent().length){initialized=false;this.el.append(dragging.placeholder=this.placeholder);if(this.index!==null){this.el.append(dragging.el)}}if(!isContainer){this.direction=this.placeholder.show().index()