widget-position-align-min.js revision 0cf8a68398b842bc096804b9a274317d5d6f88a7
YUI.add("widget-position-align",function(b){var l=b.Lang,e="align",g="bindUI",c="syncUI",f="offsetWidth",n="offsetHeight",p="viewportRegion",k="region",h="window",a="resize",m="scroll",i="visible",o="alignChange",j="visibleChange";function d(q){if(!this._posNode){b.error("WidgetPosition needs to be added to the Widget, before WidgetPositionAlign is added");}b.after(this._syncUIPosAlign,this,c);b.after(this._bindUIPosAlign,this,g);}d.ATTRS={align:{value:null},centered:{setter:"_setAlignCenter",lazyAdd:false,value:false}};d.TL="tl";d.TR="tr";d.BL="bl";d.BR="br";d.TC="tc";d.RC="rc";d.BC="bc";d.LC="lc";d.CC="cc";d.prototype={_syncUIPosAlign:function(){var q=this.get(e);this._uiSetHostVisible(this.get(i));if(q){this._uiSetAlign(q.node,q.points);}},_bindUIPosAlign:function(){this.after(o,this._afterAlignChange);this.after(j,this._afterVisibleChange);},_attachUIHandles:function(){if(this._uiHandles){return;}var q=b.bind(this._syncAlign,this);this._uiHandles=[b.one(h).on(a,q),b.on(m,q),this.after("destroy",this._detachUIHandles)];},_detachUIHandles:function(){if(this._uiHandles){new b.EventHandle(this._uiHandles).detach();this._uiHandles=null;}},_syncAlign:function(){this._syncUIPosAlign();},_setAlignCenter:function(q){if(q){this.set(e,{node:q===true?null:q,points:[d.CC,d.CC]});}return q;},_afterAlignChange:function(q){if(q.newVal){this._uiSetAlign(q.newVal.node,q.newVal.points);}},_uiSetHostVisible:function(q){if(q){this._attachUIHandles();}else{this._detachUIHandles();}},_afterVisibleChange:function(q){this._uiSetHostVisible(q.newVal);},_uiSetAlign:function(t,s){if(!l.isArray(s)||s.length!=2){b.error("align: Invalid Points Arguments");return;}var r=this._getRegion(t),q,u,v;if(r){q=s[0];u=s[1];switch(u){case d.TL:v=[r.left,r.top];break;case d.TR:v=[r.right,r.top];break;case d.BL:v=[r.left,r.bottom];break;case d.BR:v=[r.right,r.bottom];break;case d.TC:v=[r.left+Math.floor(r.width/2),r.top];break;case d.BC:v=[r.left+Math.floor(r.width/2),r.bottom];break;case d.LC:v=[r.left,r.top+Math.floor(r.height/2)];break;case d.RC:v=[r.right,r.top+Math.floor(r.height/2),q];break;case d.CC:v=[r.left+Math.floor(r.width/2),r.top+Math.floor(r.height/2),q];break;default:break;}if(v){this._doAlign(q,v[0],v[1]);}}},_doAlign:function(r,q,u){var t=this._posNode,s;switch(r){case d.TL:s=[q,u];break;case d.TR:s=[q-t.get(f),u];break;case d.BL:s=[q,u-t.get(n)];break;case d.BR:s=[q-t.get(f),u-t.get(n)];break;case d.TC:s=[q-(t.get(f)/2),u];break;case d.BC:s=[q-(t.get(f)/2),u-t.get(n)];break;case d.LC:s=[q,u-(t.get(n)/2)];break;case d.RC:s=[(q-t.get(f)),u-(t.get(n)/2)];break;case d.CC:s=[q-(t.get(f)/2),u-(t.get(n)/2)];break;default:break;}if(s){this.move(s);}},_getRegion:function(r){var q;if(!r){q=this._posNode.get(p);}else{r=b.Node.one(r);if(r){q=r.get(k);}}return q;},align:function(r,q){this.set(e,{node:r,points:q});},centered:function(q){this.align(q,[d.CC,d.CC]);}};b.WidgetPositionAlign=d;},"@VERSION@",{requires:["widget-position"]});