Ext.namespace("MODx.portal");Ext.ux.Portal=Ext.extend(Ext.Panel,{layout:"column",cls:"x-portal",defaultType:"portalcolumn",initComponent:function(){Ext.ux.Portal.superclass.initComponent.call(this);this.addEvents({validatedrop:true,beforedragover:true,dragover:true,beforedrop:true,drop:true});},initEvents:function(){Ext.ux.Portal.superclass.initEvents.call(this);this.dd=new Ext.ux.Portal.DropZone(this,this.dropConfig);},beforeDestroy:function(){if(this.dd){this.dd.unreg();}Ext.ux.Portal.superclass.beforeDestroy.call(this);}});Ext.reg("portal",Ext.ux.Portal);Ext.ux.Portal.DropZone=function(B,A){this.portal=B;Ext.dd.ScrollManager.register(B.body);Ext.ux.Portal.DropZone.superclass.constructor.call(this,B.bwrap.dom,A);B.body.ddScrollConfig=this.ddScrollConfig;};Ext.extend(Ext.ux.Portal.DropZone,Ext.dd.DropTarget,{ddScrollConfig:{vthresh:50,hthresh:-1,animate:true,increment:200},createEvent:function(B,D,A,E,F,C){return{portal:this.portal,panel:A.panel,columnIndex:E,column:F,position:C,data:A,source:B,rawEvent:D,status:this.dropAllowed};},notifyOver:function(S,O,R){var P=O.getXY(),A=this.portal,G=S.proxy;if(!this.grid){this.grid=this.getGrid();}var N=A.body.dom.clientWidth;if(!this.lastCW){this.lastCW=N;}else{if(this.lastCW!=N){this.lastCW=N;A.doLayout();this.grid=this.getGrid();}}var M=0,E=this.grid.columnX,F=false;for(var K=E.length;M<K;M++){if(P[0]<(E[M].x+E[M].w)){F=true;break;}}if(!F){M--;}var I,D=false,B=0,Q=A.items.itemAt(M),H=Q.items.items,C=false;for(var K=H.length;B<K;B++){I=H[B];var L=I.el.getHeight();if(L===0){C=true;}else{if((I.el.getY()+(L/2))>P[1]){D=true;break;}}}B=(D&&I?B:Q.items.getCount())+(C?-1:0);var J=this.createEvent(S,O,R,M,Q,B);if(A.fireEvent("validatedrop",J)!==false&&A.fireEvent("beforedragover",J)!==false){G.getProxy().setWidth("auto");if(I){G.moveProxy(I.el.dom.parentNode,D?I.el.dom:null);}else{G.moveProxy(Q.el.dom,null);}this.lastPos={c:Q,col:M,p:C||(D&&I)?B:false};this.scrollPos=A.body.getScroll();A.fireEvent("dragover",J);return J.status;}else{return J.status;}},notifyOut:function(){delete this.grid;},notifyDrop:function(I,D,H){delete this.grid;if(!this.lastPos){return ;}var F=this.lastPos.c,A=this.lastPos.col,G=this.lastPos.p;var C=this.createEvent(I,D,H,A,F,G!==false?G:F.items.getCount());if(this.portal.fireEvent("validatedrop",C)!==false&&this.portal.fireEvent("beforedrop",C)!==false){I.proxy.getProxy().remove();I.panel.el.dom.parentNode.removeChild(I.panel.el.dom);if(G!==false){if(F==I.panel.ownerCt&&(F.items.items.indexOf(I.panel)<=G)){G++;}F.insert(G,I.panel);}else{F.add(I.panel);}F.doLayout();this.portal.fireEvent("drop",C);var B=this.scrollPos.top;if(B){var E=this.portal.body.dom;setTimeout(function(){E.scrollTop=B;},10);}}delete this.lastPos;},getGrid:function(){var A=this.portal.bwrap.getBox();A.columnX=[];this.portal.items.each(function(B){A.columnX.push({x:B.el.getX(),w:B.el.getWidth()});});return A;},unreg:function(){Ext.ux.Portal.DropZone.superclass.unreg.call(this);}});MODx.portal.Column=Ext.extend(Ext.Container,{layout:"anchor",defaultType:"portlet",cls:"x-portal-column",style:"padding:10px;",columnWidth:1,defaults:{collapsible:true,autoHeight:true,titleCollapse:true,draggable:true,style:"padding: 5px 0;",bodyStyle:"padding: 15px;"}});Ext.reg("portalcolumn",MODx.portal.Column);MODx.portal.Portlet=Ext.extend(Ext.Panel,{anchor:Ext.isSafari?"98%":"100%",frame:true,collapsible:true,draggable:true,cls:"x-portlet",stateful:false,layout:"form"});Ext.reg("portlet",MODx.portal.Portlet);