(function(){var e=function(e){var t=this;e.require().script("mvc/event.drag","mvc/dom.within","mvc/dom.compare").done(function(){var n=function(){var t=e.event,n=["dropover","dropon","dropout","dropinit","dropmove","dropend"];e.Drop=function(t,n){e.extend(this,t),this.element=e(n)},e.each(n,function(){t.special[this]={add:function(t){var n=e(this),r=n.data("dropEventCount")||0;n.data("dropEventCount",r+1),r==0&&e.Drop.addElement(this)},remove:function(){var t=e(this),n=t.data("dropEventCount")||0;t.data("dropEventCount",n-1),n<=1&&e.Drop.removeElement(this)}}}),e.extend(e.Drop,{lowerName:"drop",_rootElements:[],_elements:e(),last_active:[],endName:"dropon",addElement:function(e){for(var t=0;t<this._rootElements.length;t++)if(e==this._rootElements[t])return;this._rootElements.push(e)},removeElement:function(e){for(var t=0;t<this._rootElements.length;t++)if(e==this._rootElements[t]){this._rootElements.splice(t,1);return}},sortByDeepestChild:function(e,t){var n=e.element.compare(t.element);return n&16||n&4?1:n&8||n&2?-1:0},isAffected:function(e,t,n){return n.element!=t.element&&n.element.within(e[0],e[1],n._cache).length==1},deactivate:function(e,t,n){t.out(n,e),e.callHandlers(this.lowerName+"out",e.element[0],n,t)},activate:function(e,t,n){t.over(n,e),e.callHandlers(this.lowerName+"over",e.element[0],n,t)},move:function(e,t,n){e.callHandlers(this.lowerName+"move",e.element[0],n,t)},compile:function(t,r){if(!this.dragging&&!r)return;this.dragging||(this.dragging=r,this.last_active=[]);var i,s,o,u,a=[],f=this.dragging;for(var l=0;l<this._rootElements.length;l++){i=this._rootElements[l];var s=e.event.findBySelector(i,n);for(o in s){u=o?e(o,i):[i];for(var c=0;c<u.length;c++)this.addCallbacks(u[c],s[o],f)&&a.push(u[c])}}this.add(a,t,f)},addCallbacks:function(t,n,r){var i=e.data(t,"_dropData");if(!i)return e.data(t,"_dropData",new e.Drop(n,t)),!0;if(!r){var s=i;for(var o in n)s[o]=s[o]?s[o].concat(n[o]):n[o];return!1}},add:function(t,n,r,i){var s=0,o;while(s<t.length)o=e.data(t[s],"_dropData"),o.callHandlers(this.lowerName+"init",t[s],n,r),o._canceled?t.splice(s,1):s++;this._elements.push.apply(this._elements,t)},show:function(t,n,r){var i=n.element;if(!this._elements.length)return;var s,o=[],u=!0,a=0,f,l,c,h,p=this.last_active,d=[],v=this,m;while(a<this._elements.length)m=e.data(this._elements[a],"_dropData"),m?(a++,v.isAffected(t,n,m)&&o.push(m)):this._elements.splice(a,1);o.sort(this.sortByDeepestChild),r.stopRespondPropagate=function(){u=!1},c=o.slice(),this.last_active=o;for(f=0;f<p.length;f++){l=p[f],a=0;while(h=c[a]){if(l==h){c.splice(a,1);break}a++}h||this.deactivate(l,n,r);if(!u)return}for(var a=0;a<c.length;a++){this.activate(c[a],n,r);if(!u)return}for(a=0;a<o.length;a++){this.move(o[a],n,r);if(!u)return}},end:function(t,n){var r,i,s=this.lowerName+"end",o;for(var u=0;u<this.last_active.length;u++)i=this.last_active[u],this.isAffected(t.vector(),n,i)&&i[this.endName]&&i.callHandlers(this.endName,null,t,n);for(var a=0;a<this._elements.length;a++)o=e.data(this._elements[a],"_dropData"),o&&o.callHandlers(s,null,t,n);this.clear()},clear:function(){this._elements.each(function(){e.removeData(this,"_dropData")}),this._elements=e(),delete this.dragging}}),e.Drag.responder=e.Drop,e.extend(e.Drop.prototype,{callHandlers:function(e,t,n,r){var i=this[e]?this[e].length:0;for(var s=0;s<i;s++)this[e][s].call(t||this.element[0],n,this,r)},cache:function(e){this._cache=e!=null?e:!0},cancel:function(){this._canceled=!0}})};n(),t.resolveWith(n)})};dispatch("mvc/event.drop").containing(e).to("Foundry/2.1 Modules")})();