attribute-base-min.js revision c4cf29edebef0d1c75ccfa55f67b2549c235bf8e
YUI.add("attribute-base",function(c){c.State=function(){this.data={};};c.State.prototype={add:function(B,C,E){var D=this.data;D[C]=D[C]||{};D[C][B]=E;},addAll:function(B,D){var C;for(C in D){if(D.hasOwnProperty(C)){this.add(B,C,D[C]);}}},remove:function(B,C){var D=this.data;if(D[C]&&(B in D[C])){delete D[C][B];}},removeAll:function(B,D){var C=this.data;c.each(D||C,function(F,E){if(c.Lang.isString(E)){this.remove(B,E);}else{this.remove(B,F);}},this);},get:function(B,C){var D=this.data;return(D[C]&&B in D[C])?D[C][B]:undefined;},getAll:function(B){var D=this.data,C;c.each(D,function(F,E){if(B in D[E]){C=C||{};C[E]=F[B];}},this);return C;}};var k=c.Object,f=c.Lang,l=c.EventTarget,w=".",t="Change",n="getter",m="setter",o="readOnly",x="writeOnce",u="initOnly",A="validator",h="value",p="valueFn",e="broadcast",r="lazyAdd",j="_bypassProxy",z="added",b="initializing",i="initValue",v="published",s="defaultValue",a="lazy",q="isLazyAdd",g,y={};y[o]=1;y[x]=1;y[n]=1;y[e]=1;function d(C,B){var D=this;D._ATTR_E_FACADE={};l.call(D,{emitFacade:true});D._conf=D._state=new c.State();D._stateProxy=D._stateProxy||null;D._requireAddAttr=D._requireAddAttr||false;this._initAttrs(C,B);}d.INVALID_VALUE={};g=d.INVALID_VALUE;d._ATTR_CFG=[m,n,A,h,p,x,o,r,e,j];d.prototype={addAttr:function(C,B,E){var F=this,H=F._state,G,D;E=(r in B)?B[r]:E;if(E&&!F.attrAdded(C)){H.add(C,a,B||{});H.add(C,z,true);}else{if(!F.attrAdded(C)||H.get(C,q)){B=B||{};D=(h in B);if(D){G=B.value;delete B.value;}B.added=true;B.initializing=true;H.addAll(C,B);if(D){F.set(C,G);}H.remove(C,b);}}return F;},attrAdded:function(B){return !!this._state.get(B,z);},modifyAttr:function(C,B){var D=this,F,E;if(D.attrAdded(C)){if(D._isLazyAttr(C)){D._addLazyAttr(C);}E=D._state;for(F in B){if(y[F]&&B.hasOwnProperty(F)){E.add(C,F,B[F]);if(F===e){E.remove(C,v);}}}}},removeAttr:function(B){this._state.removeAll(B);},get:function(B){return this._getAttr(B);},_isLazyAttr:function(B){return this._state.get(B,a);},_addLazyAttr:function(C){var D=this._state,B=D.get(C,a);D.add(C,q,true);D.remove(C,a);this.addAttr(C,B);},set:function(B,D,C){return this._setAttr(B,D,C);},reset:function(B){var D=this,C;if(B){if(D._isLazyAttr(B)){D._addLazyAttr(B);}D.set(B,D._state.get(B,i));}else{C=D._state.data.added;c.each(C,function(E,F){D.reset(F);},D);}return D;},_set:function(B,D,C){return this._setAttr(B,D,C,true);},_getAttr:function(D){var E=this,I=D,F=E._state,G,B,H,C;if(D.indexOf(w)!==-1){G=D.split(w);D=G.shift();}if(E._tCfgs&&E._tCfgs[D]){C={};C[D]=E._tCfgs[D];delete E._tCfgs[D];E._addAttrs(C,E._tVals);}if(E._isLazyAttr(D)){E._addLazyAttr(D);}H=E._getStateVal(D);B=F.get(D,n);if(B&&!B.call){B=this[B];}H=(B)?B.call(E,H,I):H;H=(G)?k.getValue(H,G):H;return H;},_setAttr:function(D,G,B,E){var K=true,C=this._state,H=this._stateProxy,M=C.data,J,N,O,F,I,L;if(D.indexOf(w)!==-1){N=D;O=D.split(w);D=O.shift();}if(this._isLazyAttr(D)){this._addLazyAttr(D);}J=(!M.value||!(D in M.value));if(H&&D in H&&!this._state.get(D,j)){J=false;}if(this._requireAddAttr&&!this.attrAdded(D)){}else{I=C.get(D,x);L=C.get(D,b);if(!J&&!E){if(I){K=false;}if(C.get(D,o)){K=false;}}if(!L&&!E&&I===u){K=false;}if(K){if(!J){F=this.get(D);}if(O){G=k.setValue(c.clone(F),O,G);if(G===undefined){K=false;}}if(K){if(L){this._setAttrVal(D,N,F,G);}else{this._fireAttrChange(D,N,F,G,B);}}}}return this;},_fireAttrChange:function(H,G,E,D,B){var J=this,F=H+t,C=J._state,I;if(!C.get(H,v)){J.publish(F,{queuable:false,defaultTargetOnly:true,defaultFn:J._defAttrChangeFn,silent:true,broadcast:C.get(H,e)});C.add(H,v,true);}I=(B)?c.merge(B):J._ATTR_E_FACADE;I.attrName=H;I.subAttrName=G;I.prevVal=E;I.newVal=D;J.fire(F,I);},_defAttrChangeFn:function(B){if(!this._setAttrVal(B.attrName,B.subAttrName,B.prevVal,B.newVal)){B.stopImmediatePropagation();}else{B.newVal=this.get(B.attrName);}},_getStateVal:function(B){var C=this._stateProxy;return C&&(B in C)&&!this._state.get(B,j)?C[B]:this._state.get(B,h);},_setStateVal:function(B,D){var C=this._stateProxy;if(C&&(B in C)&&!this._state.get(B,j)){C[B]=D;}else{this._state.add(B,h,D);}},_setAttrVal:function(M,L,I,G){var O=this,J=true,D=O._state,E=D.get(M,A),H=D.get(M,m),K=D.get(M,b),N=this._getStateVal(M),C=L||M,F,B;if(E){if(!E.call){E=this[E];}if(E){B=E.call(O,G,C);if(!B&&K){G=D.get(M,s);B=true;}}}if(!E||B){if(H){if(!H.call){H=this[H];}if(H){F=H.call(O,G,C);if(F===g){J=false;}else{if(F!==undefined){G=F;}}}}if(J){if(!L&&(G===N)&&!f.isObject(G)){J=false;}else{if(D.get(M,i)===undefined){D.add(M,i,G);}O._setStateVal(M,G);}}}else{J=false;}return J;},setAttrs:function(B,C){return this._setAttrs(B,C);},_setAttrs:function(C,D){for(var B in C){if(C.hasOwnProperty(B)){this.set(B,C[B]);}}return this;},getAttrs:function(B){return this._getAttrs(B);},_getAttrs:function(E){var G=this,I={},F,C,B,H,D=(E===true);E=(E&&!D)?E:k.keys(G._state.data.added);for(F=0,C=E.length;F<C;F++){B=E[F];H=G.get(B);if(!D||G._getStateVal(B)!=G._state.get(B,i)){I[B]=G.get(B);}}return I;},addAttrs:function(B,C,D){var E=this;if(B){E._tCfgs=B;E._tVals=E._normAttrVals(C);E._addAttrs(B,E._tVals,D);E._tCfgs=E._tVals=null;}return E;},_addAttrs:function(C,D,E){var G=this,B,F,H;for(B in C){if(C.hasOwnProperty(B)){F=C[B];F.defaultValue=F.value;H=G._getAttrInitVal(B,F,G._tVals);if(H!==undefined){F.value=H;}if(G._tCfgs[B]){delete G._tCfgs[B];}G.addAttr(B,F,E);}}},_protectAttrs:function(C){if(C){C=c.merge(C);for(var B in C){if(C.hasOwnProperty(B)){C[B]=c.merge(C[B]);}}}return C;},_normAttrVals:function(B){return(B)?c.merge(B):null;},_getAttrInitVal:function(B,C,E){var F,D;if(!C[o]&&E&&E.hasOwnProperty(B)){F=E[B];}else{F=C[h];D=C[p];if(D){if(!D.call){D=this[D];}if(D){F=D.call(this);}}}return F;},_getAttrCfg:function(B){var D,C=this._state.data;if(C){D={};c.each(C,function(E,F){if(B){if(B in E){D[F]=E[B];}}else{c.each(E,function(H,G){D[G]=D[G]||{};D[G][F]=H;});}});}return D;},_initAttrs:function(C,B){C=C||this.constructor.ATTRS;var D=c.Base;if(C&&!(D&&c.instanceOf(this,D))){this.addAttrs(this._protectAttrs(C),B);}}};c.mix(d,l,false,null,1);c.Attribute=d;},"@VERSION@",{requires:["event-custom"]});