dd-constrain-min.js revision a7effe28aeae2769094aec1b6b64eb241555f5c4
YUI.add("dd-constrain",function(B){var G="dragNode",H="offsetHeight",D="offsetWidth",L="host",K="constrain2region",E="tickXArray",J="tickYArray",I=B.DD.DDM,F=null;var A=function(C){A.superclass.constructor.apply(this,arguments);};A.NAME="DragConstrained";A.NS="con";A.ATTRS={host:{},stickX:{value:false},stickY:{value:false},tickX:{value:false},tickY:{value:false},tickXArray:{value:false},tickYArray:{value:false},constrain2region:{value:false,getter:function(C){if(B.Lang.isObject(C)){var M={};B.mix(M,C);return M;}else{return false;}},setter:function(C){if(B.Lang.isObject(C)){if(B.Lang.isNumber(C.top)&&B.Lang.isNumber(C.right)&&B.Lang.isNumber(C.left)&&B.Lang.isNumber(C.bottom)){var M={};B.mix(M,C);return M;}else{return false;}}else{if(C!==false){return false;}}return C;}},gutter:{value:"0",setter:function(C){return B.DD.DDM.cssSizestoObject(C);}},constrain2node:{value:false,setter:function(M){if(!this.get(K)){var C=B.Node.get(M);if(C){return C;}}else{if(this.get(K)!==false){}}return false;}},constrain2view:{value:false}};F={initializer:function(){this.get(L).on("drag:start",B.bind(this._handleStart,this));this.get(L).after("drag:align",B.bind(this.align,this));},_handleStart:function(){this._regionCache=null;},_regionCache:null,_cacheRegion:function(){this._regionCache=this.get("constrain2node").get("region");},getRegion:function(Q){var O={},P=null,C=null,N=this.get("gutter"),M=this.get(L);if(this.get("constrain2node")){if(!this._regionCache){B.on("resize",B.bind(this._cacheRegion,this),window);this._cacheRegion();}O=B.clone(this._regionCache);}else{if(this.get(K)){O=this.get(K);}else{if(this.get("constrain2view")){O=this.get("node").get("viewportRegion");}else{return false;}}}B.each(N,function(R,S){if((S=="right")||(S=="bottom")){O[S]-=R;}else{O[S]+=R;}});if(Q){P=M.get(G).get(H);C=M.get(G).get(D);O.right=O.right-C;O.bottom=O.bottom-P;}return O;},_checkRegion:function(C){var N=C,P=this.getRegion(),O=this.get(L),Q=O.get(G).get(H),M=O.get(G).get(D);if(N[1]>(P.bottom-Q)){C[1]=(P.bottom-Q);}if(P.top>N[1]){C[1]=P.top;}if(N[0]>(P.right-M)){C[0]=(P.right-M);}if(P.left>N[0]){C[0]=P.left;}return C;},inRegion:function(N){N=N||this.get(L).get(G).getXY();var M=this._checkRegion([N[0],N[1]]),C=false;if((N[0]===M[0])&&(N[1]===M[1])){C=true;}return C;},align:function(){var N=this.get(L),C=N.actXY,M=this.getRegion(true);if(this.get("stickX")){C[1]=(N.startXY[1]-N.deltaXY[1]);}if(this.get("stickY")){C[0]=(N.startXY[0]-N.deltaXY[0]);}if(M){C=this._checkRegion(C);}C=this._checkTicks(C,M);N.actXY=C;},_checkTicks:function(R,P){var O=this.get(L),Q=(O.startXY[0]-O.deltaXY[0]),N=(O.startXY[1]-O.deltaXY[1]),C=this.get("tickX"),M=this.get("tickY");if(C&&!this.get(E)){R[0]=I._calcTicks(R[0],Q,C,P.left,P.right);}if(M&&!this.get(J)){R[1]=I._calcTicks(R[1],N,M,P.top,P.bottom);}if(this.get(E)){R[0]=I._calcTickArray(R[0],this.get(E),P.left,P.right);}if(this.get(J)){R[1]=I._calcTickArray(R[1],this.get(J),P.top,P.bottom);}return R;}};B.namespace("plugin");B.extend(A,B.Base,F);B.plugin.DDConstrained=A;B.mix(I,{_calcTicks:function(S,R,O,Q,P){var M=((S-R)/O),N=Math.floor(M),C=Math.ceil(M);if((N!==0)||(C!==0)){if((M>=N)&&(M<=C)){S=(R+(O*N));if(Q&&P){if(S<Q){S=(R+(O*(N+1)));}if(S>P){S=(R+(O*(N-1)));}}}}return S;},_calcTickArray:function(T,U,S,P){var M=0,Q=U.length,O=0,N,C,R;if(!U||(U.length===0)){return T;}else{if(U[0]>=T){return U[0];}else{for(M=0;M<Q;M++){O=(M+1);if(U[O]&&U[O]>=T){N=T-U[M];C=U[O]-T;R=(C>N)?U[M]:U[O];if(S&&P){if(R>P){if(U[M]){R=U[M];}else{R=U[Q-1];}}}return R;}}return U[U.length-1];}}}});},"@VERSION@",{requires:["dd-drag"],skinnable:false});