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