[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
1 /* 2 YUI 3.17.2 (build 9c3c78e) 3 Copyright 2014 Yahoo! Inc. All rights reserved. 4 Licensed under the BSD License. 5 http://yuilibrary.com/license/ 6 */ 7 8 YUI.add('attribute-extras', function (Y, NAME) { 9 10 /** 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 15 * store state. 16 * 17 * @module attribute 18 */ 19 20 /** 21 * The attribute-extras submodule provides less commonly used attribute methods, and can 22 * be augmented/mixed into an implemention which used attribute-core. 23 * 24 * @module attribute 25 * @submodule attribute-extras 26 */ 27 var BROADCAST = "broadcast", 28 PUBLISHED = "published", 29 INIT_VALUE = "initValue", 30 31 MODIFIABLE = { 32 readOnly:1, 33 writeOnce:1, 34 getter:1, 35 broadcast:1 36 }; 37 38 /** 39 * A augmentable implementation for AttributeCore, providing less frequently used 40 * methods for Attribute management such as modifyAttrs(), removeAttr and reset() 41 * 42 * @class AttributeExtras 43 * @extensionfor AttributeCore 44 */ 45 function AttributeExtras() {} 46 47 AttributeExtras.prototype = { 48 49 /** 50 * Updates the configuration of an attribute which has already been added. 51 * <p> 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: 55 * </p> 56 * <dl> 57 * <dt>readOnly;</dt> 58 * <dt>writeOnce;</dt> 59 * <dt>broadcast; and</dt> 60 * <dt>getter.</dt> 61 * </dl> 62 * <p> 63 * Note: New attributes cannot be added using this interface. New attributes must be 64 * added using {{#crossLink "AttributeCore/addAttr:method"}}addAttr{{/crossLink}}, or an 65 * appropriate manner for a class which utilises Attributes (e.g. the 66 * {{#crossLink "Base/ATTRS:property"}}ATTRS{{/crossLink}} property in 67 * {{#crossLink "Base"}}Base{{/crossLink}}). 68 * </p> 69 * @method modifyAttr 70 * @param {String} name The name of the attribute whose configuration is to be updated. 71 * @param {Object} config An object with configuration property/value pairs, specifying the configuration properties to modify. 72 */ 73 modifyAttr: function(name, config) { 74 var host = this, // help compression 75 prop, state; 76 77 if (host.attrAdded(name)) { 78 79 if (host._isLazyAttr(name)) { 80 host._addLazyAttr(name); 81 } 82 83 state = host._state; 84 for (prop in config) { 85 if (MODIFIABLE[prop] && config.hasOwnProperty(prop)) { 86 state.add(name, prop, config[prop]); 87 88 // If we reconfigured broadcast, need to republish 89 if (prop === BROADCAST) { 90 state.remove(name, PUBLISHED); 91 } 92 } 93 } 94 } else { 95 } 96 }, 97 98 /** 99 * Removes an attribute from the host object 100 * 101 * @method removeAttr 102 * @param {String} name The name of the attribute to be removed. 103 */ 104 removeAttr: function(name) { 105 this._state.removeAll(name); 106 }, 107 108 /** 109 * Resets the attribute (or all attributes) to its initial value, as long as 110 * the attribute is not readOnly, or writeOnce. 111 * 112 * @method reset 113 * @param {String} name Optional. The name of the attribute to reset. If omitted, all attributes are reset. 114 * @return {Object} A reference to the host object. 115 * @chainable 116 */ 117 reset : function(name) { 118 var host = this; // help compression 119 120 if (name) { 121 if (host._isLazyAttr(name)) { 122 host._addLazyAttr(name); 123 } 124 host.set(name, host._state.get(name, INIT_VALUE)); 125 } else { 126 Y.Object.each(host._state.data, function(v, n) { 127 host.reset(n); 128 }); 129 } 130 return host; 131 }, 132 133 /** 134 * Returns an object with the configuration properties (and value) 135 * for the given attribute. If attrName is not provided, returns the 136 * configuration properties for all attributes. 137 * 138 * @method _getAttrCfg 139 * @protected 140 * @param {String} name Optional. The attribute name. If not provided, the method will return the configuration for all attributes. 141 * @return {Object} The configuration properties for the given attribute, or all attributes. 142 */ 143 _getAttrCfg : function(name) { 144 var o, 145 state = this._state; 146 147 if (name) { 148 o = state.getAll(name) || {}; 149 } else { 150 o = {}; 151 Y.each(state.data, function(v, n) { 152 o[n] = state.getAll(n); 153 }); 154 } 155 156 return o; 157 } 158 }; 159 160 Y.AttributeExtras = AttributeExtras; 161 162 163 }, '3.17.2', {"requires": ["oop"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |