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