2 Copyright (c) 2009, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.net/yui/license.txt
8 YUI.add('attribute-base', function(Y) {
11 * The State class maintains state for a collection of named items, with
12 * a varying number of properties defined.
14 * It avoids the need to create a separate class for the item, and separate instances
15 * of these classes for each item, by storing the state in a 2 level hash table,
16 * improving performance when the number of items is likely to be large.
21 Y.State = function() {
32 * Adds a property to an item.
35 * @param name {String} The name of the item.
36 * @param key {String} The name of the property.
37 * @param val {Any} The value of the property.
39 add : function(name, key, val) {
41 d[key] = d[key] || {};
46 * Adds multiple properties to an item.
49 * @param name {String} The name of the item.
50 * @param o {Object} A hash of property/value pairs.
52 addAll: function(name, o) {
55 if (o.hasOwnProperty(key)) {
56 this.add(name, key, o[key]);
62 * Removes a property from an item.
65 * @param name {String} The name of the item.
66 * @param key {String} The property to remove.
68 remove: function(name, key) {
70 if (d[key] && (name in d[key])) {
76 * Removes multiple properties from an item, or remove the item completely.
79 * @param name {String} The name of the item.
80 * @param o {Object|Array} Collection of properties to delete. If not provided, the entire item is removed.
82 removeAll: function(name, o) {
85 Y.each(o || d, function(v, k) {
86 if(Y.Lang.isString(k)) {
95 * For a given item, returns the value of the property requested, or undefined if not found.
98 * @param name {String} The name of the item
99 * @param key {String} Optional. The property value to retrieve.
100 * @return {Any} The value of the supplied property.
102 get: function(name, key) {
104 return (d[key] && name in d[key]) ? d[key][name] : undefined;
108 * For the given item, returns a disposable object with all of the
109 * item's property/value pairs.
112 * @param name {String} The name of the item
113 * @return {Object} An object with property/value pairs for the item.
115 getAll : function(name) {
116 var d = this.data, o;
118 Y.each(d, function(v, k) {
129 * The attribute module provides an augmentable Attribute implementation, which
130 * adds configurable attributes and attribute change events to the class being
131 * augmented. It also provides a State class, which is used internally by Attribute,
132 * but can also be used independently to provide a name/property/value data structure to
139 * The attribute-base submodule provides core attribute handling support, with everything
140 * aside from complex attribute handling in the provider's constructor.
143 * @submodule attribute-base
147 EventTarget = Y.EventTarget,
152 // Externally configurable props
155 READ_ONLY = "readOnly",
156 WRITE_ONCE = "writeOnce",
157 VALIDATOR = "validator",
159 VALUE_FN = "valueFn",
160 BROADCAST = "broadcast",
161 LAZY_ADD = "lazyAdd",
162 BYPASS_PROXY = "_bypassProxy",
164 // Used for internal state management
166 INITIALIZING = "initializing",
167 INIT_VALUE = "initValue",
168 PUBLISHED = "published",
169 DEF_VALUE = "defaultValue",
171 IS_LAZY_ADD = "isLazyAdd",
176 // Properties which can be changed after the attribute has been added.
177 MODIFIABLE[READ_ONLY] = 1;
178 MODIFIABLE[WRITE_ONCE] = 1;
179 MODIFIABLE[GETTER] = 1;
180 MODIFIABLE[BROADCAST] = 1;
184 * Attribute provides configurable attribute support along with attribute change events. It is designed to be
185 * augmented on to a host class, and provides the host with the ability to configure attributes to store and retrieve state,
186 * along with attribute change events.
188 * <p>For example, attributes added to the host can be configured:</p>
190 * <li>As read only.</li>
191 * <li>As write once.</li>
192 * <li>With a setter function, which can be used to manipulate
193 * values passed to Attribute's <a href="#method_set">set</a> method, before they are stored.</li>
194 * <li>With a getter function, which can be used to manipulate stored values,
195 * before they are returned by Attribute's <a href="#method_get">get</a> method.</li>
196 * <li>With a validator function, to validate values before they are stored.</li>
199 * <p>See the <a href="#method_addAttr">addAttr</a> method, for the complete set of configuration
200 * options available for attributes</p>.
202 * <p><strong>NOTE:</strong> Most implementations will be better off extending the <a href="Base.html">Base</a> class,
203 * instead of augmenting Attribute directly. Base augments Attribute and will handle the initial configuration
204 * of attributes for derived classes, accounting for values passed into the constructor.</p>
209 function Attribute() {
211 var host = this, // help compression
212 attrs = this.constructor.ATTRS,
215 // Perf tweak - avoid creating event literals if not required.
216 host._ATTR_E_FACADE = {};
218 EventTarget.call(host, {emitFacade:true});
220 // _conf maintained for backwards compat
221 host._conf = host._state = new Y.State();
223 host._stateProxy = host._stateProxy || null;
224 host._requireAddAttr = host._requireAddAttr || false;
226 // ATTRS support for Node, which is not Base based
227 if ( attrs && !(Base && host instanceof Base)) {
228 host.addAttrs(this._protectAttrs(attrs));
233 * <p>The value to return from an attribute setter in order to prevent the set from going through.</p>
235 * <p>You can return this value from your setter if you wish to combine validator and setter
236 * functionality into a single setter function, which either returns the massaged value to be stored or
237 * Attribute.INVALID_VALUE to prevent invalid values from being stored.</p>
239 * @property Attribute.INVALID_VALUE
244 Attribute.INVALID_VALUE = {};
245 INVALID_VALUE = Attribute.INVALID_VALUE;
248 * The list of properties which can be configured for
249 * each attribute (e.g. setter, getter, writeOnce etc.).
251 * This property is used internally as a whitelist for faster
254 * @property Attribute._ATTR_CFG
259 Attribute._ATTR_CFG = [SETTER, GETTER, VALIDATOR, VALUE, VALUE_FN, WRITE_ONCE, READ_ONLY, LAZY_ADD, BROADCAST, BYPASS_PROXY];
261 Attribute.prototype = {
264 * Adds an attribute with the provided configuration to the host object.
267 * The config argument object supports the following properties:
271 * <dt>value <Any></dt>
272 * <dd>The initial value to set on the attribute</dd>
274 * <dt>valueFn <Function></dt>
275 * <dd>A function, which will return the initial value to set on the attribute. This is useful
276 * for cases where the attribute configuration is defined statically, but needs to
277 * reference the host instance ("this") to obtain an initial value.
278 * If defined, this precedence over the value property.</dd>
280 * <dt>readOnly <boolean></dt>
281 * <dd>Whether or not the attribute is read only. Attributes having readOnly set to true
282 * cannot be modified by invoking the set method.</dd>
284 * <dt>writeOnce <boolean></dt>
285 * <dd>Whether or not the attribute is "write once". Attributes having writeOnce set to true,
286 * can only have their values set once, be it through the default configuration,
287 * constructor configuration arguments, or by invoking set.</dd>
289 * <dt>setter <Function></dt>
290 * <dd>The setter function used to massage or normalize the value passed to the set method for the attribute.
291 * The value returned by the setter will be the final stored value. Returning
292 * <a href="#property_Attribute.INVALID_VALUE">Attribute.INVALID_VALUE</a>, from the setter will prevent
293 * the value from being stored.</dd>
295 * <dt>getter <Function></dt>
296 * <dd>The getter function used to massage or normalize the value returned by the get method for the attribute.
297 * The value returned by the getter function is the value which will be returned to the user when they
300 * <dt>validator <Function></dt>
301 * <dd>The validator function invoked prior to setting the stored value. Returning
302 * false from the validator function will prevent the value from being stored.</dd>
304 * <dt>broadcast <int></dt>
305 * <dd>If and how attribute change events for this attribute should be broadcast. See CustomEvent's <a href="CustomEvent.html#property_broadcast">broadcast</a> property for
306 * valid values. By default attribute change events are not broadcast.</dd>
308 * <dt>lazyAdd <boolean></dt>
309 * <dd>Whether or not to delay initialization of the attribute until the first call to get/set it.
310 * This flag can be used to over-ride lazy initialization on a per attribute basis, when adding multiple attributes through
311 * the <a href="#method_addAttrs">addAttrs</a> method.</dd>
315 * <p>The setter, getter and validator are invoked with the value and name passed in as the first and second arguments, and with
316 * the context ("this") set to the host object.</p>
318 * <p>Configuration properties outside of the list mentioned above are considered private properties used internally by attribute, and are not intended for public use.</p>
322 * @param {String} name The name of the attribute.
323 * @param {Object} config An object with attribute configuration property/value pairs, specifying the configuration for the attribute.
326 * <strong>NOTE:</strong> The configuration object is modified when adding an attribute, so if you need
327 * to protect the original values, you will need to merge the object.
330 * @param {boolean} lazy (optional) Whether or not to add this attribute lazily (on the first call to get/set).
332 * @return {Object} A reference to the host object.
336 addAttr: function(name, config, lazy) {
339 var host = this, // help compression
344 lazy = (LAZY_ADD in config) ? config[LAZY_ADD] : lazy;
346 if (lazy && !host.attrAdded(name)) {
347 state.add(name, LAZY, config || {});
348 state.add(name, ADDED, true);
352 if (!host.attrAdded(name) || state.get(name, IS_LAZY_ADD)) {
354 config = config || {};
356 hasValue = (VALUE in config);
360 // We'll go through set, don't want to set value in _state directly
361 value = config.value;
366 config.initializing = true;
368 state.addAll(name, config);
371 // Go through set, so that raw values get normalized/validated
372 host.set(name, value);
375 state.remove(name, INITIALIZING);
383 * Checks if the given attribute has been added to the host
386 * @param {String} name The name of the attribute to check.
387 * @return {boolean} true if an attribute with the given name has been added, false if it hasn't. This method will return true for lazily added attributes.
389 attrAdded: function(name) {
390 return !!this._state.get(name, ADDED);
394 * Updates the configuration of an attribute which has already been added.
396 * The properties which can be modified through this interface are limited
397 * to the following subset of attributes, which can be safely modified
398 * after a value has already been set on the attribute: readOnly, writeOnce,
399 * broadcast and getter.
402 * @param {String} name The name of the attribute whose configuration is to be updated.
403 * @param {Object} config An object with configuration property/value pairs, specifying the configuration properties to modify.
405 modifyAttr: function(name, config) {
406 var host = this, // help compression
409 if (host.attrAdded(name)) {
411 if (host._isLazyAttr(name)) {
412 host._addLazyAttr(name);
416 for (prop in config) {
417 if (MODIFIABLE[prop] && config.hasOwnProperty(prop)) {
418 state.add(name, prop, config[prop]);
420 // If we reconfigured broadcast, need to republish
421 if (prop === BROADCAST) {
422 state.remove(name, PUBLISHED);
431 * Removes an attribute from the host object
434 * @param {String} name The name of the attribute to be removed.
436 removeAttr: function(name) {
437 this._state.removeAll(name);
441 * Returns the current value of the attribute. If the attribute
442 * has been configured with a 'getter' function, this method will delegate
443 * to the 'getter' to obtain the value of the attribute.
447 * @param {String} name The name of the attribute. If the value of the attribute is an Object,
448 * dot notation can be used to obtain the value of a property of the object (e.g. <code>get("x.y.z")</code>)
450 * @return {Any} The value of the attribute
452 get : function(name) {
453 return this._getAttr(name);
457 * Checks whether or not the attribute is one which has been
458 * added lazily and still requires initialization.
460 * @method _isLazyAttr
462 * @param {String} name The name of the attribute
463 * @return {boolean} true if it's a lazily added attribute, false otherwise.
465 _isLazyAttr: function(name) {
466 return this._state.get(name, LAZY);
470 * Finishes initializing an attribute which has been lazily added.
472 * @method _addLazyAttr
474 * @param {Object} name The name of the attribute
476 _addLazyAttr: function(name) {
477 var state = this._state,
478 lazyCfg = state.get(name, LAZY);
480 state.add(name, IS_LAZY_ADD, true);
481 state.remove(name, LAZY);
482 this.addAttr(name, lazyCfg);
486 * Sets the value of an attribute.
491 * @param {String} name The name of the attribute. If the
492 * current value of the attribute is an Object, dot notation can be used
493 * to set the value of a property within the object (e.g. <code>set("x.y.z", 5)</code>).
495 * @param {Any} value The value to set the attribute to.
497 * @param {Object} opts (Optional) Optional event data to be mixed into
498 * the event facade passed to subscribers of the attribute's change event. This
499 * can be used as a flexible way to identify the source of a call to set, allowing
500 * the developer to distinguish between set called internally by the host, vs.
501 * set called externally by the application developer.
503 * @return {Object} A reference to the host object.
505 set : function(name, val, opts) {
506 return this._setAttr(name, val, opts);
510 * Resets the attribute (or all attributes) to its initial value, as long as
511 * the attribute is not readOnly, or writeOnce.
514 * @param {String} name Optional. The name of the attribute to reset. If omitted, all attributes are reset.
515 * @return {Object} A reference to the host object.
518 reset : function(name) {
519 var host = this, // help compression
523 if (host._isLazyAttr(name)) {
524 host._addLazyAttr(name);
526 host.set(name, host._state.get(name, INIT_VALUE));
528 added = host._state.data.added;
529 Y.each(added, function(v, n) {
537 * Allows setting of readOnly/writeOnce attributes. See <a href="#method_set">set</a> for argument details.
543 * @param {String} name The name of the attribute.
544 * @param {Any} val The value to set the attribute to.
545 * @param {Object} opts (Optional) Optional event data to be mixed into
546 * the event facade passed to subscribers of the attribute's change event.
547 * @return {Object} A reference to the host object.
549 _set : function(name, val, opts) {
550 return this._setAttr(name, val, opts, true);
554 * Provides the common implementation for the public get method,
555 * allowing Attribute hosts to over-ride either method.
557 * See <a href="#method_get">get</a> for argument details.
563 * @param {String} name The name of the attribute.
564 * @return {Any} The value of the attribute.
566 _getAttr : function(name) {
567 var host = this, // help compression
575 if (name.indexOf(DOT) !== -1) {
576 path = name.split(DOT);
580 // On Demand - Should be rare - handles out of order valueFn references
581 if (host._tCfgs && host._tCfgs[name]) {
583 cfg[name] = host._tCfgs[name];
584 delete host._tCfgs[name];
585 host._addAttrs(cfg, host._tVals);
589 if (host._isLazyAttr(name)) {
590 host._addLazyAttr(name);
593 val = host._getStateVal(name);
594 getter = state.get(name, GETTER);
596 val = (getter) ? getter.call(host, val, fullName) : val;
597 val = (path) ? O.getValue(val, path) : val;
603 * Provides the common implementation for the public set and protected _set methods.
605 * See <a href="#method_set">set</a> for argument details.
611 * @param {String} name The name of the attribute.
612 * @param {Any} value The value to set the attribute to.
613 * @param {Object} opts (Optional) Optional event data to be mixed into
614 * the event facade passed to subscribers of the attribute's change event.
615 * @param {boolean} force If true, allows the caller to set values for
616 * readOnly or writeOnce attributes which have already been set.
618 * @return {Object} A reference to the host object.
620 _setAttr : function(name, val, opts, force) {
623 stateProxy = this._stateProxy,
630 if (name.indexOf(DOT) !== -1) {
632 path = name.split(DOT);
636 if (this._isLazyAttr(name)) {
637 this._addLazyAttr(name);
640 initialSet = (!data.value || !(name in data.value));
642 if (stateProxy && name in stateProxy && !this._state.get(name, BYPASS_PROXY)) {
643 // TODO: Value is always set for proxy. Can we do any better? Maybe take a snapshot as the initial value for the first call to set?
647 if (this._requireAddAttr && !this.attrAdded(name)) {
650 if (!initialSet && !force) {
652 if (state.get(name, WRITE_ONCE)) {
656 if (state.get(name, READ_ONLY)) {
662 // Don't need currVal if initialSet (might fail in custom getter if it always expects a non-undefined/non-null value)
664 currVal = this.get(name);
668 val = O.setValue(Y.clone(currVal), path, val);
670 if (val === undefined) {
676 if (state.get(name, INITIALIZING)) {
677 this._setAttrVal(name, strPath, currVal, val);
679 this._fireAttrChange(name, strPath, currVal, val, opts);
689 * Utility method to help setup the event payload and fire the attribute change event.
691 * @method _fireAttrChange
693 * @param {String} attrName The name of the attribute
694 * @param {String} subAttrName The full path of the property being changed,
695 * if this is a sub-attribute value being change. Otherwise null.
696 * @param {Any} currVal The current value of the attribute
697 * @param {Any} newVal The new value of the attribute
698 * @param {Object} opts Any additional event data to mix into the attribute change event's event facade.
700 _fireAttrChange : function(attrName, subAttrName, currVal, newVal, opts) {
702 eventName = attrName + CHANGE,
706 if (!state.get(attrName, PUBLISHED)) {
707 host.publish(eventName, {
709 defaultFn:host._defAttrChangeFn,
711 broadcast : state.get(attrName, BROADCAST)
713 state.add(attrName, PUBLISHED, true);
716 facade = (opts) ? Y.merge(opts) : host._ATTR_E_FACADE;
718 facade.type = eventName;
719 facade.attrName = attrName;
720 facade.subAttrName = subAttrName;
721 facade.prevVal = currVal;
722 facade.newVal = newVal;
728 * Default function for attribute change events.
731 * @method _defAttrChangeFn
732 * @param {EventFacade} e The event object for attribute change events.
734 _defAttrChangeFn : function(e) {
735 if (!this._setAttrVal(e.attrName, e.subAttrName, e.prevVal, e.newVal)) {
736 // Prevent "after" listeners from being invoked since nothing changed.
737 e.stopImmediatePropagation();
739 e.newVal = this._getStateVal(e.attrName);
744 * Gets the stored value for the attribute, from either the
745 * internal state object, or the state proxy if it exits
747 * @method _getStateVal
749 * @param {String} name The name of the attribute
750 * @return {Any} The stored value of the attribute
752 _getStateVal : function(name) {
753 var stateProxy = this._stateProxy;
754 return stateProxy && (name in stateProxy) && !this._state.get(name, BYPASS_PROXY) ? stateProxy[name] : this._state.get(name, VALUE);
758 * Sets the stored value for the attribute, in either the
759 * internal state object, or the state proxy if it exits
761 * @method _setStateVal
763 * @param {String} name The name of the attribute
764 * @param {Any} value The value of the attribute
766 _setStateVal : function(name, value) {
767 var stateProxy = this._stateProxy;
768 if (stateProxy && (name in stateProxy) && !this._state.get(name, BYPASS_PROXY)) {
769 stateProxy[name] = value;
771 this._state.add(name, VALUE, value);
776 * Updates the stored value of the attribute in the privately held State object,
777 * if validation and setter passes.
779 * @method _setAttrVal
781 * @param {String} attrName The attribute name.
782 * @param {String} subAttrName The sub-attribute name, if setting a sub-attribute property ("x.y.z").
783 * @param {Any} prevVal The currently stored value of the attribute.
784 * @param {Any} newVal The value which is going to be stored.
786 * @return {booolean} true if the new attribute value was stored, false if not.
788 _setAttrVal : function(attrName, subAttrName, prevVal, newVal) {
794 validator = state.get(attrName, VALIDATOR),
795 setter = state.get(attrName, SETTER),
796 initializing = state.get(attrName, INITIALIZING),
797 prevValRaw = this._getStateVal(attrName),
799 name = subAttrName || attrName,
804 valid = validator.call(host, newVal, name);
806 if (!valid && initializing) {
807 newVal = state.get(attrName, DEF_VALUE);
808 valid = true; // Assume it's valid, for perf.
812 if (!validator || valid) {
814 retVal = setter.call(host, newVal, name);
816 if (retVal === INVALID_VALUE) {
818 } else if (retVal !== undefined){
824 if(!subAttrName && (newVal === prevValRaw) && !Lang.isObject(newVal)) {
828 if (state.get(attrName, INIT_VALUE) === undefined) {
829 state.add(attrName, INIT_VALUE, newVal);
831 host._setStateVal(attrName, newVal);
843 * Sets multiple attribute values.
846 * @param {Object} attrs An object with attributes name/value pairs.
847 * @return {Object} A reference to the host object.
850 setAttrs : function(attrs, opts) {
851 return this._setAttrs(attrs, opts);
855 * Implementation behind the public setAttrs method, to set multiple attribute values.
859 * @param {Object} attrs An object with attributes name/value pairs.
860 * @return {Object} A reference to the host object.
863 _setAttrs : function(attrs, opts) {
864 for (var attr in attrs) {
865 if ( attrs.hasOwnProperty(attr) ) {
866 this.set(attr, attrs[attr]);
873 * Gets multiple attribute values.
876 * @param {Array | boolean} attrs Optional. An array of attribute names. If omitted, all attribute values are
877 * returned. If set to true, all attributes modified from their initial values are returned.
878 * @return {Object} An object with attribute name/value pairs.
880 getAttrs : function(attrs) {
881 return this._getAttrs(attrs);
885 * Implementation behind the public getAttrs method, to get multiple attribute values.
889 * @param {Array | boolean} attrs Optional. An array of attribute names. If omitted, all attribute values are
890 * returned. If set to true, all attributes modified from their initial values are returned.
891 * @return {Object} An object with attribute name/value pairs.
893 _getAttrs : function(attrs) {
897 modifiedOnly = (attrs === true);
899 attrs = (attrs && !modifiedOnly) ? attrs : O.keys(host._state.data.added);
901 for (i = 0, l = attrs.length; i < l; i++) {
902 // Go through get, to honor cloning/normalization
904 val = host.get(attr);
906 if (!modifiedOnly || host._getStateVal(attr) != host._state.get(attr, INIT_VALUE)) {
907 o[attr] = host.get(attr);
915 * Configures a group of attributes, and sets initial values.
918 * <strong>NOTE:</strong> This method does not isolate the configuration object by merging/cloning.
919 * The caller is responsible for merging/cloning the configuration object if required.
925 * @param {Object} cfgs An object with attribute name/configuration pairs.
926 * @param {Object} values An object with attribute name/value pairs, defining the initial values to apply.
927 * Values defined in the cfgs argument will be over-written by values in this argument unless defined as read only.
928 * @param {boolean} lazy Whether or not to delay the intialization of these attributes until the first call to get/set.
929 * Individual attributes can over-ride this behavior by defining a lazyAdd configuration property in their configuration.
930 * See <a href="#method_addAttr">addAttr</a>.
932 * @return {Object} A reference to the host object.
934 addAttrs : function(cfgs, values, lazy) {
935 var host = this; // help compression
938 host._tVals = host._normAttrVals(values);
939 host._addAttrs(cfgs, host._tVals, lazy);
940 host._tCfgs = host._tVals = null;
947 * Implementation behind the public addAttrs method.
949 * This method is invoked directly by get if it encounters a scenario
950 * in which an attribute's valueFn attempts to obtain the
951 * value an attribute in the same group of attributes, which has not yet
952 * been added (on demand initialization).
956 * @param {Object} cfgs An object with attribute name/configuration pairs.
957 * @param {Object} values An object with attribute name/value pairs, defining the initial values to apply.
958 * Values defined in the cfgs argument will be over-written by values in this argument unless defined as read only.
959 * @param {boolean} lazy Whether or not to delay the intialization of these attributes until the first call to get/set.
960 * Individual attributes can over-ride this behavior by defining a lazyAdd configuration property in their configuration.
961 * See <a href="#method_addAttr">addAttr</a>.
963 _addAttrs : function(cfgs, values, lazy) {
964 var host = this, // help compression
970 if (cfgs.hasOwnProperty(attr)) {
972 // Not Merging. Caller is responsible for isolating configs
973 attrCfg = cfgs[attr];
974 attrCfg.defaultValue = attrCfg.value;
976 // Handle simple, complex and user values, accounting for read-only
977 value = host._getAttrInitVal(attr, attrCfg, host._tVals);
979 if (value !== undefined) {
980 attrCfg.value = value;
983 if (host._tCfgs[attr]) {
984 delete host._tCfgs[attr];
987 host.addAttr(attr, attrCfg, lazy);
993 * Utility method to protect an attribute configuration
994 * hash, by merging the entire object and the individual
995 * attr config objects.
997 * @method _protectAttrs
999 * @param {Object} attrs A hash of attribute to configuration object pairs.
1000 * @return {Object} A protected version of the attrs argument.
1002 _protectAttrs : function(attrs) {
1004 attrs = Y.merge(attrs);
1005 for (var attr in attrs) {
1006 if (attrs.hasOwnProperty(attr)) {
1007 attrs[attr] = Y.merge(attrs[attr]);
1015 * Utility method to normalize attribute values. The base implementation
1016 * simply merges the hash to protect the original.
1018 * @method _normAttrVals
1019 * @param {Object} valueHash An object with attribute name/value pairs
1025 _normAttrVals : function(valueHash) {
1026 return (valueHash) ? Y.merge(valueHash) : null;
1030 * Returns the initial value of the given attribute from
1031 * either the default configuration provided, or the
1032 * over-ridden value if it exists in the set of initValues
1033 * provided and the attribute is not read-only.
1035 * @param {String} attr The name of the attribute
1036 * @param {Object} cfg The attribute configuration object
1037 * @param {Object} initValues The object with simple and complex attribute name/value pairs returned from _normAttrVals
1039 * @return {Any} The initial value of the attribute.
1041 * @method _getAttrInitVal
1044 _getAttrInitVal : function(attr, cfg, initValues) {
1046 // init value is provided by the user if it exists, else, provided by the config
1047 var val = (!cfg[READ_ONLY] && initValues && initValues.hasOwnProperty(attr)) ?
1048 val = initValues[attr] :
1050 cfg[VALUE_FN].call(this) :
1058 // Basic prototype augment - no lazy constructor invocation.
1059 Y.mix(Attribute, EventTarget, false, null, 1);
1061 Y.Attribute = Attribute;
1064 }, '3.0.0' ,{requires:['event-custom']});