2 YUI 3.13.0 (build 508226d)
3 Copyright 2013 Yahoo! Inc. All rights reserved.
4 Licensed under the BSD License.
5 http://yuilibrary.com/license/
8 YUI.add('attribute-extras', function (Y, NAME) {
11 * The attribute module provides an augmentable Attribute implementation, which
12 * adds configurable attributes and attribute change events to the class being
13 * augmented. It also provides a State class, which is used internally by Attribute,
14 * but can also be used independently to provide a name/property/value data structure to
21 * The attribute-extras submodule provides less commonly used attribute methods, and can
22 * be augmented/mixed into an implemention which used attribute-core.
25 * @submodule attribute-extras
27 var BROADCAST = "broadcast",
28 PUBLISHED = "published",
29 INIT_VALUE = "initValue",
39 * A augmentable implementation for AttributeCore, providing less frequently used
40 * methods for Attribute management such as modifyAttrs(), removeAttr and reset()
42 * @class AttributeExtras
43 * @extensionfor AttributeCore
45 function AttributeExtras() {}
47 AttributeExtras.prototype = {
50 * Updates the configuration of an attribute which has already been added.
52 * The properties which can be modified through this interface are limited
53 * to the following subset of attributes, which can be safely modified
54 * after a value has already been set on the attribute: readOnly, writeOnce,
55 * broadcast and getter.
58 * @param {String} name The name of the attribute whose configuration is to be updated.
59 * @param {Object} config An object with configuration property/value pairs, specifying the configuration properties to modify.
61 modifyAttr: function(name, config) {
62 var host = this, // help compression
65 if (host.attrAdded(name)) {
67 if (host._isLazyAttr(name)) {
68 host._addLazyAttr(name);
72 for (prop in config) {
73 if (MODIFIABLE[prop] && config.hasOwnProperty(prop)) {
74 state.add(name, prop, config[prop]);
76 // If we reconfigured broadcast, need to republish
77 if (prop === BROADCAST) {
78 state.remove(name, PUBLISHED);
84 if (!host.attrAdded(name)) {Y.log('Attribute modifyAttr:' + name + ' has not been added. Use addAttr to add the attribute', 'warn', 'attribute');}
85 /*jshint maxlen:150 */
89 * Removes an attribute from the host object
92 * @param {String} name The name of the attribute to be removed.
94 removeAttr: function(name) {
95 this._state.removeAll(name);
99 * Resets the attribute (or all attributes) to its initial value, as long as
100 * the attribute is not readOnly, or writeOnce.
103 * @param {String} name Optional. The name of the attribute to reset. If omitted, all attributes are reset.
104 * @return {Object} A reference to the host object.
107 reset : function(name) {
108 var host = this; // help compression
111 if (host._isLazyAttr(name)) {
112 host._addLazyAttr(name);
114 host.set(name, host._state.get(name, INIT_VALUE));
116 Y.each(host._state.data, function(v, n) {
124 * Returns an object with the configuration properties (and value)
125 * for the given attribute. If attrName is not provided, returns the
126 * configuration properties for all attributes.
128 * @method _getAttrCfg
130 * @param {String} name Optional. The attribute name. If not provided, the method will return the configuration for all attributes.
131 * @return {Object} The configuration properties for the given attribute, or all attributes.
133 _getAttrCfg : function(name) {
138 o = state.getAll(name) || {};
141 Y.each(state.data, function(v, n) {
142 o[n] = state.getAll(n);
150 Y.AttributeExtras = AttributeExtras;
153 }, '3.13.0', {"requires": ["oop"]});