!function(){var moduleFactory=function($){var module=this;$.require().script("mvc/event.drag","mvc/dom.within","mvc/dom.compare").done(function(){var exports=function(){var event=$.event,eventNames=["dropover","dropon","dropout","dropinit","dropmove","dropend"];$.Drop=function(callbacks,element){$.extend(this,callbacks),this.element=$(element)},$.each(eventNames,function(){event.special[this]={add:function(){var el=$(this),current=el.data("dropEventCount")||0;el.data("dropEventCount",current+1),0==current&&$.Drop.addElement(this)
},remove:function(){var el=$(this),current=el.data("dropEventCount")||0;el.data("dropEventCount",current-1),1>=current&&$.Drop.removeElement(this)}}}),$.extend($.Drop,{lowerName:"drop",_rootElements:[],_elements:$(),last_active:[],endName:"dropon",addElement:function(el){for(var i=0;i<this._rootElements.length;i++)if(el==this._rootElements[i])return;this._rootElements.push(el)},removeElement:function(el){for(var i=0;i<this._rootElements.length;i++)if(el==this._rootElements[i])return this._rootElements.splice(i,1),void 0
},sortByDeepestChild:function(a,b){var compare=a.element.compare(b.element);return 16&compare||4&compare?1:8&compare||2&compare?-1:0},isAffected:function(point,moveable,responder){return responder.element!=moveable.element&&1==responder.element.within(point[0],point[1],responder._cache).length},deactivate:function(responder,mover,event){mover.out(event,responder),responder.callHandlers(this.lowerName+"out",responder.element[0],event,mover)},activate:function(responder,mover,event){mover.over(event,responder),responder.callHandlers(this.lowerName+"over",responder.element[0],event,mover)
},move:function(responder,mover,event){responder.callHandlers(this.lowerName+"move",responder.element[0],event,mover)},compile:function(event,drag){if(this.dragging||drag){this.dragging||(this.dragging=drag,this.last_active=[]);for(var el,drops,selector,dropResponders,newEls=[],dragging=this.dragging,i=0;i<this._rootElements.length;i++){el=this._rootElements[i];var drops=$.event.findBySelector(el,eventNames);for(selector in drops){dropResponders=selector?$(selector,el):[el];for(var e=0;e<dropResponders.length;e++)this.addCallbacks(dropResponders[e],drops[selector],dragging)&&newEls.push(dropResponders[e])
}}this.add(newEls,event,dragging)}},addCallbacks:function(el,callbacks,onlyNew){var origData=$.data(el,"_dropData");if(!origData)return $.data(el,"_dropData",new $.Drop(callbacks,el)),!0;if(!onlyNew){var origCbs=origData;for(var eventName in callbacks)origCbs[eventName]=origCbs[eventName]?origCbs[eventName].concat(callbacks[eventName]):callbacks[eventName];return!1}},add:function(newEls,event,drag){for(var drop,i=0;i<newEls.length;)drop=$.data(newEls[i],"_dropData"),drop.callHandlers(this.lowerName+"init",newEls[i],event,drag),drop._canceled?newEls.splice(i,1):i++;
this._elements.push.apply(this._elements,newEls)},show:function(point,moveable,event){if(moveable.element,this._elements.length){for(var j,la,toBeActivated,aff,drag,affected=[],propagate=!0,i=0,oldLastActive=this.last_active,self=this;i<this._elements.length;)drag=$.data(this._elements[i],"_dropData"),drag?(i++,self.isAffected(point,moveable,drag)&&affected.push(drag)):this._elements.splice(i,1);for(affected.sort(this.sortByDeepestChild),event.stopRespondPropagate=function(){propagate=!1},toBeActivated=affected.slice(),this.last_active=affected,j=0;j<oldLastActive.length;j++){for(la=oldLastActive[j],i=0;aff=toBeActivated[i];){if(la==aff){toBeActivated.splice(i,1);
break}i++}if(aff||this.deactivate(la,moveable,event),!propagate)return}for(var i=0;i<toBeActivated.length;i++)if(this.activate(toBeActivated[i],moveable,event),!propagate)return;for(i=0;i<affected.length;i++)if(this.move(affected[i],moveable,event),!propagate)return}},end:function(event,moveable){for(var la,dropData,endName=this.lowerName+"end",i=0;i<this.last_active.length;i++)la=this.last_active[i],this.isAffected(event.vector(),moveable,la)&&la[this.endName]&&la.callHandlers(this.endName,null,event,moveable);
for(var r=0;r<this._elements.length;r++)dropData=$.data(this._elements[r],"_dropData"),dropData&&dropData.callHandlers(endName,null,event,moveable);this.clear()},clear:function(){this._elements.each(function(){$.removeData(this,"_dropData")}),this._elements=$(),delete this.dragging}}),$.Drag.responder=$.Drop,$.extend($.Drop.prototype,{callHandlers:function(method,el,ev,drag){for(var length=this[method]?this[method].length:0,i=0;length>i;i++)this[method][i].call(el||this.element[0],ev,this,drag)},cache:function(value){this._cache=null!=value?value:!0
},cancel:function(){this._canceled=!0}})};exports(),module.resolveWith(exports)})};dispatch("mvc/event.drop").containing(moduleFactory).to("Foundry/2.1 Modules")}();