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