attribute-min.js revision 77b62780ab47bc020d3cae8b1fb13c808d9bca7c
YUI.add("attribute",function(B){B.State=function(){this.data={};};B.State.prototype={add:function(O,Q){B.each(Q,function(S,R){if(!this.data[R]){this.data[R]={};}this.data[R][O]=S;},this);},remove:function(Q,S){var R=this.data,O=function(T){if(R[T]&&(Q in R[T])){delete R[T][Q];}};if(B.Lang.isString(S)){O(S);}else{B.each(S||R,function(U,T){if(B.Lang.isString(T)){O(T);}else{O(U);}},this);}},get:function(O,Q){var S=this.data,R;if(Q){return(S[Q]&&O in S[Q])?S[Q][O]:undefined;}else{B.each(S,function(U,T){if(O in S[T]){R=R||{};R[T]=U[O];}},this);return R;}}};var I=B.Object,J=".",F="Change",E="getter",C="setter",H="value",N="init",K="initValue",M="readOnly",G="writeOnce",D="validator",L,P=B.EventTarget;function A(){P.call(this,{emitFacade:true});this._conf=new B.State();}A.INVALID_VALUE={};L=A.INVALID_VALUE;A.prototype={addAttr:function(Q,O){if(!this.attrAdded(Q)){O=O||{};var S,R=(H in O);if(R){S=O.value;delete O.value;}O[N]=true;this._conf.add(Q,O);if(R){this.set(Q,S);}}else{}return this;},attrAdded:function(O){return !!(this._conf.get(O,N));},removeAttr:function(O){this._conf.remove(O);},get:function(R){var Q=this._conf,S,O,T;if(R.indexOf(J)!==-1){S=R.split(J);R=S.shift();}T=Q.get(R,H);O=Q.get(R,E);T=(O)?O.call(this,T):T;T=(S)?I.getValue(T,S):T;return T;},set:function(O,R,Q){return this._setAttr(O,R,Q);},reset:function(Q){if(Q){this._set(Q,this._conf.get(Q,K));}else{var O=this._conf.data.initValue;B.each(O,function(R,S){this._set(S,R);},this);}return this;},_set:function(O,R,Q){return this._setAttr(O,R,Q,true);},_setAttr:function(Q,T,O,R){var Y=this._conf,W=Y.data,V=true,U=(!W.value||!(Q in W.value)),X,Z,S;if(Q.indexOf(J)!==-1){X=Q;Z=Q.split(J);Q=Z.shift();}if(!U&&!R){if(Y.get(Q,G)){V=false;}if(Y.get(Q,M)){V=false;}}if(!Y.get(Q)){V=false;}S=this.get(Q);if(Z){T=I.setValue(B.clone(S),Z,T);if(T===undefined){V=false;}}if(V){this._fireAttrChange(Q,S,T,Q,X,O);}return this;},_fireAttrChange:function(S,U,O,Q,V,T){S=S+F;this.publish(S,{queuable:false,defaultFn:this._defAttrChangeFn,silent:true});var R={type:S,prevVal:U,newVal:O,attrName:Q,subAttrName:V};if(T){B.mix(R,T);}this.fire(R);},_defAttrChangeFn:function(U){var S=true,V=this._conf,O=U.attrName,R=U.newVal,X=V.get(O,D),W=V.get(O,C),T,Q;if(!X||X.call(this,R)){if(W){Q=W.call(this,R);if(Q===L){S=false;}else{if(Q!==undefined){R=Q;}}}}else{S=false;}if(!U.subAttrName&&R===U.prevVal){S=false;}if(S){T={value:R};if(V.get(O,K)===undefined){T[K]=R;}V.add(O,T);U.newVal=V.get(O,H);}else{U.stopImmediatePropagation();}},setAttrs:function(Q){for(var O in Q){if(Q.hasOwnProperty(O)){this.set(O,Q[O]);}}return this;},getAttrs:function(S){var V={},T,Q,O,U,R=(S===true);S=(S&&!R)?S:I.keys(this._conf.data[H]);for(T=0,Q=S.length;T<Q;T++){O=S[T];U=this.get(O);if(!R||this._conf.get(O,H)!=this._conf.get(O,K)){V[O]=this.get(O);}}return V;},addAttrs:function(Q,R){if(Q){var O,S,T;R=this._splitAttrVals(R);for(O in Q){if(Q.hasOwnProperty(O)){S=Q[O];T=this._getAttrInitVal(O,S,R);if(T!==undefined){S.value=T;}this.addAttr(O,S);}}}return this;},_splitAttrVals:function(S){var U={},T={},V,O,R,Q;for(Q in S){if(S.hasOwnProperty(Q)){if(Q.indexOf(J)!==-1){V=Q.split(J);O=V.shift();R=T[O]=T[O]||[];R[R.length]={path:V,value:S[Q]};}else{U[Q]=S[Q];}}}return{simple:U,complex:T};},_getAttrInitVal:function(W,U,Y){var Q=(U.valueFn)?U.valueFn.call(this):U.value,O,R,T,S,Z,X,V;if(!U[M]&&Y){O=Y.simple;if(O&&O.hasOwnProperty(W)){Q=O[W];}R=Y.complex;if(R&&R.hasOwnProperty(W)){V=R[W];for(T=0,S=V.length;T<S;++T){Z=V[T].path;X=V[T].value;I.setValue(Q,Z,X);}}}return Q;}};B.mix(A,P,false,null,1);B.Attribute=A;},"@VERSION@",{requires:["event-custom"]});