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