1YUI.add('attribute-extras', function (Y, NAME) { 2 3 /** 4 * The attribute module provides an augmentable Attribute implementation, which 5 * adds configurable attributes and attribute change events to the class being 6 * augmented. It also provides a State class, which is used internally by Attribute, 7 * but can also be used independently to provide a name/property/value data structure to 8 * store state. 9 * 10 * @module attribute 11 */ 12 13 /** 14 * The attribute-extras submodule provides less commonly used attribute methods, and can 15 * be augmented/mixed into an implemention which used attribute-core. 16 * 17 * @module attribute 18 * @submodule attribute-extras 19 */ 20 var BROADCAST = "broadcast", 21 PUBLISHED = "published", 22 INIT_VALUE = "initValue", 23 24 MODIFIABLE = { 25 readOnly:1, 26 writeOnce:1, 27 getter:1, 28 broadcast:1 29 }; 30 31 /** 32 * A augmentable implementation for AttributeCore, providing less frequently used 33 * methods for Attribute management such as modifyAttrs(), removeAttr and reset() 34 * 35 * @class AttributeExtras 36 * @extensionfor AttributeCore 37 */ 38 function AttributeExtras() {} 39 40 AttributeExtras.prototype = { 41 42 /** 43 * Updates the configuration of an attribute which has already been added. 44 * <p> 45 * The properties which can be modified through this interface are limited 46 * to the following subset of attributes, which can be safely modified 47 * after a value has already been set on the attribute: 48 * </p> 49 * <dl> 50 * <dt>readOnly;</dt> 51 * <dt>writeOnce;</dt> 52 * <dt>broadcast; and</dt> 53 * <dt>getter.</dt> 54 * </dl> 55 * <p> 56 * Note: New attributes cannot be added using this interface. New attributes must be 57 * added using {{#crossLink "AttributeCore/addAttr:method"}}addAttr{{/crossLink}}, or an 58 * appropriate manner for a class which utilises Attributes (e.g. the 59 * {{#crossLink "Base/ATTRS:property"}}ATTRS{{/crossLink}} property in 60 * {{#crossLink "Base"}}Base{{/crossLink}}). 61 * </p> 62 * @method modifyAttr 63 * @param {String} name The name of the attribute whose configuration is to be updated. 64 * @param {Object} config An object with configuration property/value pairs, specifying the configuration properties to modify. 65 */ 66 modifyAttr: function(name, config) { 67 var host = this, // help compression 68 prop, state; 69 70 if (host.attrAdded(name)) { 71 72 if (host._isLazyAttr(name)) { 73 host._addLazyAttr(name); 74 } 75 76 state = host._state; 77 for (prop in config) { 78 if (MODIFIABLE[prop] && config.hasOwnProperty(prop)) { 79 state.add(name, prop, config[prop]); 80 81 // If we reconfigured broadcast, need to republish 82 if (prop === BROADCAST) { 83 state.remove(name, PUBLISHED); 84 } 85 } 86 } 87 } else { 88 } 89 }, 90 91 /** 92 * Removes an attribute from the host object 93 * 94 * @method removeAttr 95 * @param {String} name The name of the attribute to be removed. 96 */ 97 removeAttr: function(name) { 98 this._state.removeAll(name); 99 }, 100 101 /** 102 * Resets the attribute (or all attributes) to its initial value, as long as 103 * the attribute is not readOnly, or writeOnce. 104 * 105 * @method reset 106 * @param {String} name Optional. The name of the attribute to reset. If omitted, all attributes are reset. 107 * @return {Object} A reference to the host object. 108 * @chainable 109 */ 110 reset : function(name) { 111 var host = this; // help compression 112 113 if (name) { 114 if (host._isLazyAttr(name)) { 115 host._addLazyAttr(name); 116 } 117 host.set(name, host._state.get(name, INIT_VALUE)); 118 } else { 119 Y.Object.each(host._state.data, function(v, n) { 120 host.reset(n); 121 }); 122 } 123 return host; 124 }, 125 126 /** 127 * Returns an object with the configuration properties (and value) 128 * for the given attribute. If attrName is not provided, returns the 129 * configuration properties for all attributes. 130 * 131 * @method _getAttrCfg 132 * @protected 133 * @param {String} name Optional. The attribute name. If not provided, the method will return the configuration for all attributes. 134 * @return {Object} The configuration properties for the given attribute, or all attributes. 135 */ 136 _getAttrCfg : function(name) { 137 var o, 138 state = this._state; 139 140 if (name) { 141 o = state.getAll(name) || {}; 142 } else { 143 o = {}; 144 Y.each(state.data, function(v, n) { 145 o[n] = state.getAll(n); 146 }); 147 } 148 149 return o; 150 } 151 }; 152 153 Y.AttributeExtras = AttributeExtras; 154 155 156}, 'patched-v3.18.7', {"requires": ["oop"]});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.