AUI.add("aui-resize-constrain",function(t){var i=t.Lang,o=i.isBoolean,s=i.isNumber,q=i.isString,z=function(A){return(A instanceof t.Node);},D="borderBottomWidth",f="borderLeftWidth",y="borderRightWidth",j="borderTopWidth",m="bottom",l="con",E="constrain",F="host",r="left",h="maxHeight",v="maxWidth",a="minHeight",k="minWidth",G="node",b="offsetHeight",n="offsetWidth",d="preserveRatio",x="region",u="resizeConstrained",p="right",e="tickX",c="tickY",w="top",C="view",B="viewportRegion";function g(){g.superclass.constructor.apply(this,arguments);}t.mix(g,{NAME:u,NS:l,ATTRS:{constrain:{setter:function(A){if(A&&(z(A)||q(A)||A.nodeType)){A=t.one(A);}return A;}},minHeight:{value:15,validator:s},minWidth:{value:15,validator:s},maxHeight:{value:Infinity,validator:s},maxWidth:{value:Infinity,validator:s},preserveRatio:{value:false,validator:o},tickX:{value:false},tickY:{value:false}}});t.extend(g,t.Plugin.Base,{constrainBorderInfo:null,initializer:function(){var A=this;var H=A.get(F);A.constrainBorderInfo={bottom:0,left:0,right:0,top:0};H.delegate.dd.plug(t.Plugin.DDConstrained,{tickX:A.get(e),tickY:A.get(c)});H.after("resize:align",t.bind(A._handleResizeAlignEvent,A));H.on("resize:start",t.bind(A._handleResizeStartEvent,A));},_checkConstrain:function(H,P,I){var N=this;var Q=N.get(F);var A=Q.info;var L=N._getConstrainRegion();if(L){var M=A[H]+A[I];var J=L[P]-N.constrainBorderInfo[P];if(M>=J){A[I]-=(M-J);}var K=A[H];var O=L[H]+N.constrainBorderInfo[H];if(K<=O){A[H]+=(O-K);A[I]-=(O-K);}}},_checkHeight:function(){var A=this;var I=A.get(F);var L=I.info;var K=I.originalInfo;var H=A.get(h);var J=A.get(a);A._checkConstrain(w,m,b);if(L.offsetHeight>H){I._checkSize(b,H);}if(L.offsetHeight<J){I._checkSize(b,J);}},_checkRatio:function(){var U=this;var N=U.get(F);var T=N.info;var J=N.originalInfo;var M=J.offsetWidth;var V=J.offsetHeight;var L=J.top;var W=J.left;var P=J.bottom;var S=J.right;var I=function(){return(T.offsetWidth/M);};var K=function(){return(T.offsetHeight/V);};var O=N.changeHeightHandles;if(U.get(E)&&N.changeHeightHandles&&N.changeWidthHandles){var Q=U._getConstrainRegion();var X=U.constrainBorderInfo;var A=(Q.bottom-X.bottom)-P;var R=W-(Q.left+X.left);var H=(Q.right-X.right)-S;var Y=L-(Q.top+X.top);if(N.changeLeftHandles&&N.changeTopHandles){O=(Y<R);}else{if(N.changeLeftHandles){O=(A<R);}else{if(N.changeTopHandles){O=(Y<H);}else{O=(A<H);}}}}if(O){T.offsetWidth=M*K();U._checkWidth();T.offsetHeight=V*I();}else{T.offsetHeight=V*I();U._checkHeight();T.offsetWidth=M*K();}if(N.changeTopHandles){T.top=L+(V-T.offsetHeight);}if(N.changeLeftHandles){T.left=W+(M-T.offsetWidth);}t.each(T,function(aa,Z){if(s(aa)){T[Z]=Math.round(aa);}});},_checkRegion:function(){var A=this;var H=A.get(F);var I=A._getConstrainRegion();return t.DOM.inRegion(null,I,true,H.info);},_checkWidth:function(){var A=this;var J=A.get(F);var L=J.info;var K=J.originalInfo;var I=A.get(v);var H=A.get(k);A._checkConstrain(r,p,n);if(L.offsetWidth<H){J._checkSize(n,H);}if(L.offsetWidth>I){J._checkSize(n,I);}},_getConstrainRegion:function(){var A=this;var I=A.get(F);var H=I.get(G);var K=A.get(E);var J=null;if(K){if(K==C){J=H.get(B);}else{if(z(K)){J=K.get(x);}else{J=K;}}}return J;},_handleResizeAlignEvent:function(I){var A=this;var H=A.get(F);A._checkHeight();A._checkWidth();if(A.get(d)){A._checkRatio();}if(A.get(E)&&!A._checkRegion()){H.info=H.lastInfo;}},_handleResizeStartEvent:function(H){var A=this;A._updateConstrainBorderInfo();},_updateConstrainBorderInfo:function(){var H=this;var I=H.get(E);if(z(I)){var A=function(J){return parseFloat(I.getStyle(J))||0;};H.constrainBorderInfo.bottom=A(D);H.constrainBorderInfo.left=A(f);H.constrainBorderInfo.right=A(y);H.constrainBorderInfo.top=A(j);}}});t.namespace("Plugin");t.Plugin.ResizeConstrained=g;},"1.0.1",{requires:["aui-resize-base","dd-constrain","plugin"],skinnable:false});