|
1 YUI.add('attribute-base', 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-base submodule provides core attribute handling support, with everything |
|
15 * aside from complex attribute handling in the provider's constructor. |
|
16 * |
|
17 * @module attribute |
|
18 * @submodule attribute-base |
|
19 */ |
|
20 |
|
21 /** |
|
22 * <p> |
|
23 * Attribute provides configurable attribute support along with attribute change events. It is designed to be |
|
24 * augmented on to a host class, and provides the host with the ability to configure attributes to store and retrieve state, |
|
25 * along with attribute change events. |
|
26 * </p> |
|
27 * <p>For example, attributes added to the host can be configured:</p> |
|
28 * <ul> |
|
29 * <li>As read only.</li> |
|
30 * <li>As write once.</li> |
|
31 * <li>With a setter function, which can be used to manipulate |
|
32 * values passed to Attribute's <a href="#method_set">set</a> method, before they are stored.</li> |
|
33 * <li>With a getter function, which can be used to manipulate stored values, |
|
34 * before they are returned by Attribute's <a href="#method_get">get</a> method.</li> |
|
35 * <li>With a validator function, to validate values before they are stored.</li> |
|
36 * </ul> |
|
37 * |
|
38 * <p>See the <a href="#method_addAttr">addAttr</a> method, for the complete set of configuration |
|
39 * options available for attributes.</p> |
|
40 * |
|
41 * <p><strong>NOTE:</strong> Most implementations will be better off extending the <a href="Base.html">Base</a> class, |
|
42 * instead of augmenting Attribute directly. Base augments Attribute and will handle the initial configuration |
|
43 * of attributes for derived classes, accounting for values passed into the constructor.</p> |
|
44 * |
|
45 * @class Attribute |
|
46 * @param attrs {Object} The attributes to add during construction (passed through to <a href="#method_addAttrs">addAttrs</a>). |
|
47 * These can also be defined on the constructor being augmented with Attribute by defining the ATTRS property on the constructor. |
|
48 * @param values {Object} The initial attribute values to apply (passed through to <a href="#method_addAttrs">addAttrs</a>). |
|
49 * These are not merged/cloned. The caller is responsible for isolating user provided values if required. |
|
50 * @param lazy {boolean} Whether or not to add attributes lazily (passed through to <a href="#method_addAttrs">addAttrs</a>). |
|
51 * @uses AttributeCore |
|
52 * @uses AttributeObservable |
|
53 * @uses EventTarget |
|
54 * @uses AttributeExtras |
|
55 */ |
|
56 function Attribute() { |
|
57 Y.AttributeCore.apply(this, arguments); |
|
58 Y.AttributeObservable.apply(this, arguments); |
|
59 Y.AttributeExtras.apply(this, arguments); |
|
60 } |
|
61 |
|
62 Y.mix(Attribute, Y.AttributeCore, false, null, 1); |
|
63 Y.mix(Attribute, Y.AttributeExtras, false, null, 1); |
|
64 |
|
65 // Needs to be `true`, to overwrite methods from AttributeCore |
|
66 Y.mix(Attribute, Y.AttributeObservable, true, null, 1); |
|
67 |
|
68 /** |
|
69 * <p>The value to return from an attribute setter in order to prevent the set from going through.</p> |
|
70 * |
|
71 * <p>You can return this value from your setter if you wish to combine validator and setter |
|
72 * functionality into a single setter function, which either returns the massaged value to be stored or |
|
73 * AttributeCore.INVALID_VALUE to prevent invalid values from being stored.</p> |
|
74 * |
|
75 * @property INVALID_VALUE |
|
76 * @type Object |
|
77 * @static |
|
78 * @final |
|
79 */ |
|
80 Attribute.INVALID_VALUE = Y.AttributeCore.INVALID_VALUE; |
|
81 |
|
82 /** |
|
83 * The list of properties which can be configured for |
|
84 * each attribute (e.g. setter, getter, writeOnce etc.). |
|
85 * |
|
86 * This property is used internally as a whitelist for faster |
|
87 * Y.mix operations. |
|
88 * |
|
89 * @property _ATTR_CFG |
|
90 * @type Array |
|
91 * @static |
|
92 * @protected |
|
93 */ |
|
94 Attribute._ATTR_CFG = Y.AttributeCore._ATTR_CFG.concat(Y.AttributeObservable._ATTR_CFG); |
|
95 |
|
96 /** |
|
97 * Utility method to protect an attribute configuration hash, by merging the |
|
98 * entire object and the individual attr config objects. |
|
99 * |
|
100 * @method protectAttrs |
|
101 * @static |
|
102 * @param {Object} attrs A hash of attribute to configuration object pairs. |
|
103 * @return {Object} A protected version of the `attrs` argument. |
|
104 */ |
|
105 Attribute.protectAttrs = Y.AttributeCore.protectAttrs; |
|
106 |
|
107 Y.Attribute = Attribute; |
|
108 |
|
109 |
|
110 }, '@VERSION@', {"requires": ["attribute-core", "attribute-observable", "attribute-extras"]}); |