[ 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 Y.log('Attribute modifyAttr:' + name + ' has not been added. Use addAttr to add the attribute', 'warn', 'attribute'); 96 } 97 }, 98 99 /** 100 * Removes an attribute from the host object 101 * 102 * @method removeAttr 103 * @param {String} name The name of the attribute to be removed. 104 */ 105 removeAttr: function(name) { 106 this._state.removeAll(name); 107 }, 108 109 /** 110 * Resets the attribute (or all attributes) to its initial value, as long as 111 * the attribute is not readOnly, or writeOnce. 112 * 113 * @method reset 114 * @param {String} name Optional. The name of the attribute to reset. If omitted, all attributes are reset. 115 * @return {Object} A reference to the host object. 116 * @chainable 117 */ 118 reset : function(name) { 119 var host = this; // help compression 120 121 if (name) { 122 if (host._isLazyAttr(name)) { 123 host._addLazyAttr(name); 124 } 125 host.set(name, host._state.get(name, INIT_VALUE)); 126 } else { 127 Y.Object.each(host._state.data, function(v, n) { 128 host.reset(n); 129 }); 130 } 131 return host; 132 }, 133 134 /** 135 * Returns an object with the configuration properties (and value) 136 * for the given attribute. If attrName is not provided, returns the 137 * configuration properties for all attributes. 138 * 139 * @method _getAttrCfg 140 * @protected 141 * @param {String} name Optional. The attribute name. If not provided, the method will return the configuration for all attributes. 142 * @return {Object} The configuration properties for the given attribute, or all attributes. 143 */ 144 _getAttrCfg : function(name) { 145 var o, 146 state = this._state; 147 148 if (name) { 149 o = state.getAll(name) || {}; 150 } else { 151 o = {}; 152 Y.each(state.data, function(v, n) { 153 o[n] = state.getAll(n); 154 }); 155 } 156 157 return o; 158 } 159 }; 160 161 Y.AttributeExtras = AttributeExtras; 162 163 164 }, '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 |