~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/attribute-base/attribute-base.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('attribute-base', function(Y) {
8
 
 
9
 
    /**
10
 
     * The State class maintains state for a collection of named items, with 
11
 
     * a varying number of properties defined.
12
 
     *
13
 
     * It avoids the need to create a separate class for the item, and separate instances 
14
 
     * of these classes for each item, by storing the state in a 2 level hash table, 
15
 
     * improving performance when the number of items is likely to be large.
16
 
     *
17
 
     * @constructor
18
 
     * @class State
19
 
     */
20
 
    Y.State = function() { 
21
 
        /**
22
 
         * Hash of attributes
23
 
         * @property data
24
 
         */
25
 
        this.data = {};
26
 
    };
27
 
 
28
 
    Y.State.prototype = {
29
 
 
30
 
        /**
31
 
         * Adds a property to an item.
32
 
         *
33
 
         * @method add
34
 
         * @param name {String} The name of the item.
35
 
         * @param key {String} The name of the property.
36
 
         * @param val {Any} The value of the property.
37
 
         */
38
 
        add : function(name, key, val) {
39
 
            var d = this.data;
40
 
            d[key] = d[key] || {};
41
 
            d[key][name] = val;
42
 
        },
43
 
 
44
 
        /**
45
 
         * Adds multiple properties to an item.
46
 
         *
47
 
         * @method addAll
48
 
         * @param name {String} The name of the item.
49
 
         * @param o {Object} A hash of property/value pairs.
50
 
         */
51
 
        addAll: function(name, o) {
52
 
            var key;
53
 
            for (key in o) {
54
 
                if (o.hasOwnProperty(key)) {
55
 
                    this.add(name, key, o[key]);
56
 
                }
57
 
            }
58
 
        },
59
 
 
60
 
        /**
61
 
         * Removes a property from an item.
62
 
         *
63
 
         * @method remove
64
 
         * @param name {String} The name of the item.
65
 
         * @param key {String} The property to remove.
66
 
         */
67
 
        remove: function(name, key) {
68
 
            var d = this.data;
69
 
            if (d[key] && (name in d[key])) {
70
 
                delete d[key][name];
71
 
            }
72
 
        },
73
 
 
74
 
        /**
75
 
         * Removes multiple properties from an item, or remove the item completely.
76
 
         *
77
 
         * @method removeAll
78
 
         * @param name {String} The name of the item.
79
 
         * @param o {Object|Array} Collection of properties to delete. If not provided, the entire item is removed.
80
 
         */
81
 
        removeAll: function(name, o) {
82
 
            var d = this.data;
83
 
 
84
 
            Y.each(o || d, function(v, k) {
85
 
                if(Y.Lang.isString(k)) {
86
 
                    this.remove(name, k);
87
 
                } else {
88
 
                    this.remove(name, v);
89
 
                }
90
 
            }, this);
91
 
        },
92
 
 
93
 
        /**
94
 
         * For a given item, returns the value of the property requested, or undefined if not found.
95
 
         *
96
 
         * @method get
97
 
         * @param name {String} The name of the item
98
 
         * @param key {String} Optional. The property value to retrieve.
99
 
         * @return {Any} The value of the supplied property.
100
 
         */
101
 
        get: function(name, key) {
102
 
            var d = this.data;
103
 
            return (d[key] && name in d[key]) ?  d[key][name] : undefined;
104
 
        },
105
 
 
106
 
        /**
107
 
         * For the given item, returns a disposable object with all of the
108
 
         * item's property/value pairs.
109
 
         *
110
 
         * @method getAll
111
 
         * @param name {String} The name of the item
112
 
         * @return {Object} An object with property/value pairs for the item.
113
 
         */
114
 
        getAll : function(name) {
115
 
            var d = this.data, o;
116
 
 
117
 
            Y.each(d, function(v, k) {
118
 
                if (name in d[k]) {
119
 
                    o = o || {};
120
 
                    o[k] = v[name];
121
 
                }
122
 
            }, this);
123
 
 
124
 
            return o;
125
 
        }
126
 
    };
127
 
    /**
128
 
     * The attribute module provides an augmentable Attribute implementation, which 
129
 
     * adds configurable attributes and attribute change events to the class being 
130
 
     * augmented. It also provides a State class, which is used internally by Attribute,
131
 
     * but can also be used independently to provide a name/property/value data structure to
132
 
     * store state.
133
 
     *
134
 
     * @module attribute
135
 
     */
136
 
 
137
 
    /**
138
 
     * The attribute-base submodule provides core attribute handling support, with everything
139
 
     * aside from complex attribute handling in the provider's constructor.
140
 
     *
141
 
     * @module attribute
142
 
     * @submodule attribute-base
143
 
     */
144
 
    var O = Y.Object,
145
 
        Lang = Y.Lang,
146
 
        EventTarget = Y.EventTarget,
147
 
 
148
 
        DOT = ".",
149
 
        CHANGE = "Change",
150
 
 
151
 
        // Externally configurable props
152
 
        GETTER = "getter",
153
 
        SETTER = "setter",
154
 
        READ_ONLY = "readOnly",
155
 
        WRITE_ONCE = "writeOnce",
156
 
        INIT_ONLY = "initOnly",
157
 
        VALIDATOR = "validator",
158
 
        VALUE = "value",
159
 
        VALUE_FN = "valueFn",
160
 
        BROADCAST = "broadcast",
161
 
        LAZY_ADD = "lazyAdd",
162
 
        BYPASS_PROXY = "_bypassProxy",
163
 
 
164
 
        // Used for internal state management
165
 
        ADDED = "added",
166
 
        INITIALIZING = "initializing",
167
 
        INIT_VALUE = "initValue",
168
 
        PUBLISHED = "published",
169
 
        DEF_VALUE = "defaultValue",
170
 
        LAZY = "lazy",
171
 
        IS_LAZY_ADD = "isLazyAdd",
172
 
 
173
 
        INVALID_VALUE,
174
 
 
175
 
        MODIFIABLE = {};
176
 
 
177
 
        // Properties which can be changed after the attribute has been added.
178
 
        MODIFIABLE[READ_ONLY] = 1;
179
 
        MODIFIABLE[WRITE_ONCE] = 1;
180
 
        MODIFIABLE[GETTER] = 1;
181
 
        MODIFIABLE[BROADCAST] = 1;
182
 
 
183
 
    /**
184
 
     * <p>
185
 
     * Attribute provides configurable attribute support along with attribute change events. It is designed to be 
186
 
     * augmented on to a host class, and provides the host with the ability to configure attributes to store and retrieve state, 
187
 
     * along with attribute change events.
188
 
     * </p>
189
 
     * <p>For example, attributes added to the host can be configured:</p>
190
 
     * <ul>
191
 
     *     <li>As read only.</li>
192
 
     *     <li>As write once.</li>
193
 
     *     <li>With a setter function, which can be used to manipulate
194
 
     *     values passed to Attribute's <a href="#method_set">set</a> method, before they are stored.</li>
195
 
     *     <li>With a getter function, which can be used to manipulate stored values,
196
 
     *     before they are returned by Attribute's <a href="#method_get">get</a> method.</li>
197
 
     *     <li>With a validator function, to validate values before they are stored.</li>
198
 
     * </ul>
199
 
     *
200
 
     * <p>See the <a href="#method_addAttr">addAttr</a> method, for the complete set of configuration
201
 
     * options available for attributes</p>.
202
 
     *
203
 
     * <p><strong>NOTE:</strong> Most implementations will be better off extending the <a href="Base.html">Base</a> class, 
204
 
     * instead of augmenting Attribute directly. Base augments Attribute and will handle the initial configuration 
205
 
     * of attributes for derived classes, accounting for values passed into the constructor.</p>
206
 
     *
207
 
     * @class Attribute
208
 
     * @param attrs {Object} The attributes to add during construction (passed through to <a href="#method_addAttrs">addAttrs</a>). These can also be defined on the constructor being augmented with Attribute by defining the ATTRS property on the constructor.
209
 
     * @param values {Object} The initial attribute values to apply (passed through to <a href="#method_addAttrs">addAttrs</a>). These are not merged/cloned. The caller is responsible for isolating user provided values if required.
210
 
     * @param lazy {boolean} Whether or not to add attributes lazily (passed through to <a href="#method_addAttrs">addAttrs</a>).
211
 
     * @uses EventTarget
212
 
     */
213
 
    function Attribute(attrs, values, lazy) {
214
 
 
215
 
        var host = this; // help compression
216
 
 
217
 
        // Perf tweak - avoid creating event literals if not required.
218
 
        host._ATTR_E_FACADE = {};
219
 
 
220
 
        EventTarget.call(host, {emitFacade:true});
221
 
 
222
 
        // _conf maintained for backwards compat
223
 
        host._conf = host._state = new Y.State();
224
 
 
225
 
        host._stateProxy = host._stateProxy || null;
226
 
        host._requireAddAttr = host._requireAddAttr || false;
227
 
 
228
 
        this._initAttrs(attrs, values, lazy);
229
 
    }
230
 
 
231
 
    /**
232
 
     * <p>The value to return from an attribute setter in order to prevent the set from going through.</p>
233
 
     *
234
 
     * <p>You can return this value from your setter if you wish to combine validator and setter 
235
 
     * functionality into a single setter function, which either returns the massaged value to be stored or 
236
 
     * Attribute.INVALID_VALUE to prevent invalid values from being stored.</p>
237
 
     *
238
 
     * @property INVALID_VALUE
239
 
     * @type Object
240
 
     * @static
241
 
     * @final
242
 
     */
243
 
    Attribute.INVALID_VALUE = {};
244
 
    INVALID_VALUE = Attribute.INVALID_VALUE;
245
 
 
246
 
    /**
247
 
     * The list of properties which can be configured for 
248
 
     * each attribute (e.g. setter, getter, writeOnce etc.).
249
 
     *
250
 
     * This property is used internally as a whitelist for faster
251
 
     * Y.mix operations.
252
 
     *
253
 
     * @property _ATTR_CFG
254
 
     * @type Array
255
 
     * @static
256
 
     * @protected
257
 
     */
258
 
    Attribute._ATTR_CFG = [SETTER, GETTER, VALIDATOR, VALUE, VALUE_FN, WRITE_ONCE, READ_ONLY, LAZY_ADD, BROADCAST, BYPASS_PROXY];
259
 
 
260
 
    Attribute.prototype = {
261
 
        /**
262
 
         * <p>
263
 
         * Adds an attribute with the provided configuration to the host object.
264
 
         * </p>
265
 
         * <p>
266
 
         * The config argument object supports the following properties:
267
 
         * </p>
268
 
         * 
269
 
         * <dl>
270
 
         *    <dt>value &#60;Any&#62;</dt>
271
 
         *    <dd>The initial value to set on the attribute</dd>
272
 
         *
273
 
         *    <dt>valueFn &#60;Function | String&#62;</dt>
274
 
         *    <dd>
275
 
         *    <p>A function, which will return the initial value to set on the attribute. This is useful
276
 
         *    for cases where the attribute configuration is defined statically, but needs to 
277
 
         *    reference the host instance ("this") to obtain an initial value. If both the value and valueFn properties are defined, 
278
 
         *    the value returned by the valueFn has precedence over the value property, unless it returns undefined, in which 
279
 
         *    case the value property is used.</p>
280
 
         *
281
 
         *    <p>valueFn can also be set to a string, representing the name of the instance method to be used to retrieve the value.</p>
282
 
         *    </dd>
283
 
         *
284
 
         *    <dt>readOnly &#60;boolean&#62;</dt>
285
 
         *    <dd>Whether or not the attribute is read only. Attributes having readOnly set to true
286
 
         *        cannot be modified by invoking the set method.</dd>
287
 
         *
288
 
         *    <dt>writeOnce &#60;boolean&#62; or &#60;string&#62;</dt>
289
 
         *    <dd>
290
 
         *        Whether or not the attribute is "write once". Attributes having writeOnce set to true, 
291
 
         *        can only have their values set once, be it through the default configuration, 
292
 
         *        constructor configuration arguments, or by invoking set.
293
 
         *        <p>The writeOnce attribute can also be set to the string "initOnly", in which case the attribute can only be set during initialization
294
 
         *        (when used with Base, this means it can only be set during construction)</p>
295
 
         *    </dd>
296
 
         *
297
 
         *    <dt>setter &#60;Function | String&#62;</dt>
298
 
         *    <dd>
299
 
         *    <p>The setter function used to massage or normalize the value passed to the set method for the attribute. 
300
 
         *    The value returned by the setter will be the final stored value. Returning
301
 
         *    <a href="#property_Attribute.INVALID_VALUE">Attribute.INVALID_VALUE</a>, from the setter will prevent
302
 
         *    the value from being stored.
303
 
         *    </p>
304
 
         *    
305
 
         *    <p>setter can also be set to a string, representing the name of the instance method to be used as the setter function.</p>
306
 
         *    </dd>
307
 
         *      
308
 
         *    <dt>getter &#60;Function | String&#62;</dt>
309
 
         *    <dd>
310
 
         *    <p>
311
 
         *    The getter function used to massage or normalize the value returned by the get method for the attribute.
312
 
         *    The value returned by the getter function is the value which will be returned to the user when they 
313
 
         *    invoke get.
314
 
         *    </p>
315
 
         *
316
 
         *    <p>getter can also be set to a string, representing the name of the instance method to be used as the getter function.</p>
317
 
         *    </dd>
318
 
         *
319
 
         *    <dt>validator &#60;Function | String&#62;</dt>
320
 
         *    <dd>
321
 
         *    <p>
322
 
         *    The validator function invoked prior to setting the stored value. Returning
323
 
         *    false from the validator function will prevent the value from being stored.
324
 
         *    </p>
325
 
         *    
326
 
         *    <p>validator can also be set to a string, representing the name of the instance method to be used as the validator function.</p>
327
 
         *    </dd>
328
 
         *    
329
 
         *    <dt>broadcast &#60;int&#62;</dt>
330
 
         *    <dd>If and how attribute change events for this attribute should be broadcast. See CustomEvent's <a href="CustomEvent.html#property_broadcast">broadcast</a> property for 
331
 
         *    valid values. By default attribute change events are not broadcast.</dd>
332
 
         *
333
 
         *    <dt>lazyAdd &#60;boolean&#62;</dt>
334
 
         *    <dd>Whether or not to delay initialization of the attribute until the first call to get/set it. 
335
 
         *    This flag can be used to over-ride lazy initialization on a per attribute basis, when adding multiple attributes through 
336
 
         *    the <a href="#method_addAttrs">addAttrs</a> method.</dd>
337
 
         *
338
 
         * </dl>
339
 
         *
340
 
         * <p>The setter, getter and validator are invoked with the value and name passed in as the first and second arguments, and with
341
 
         * the context ("this") set to the host object.</p>
342
 
         *
343
 
         * <p>Configuration properties outside of the list mentioned above are considered private properties used internally by attribute, and are not intended for public use.</p>
344
 
         * 
345
 
         * @method addAttr
346
 
         *
347
 
         * @param {String} name The name of the attribute.
348
 
         * @param {Object} config An object with attribute configuration property/value pairs, specifying the configuration for the attribute.
349
 
         *
350
 
         * <p>
351
 
         * <strong>NOTE:</strong> The configuration object is modified when adding an attribute, so if you need 
352
 
         * to protect the original values, you will need to merge the object.
353
 
         * </p>
354
 
         *
355
 
         * @param {boolean} lazy (optional) Whether or not to add this attribute lazily (on the first call to get/set). 
356
 
         *
357
 
         * @return {Object} A reference to the host object.
358
 
         *
359
 
         * @chainable
360
 
         */
361
 
        addAttr: function(name, config, lazy) {
362
 
 
363
 
 
364
 
            var host = this, // help compression
365
 
                state = host._state,
366
 
                value,
367
 
                hasValue;
368
 
 
369
 
            lazy = (LAZY_ADD in config) ? config[LAZY_ADD] : lazy;
370
 
 
371
 
            if (lazy && !host.attrAdded(name)) {
372
 
                state.add(name, LAZY, config || {});
373
 
                state.add(name, ADDED, true);
374
 
            } else {
375
 
 
376
 
 
377
 
                if (!host.attrAdded(name) || state.get(name, IS_LAZY_ADD)) {
378
 
 
379
 
                    config = config || {};
380
 
 
381
 
                    hasValue = (VALUE in config);
382
 
 
383
 
 
384
 
                    if(hasValue) {
385
 
                        // We'll go through set, don't want to set value in config directly
386
 
                        value = config.value;
387
 
                        delete config.value;
388
 
                    }
389
 
 
390
 
                    config.added = true;
391
 
                    config.initializing = true;
392
 
 
393
 
                    state.addAll(name, config);
394
 
 
395
 
                    if (hasValue) {
396
 
                        // Go through set, so that raw values get normalized/validated
397
 
                        host.set(name, value);
398
 
                    }
399
 
 
400
 
                    state.remove(name, INITIALIZING);
401
 
                }
402
 
            }
403
 
 
404
 
            return host;
405
 
        },
406
 
 
407
 
        /**
408
 
         * Checks if the given attribute has been added to the host
409
 
         *
410
 
         * @method attrAdded
411
 
         * @param {String} name The name of the attribute to check.
412
 
         * @return {boolean} true if an attribute with the given name has been added, false if it hasn't. This method will return true for lazily added attributes.
413
 
         */
414
 
        attrAdded: function(name) {
415
 
            return !!this._state.get(name, ADDED);
416
 
        },
417
 
 
418
 
        /**
419
 
         * Updates the configuration of an attribute which has already been added.
420
 
         * <p>
421
 
         * The properties which can be modified through this interface are limited
422
 
         * to the following subset of attributes, which can be safely modified
423
 
         * after a value has already been set on the attribute: readOnly, writeOnce, 
424
 
         * broadcast and getter.
425
 
         * </p>
426
 
         * @method modifyAttr
427
 
         * @param {String} name The name of the attribute whose configuration is to be updated.
428
 
         * @param {Object} config An object with configuration property/value pairs, specifying the configuration properties to modify.
429
 
         */
430
 
        modifyAttr: function(name, config) {
431
 
            var host = this, // help compression
432
 
                prop, state;
433
 
 
434
 
            if (host.attrAdded(name)) {
435
 
 
436
 
                if (host._isLazyAttr(name)) {
437
 
                    host._addLazyAttr(name);
438
 
                }
439
 
 
440
 
                state = host._state;
441
 
                for (prop in config) {
442
 
                    if (MODIFIABLE[prop] && config.hasOwnProperty(prop)) {
443
 
                        state.add(name, prop, config[prop]);
444
 
 
445
 
                        // If we reconfigured broadcast, need to republish
446
 
                        if (prop === BROADCAST) {
447
 
                            state.remove(name, PUBLISHED);
448
 
                        }
449
 
                    }
450
 
                }
451
 
            }
452
 
 
453
 
        },
454
 
 
455
 
        /**
456
 
         * Removes an attribute from the host object
457
 
         *
458
 
         * @method removeAttr
459
 
         * @param {String} name The name of the attribute to be removed.
460
 
         */
461
 
        removeAttr: function(name) {
462
 
            this._state.removeAll(name);
463
 
        },
464
 
 
465
 
        /**
466
 
         * Returns the current value of the attribute. If the attribute
467
 
         * has been configured with a 'getter' function, this method will delegate
468
 
         * to the 'getter' to obtain the value of the attribute.
469
 
         *
470
 
         * @method get
471
 
         *
472
 
         * @param {String} name The name of the attribute. If the value of the attribute is an Object, 
473
 
         * dot notation can be used to obtain the value of a property of the object (e.g. <code>get("x.y.z")</code>)
474
 
         *
475
 
         * @return {Any} The value of the attribute
476
 
         */
477
 
        get : function(name) {
478
 
            return this._getAttr(name);
479
 
        },
480
 
 
481
 
        /**
482
 
         * Checks whether or not the attribute is one which has been
483
 
         * added lazily and still requires initialization.
484
 
         *
485
 
         * @method _isLazyAttr
486
 
         * @private
487
 
         * @param {String} name The name of the attribute
488
 
         * @return {boolean} true if it's a lazily added attribute, false otherwise.
489
 
         */
490
 
        _isLazyAttr: function(name) {
491
 
            return this._state.get(name, LAZY);
492
 
        },
493
 
 
494
 
        /**
495
 
         * Finishes initializing an attribute which has been lazily added.
496
 
         *
497
 
         * @method _addLazyAttr
498
 
         * @private
499
 
         * @param {Object} name The name of the attribute
500
 
         */
501
 
        _addLazyAttr: function(name) {
502
 
            var state = this._state,
503
 
                lazyCfg = state.get(name, LAZY);
504
 
 
505
 
            state.add(name, IS_LAZY_ADD, true);
506
 
            state.remove(name, LAZY);
507
 
            this.addAttr(name, lazyCfg);
508
 
        },
509
 
 
510
 
        /**
511
 
         * Sets the value of an attribute.
512
 
         *
513
 
         * @method set
514
 
         * @chainable
515
 
         *
516
 
         * @param {String} name The name of the attribute. If the 
517
 
         * current value of the attribute is an Object, dot notation can be used
518
 
         * to set the value of a property within the object (e.g. <code>set("x.y.z", 5)</code>).
519
 
         *
520
 
         * @param {Any} value The value to set the attribute to.
521
 
         *
522
 
         * @param {Object} opts (Optional) Optional event data to be mixed into
523
 
         * the event facade passed to subscribers of the attribute's change event. This 
524
 
         * can be used as a flexible way to identify the source of a call to set, allowing 
525
 
         * the developer to distinguish between set called internally by the host, vs. 
526
 
         * set called externally by the application developer.
527
 
         *
528
 
         * @return {Object} A reference to the host object.
529
 
         */
530
 
        set : function(name, val, opts) {
531
 
            return this._setAttr(name, val, opts);
532
 
        },
533
 
 
534
 
        /**
535
 
         * Resets the attribute (or all attributes) to its initial value, as long as
536
 
         * the attribute is not readOnly, or writeOnce.
537
 
         *
538
 
         * @method reset
539
 
         * @param {String} name Optional. The name of the attribute to reset.  If omitted, all attributes are reset.
540
 
         * @return {Object} A reference to the host object.
541
 
         * @chainable
542
 
         */
543
 
        reset : function(name) {
544
 
            var host = this,  // help compression
545
 
                added;
546
 
 
547
 
            if (name) {
548
 
                if (host._isLazyAttr(name)) {
549
 
                    host._addLazyAttr(name);
550
 
                }
551
 
                host.set(name, host._state.get(name, INIT_VALUE));
552
 
            } else {
553
 
                added = host._state.data.added;
554
 
                Y.each(added, function(v, n) {
555
 
                    host.reset(n);
556
 
                }, host);
557
 
            }
558
 
            return host;
559
 
        },
560
 
 
561
 
        /**
562
 
         * Allows setting of readOnly/writeOnce attributes. See <a href="#method_set">set</a> for argument details.
563
 
         *
564
 
         * @method _set
565
 
         * @protected
566
 
         * @chainable
567
 
         * 
568
 
         * @param {String} name The name of the attribute.
569
 
         * @param {Any} val The value to set the attribute to.
570
 
         * @param {Object} opts (Optional) Optional event data to be mixed into
571
 
         * the event facade passed to subscribers of the attribute's change event.
572
 
         * @return {Object} A reference to the host object.
573
 
         */
574
 
        _set : function(name, val, opts) {
575
 
            return this._setAttr(name, val, opts, true);
576
 
        },
577
 
 
578
 
        /**
579
 
         * Provides the common implementation for the public get method,
580
 
         * allowing Attribute hosts to over-ride either method.
581
 
         *
582
 
         * See <a href="#method_get">get</a> for argument details.
583
 
         *
584
 
         * @method _getAttr
585
 
         * @protected
586
 
         * @chainable
587
 
         *
588
 
         * @param {String} name The name of the attribute.
589
 
         * @return {Any} The value of the attribute.
590
 
         */
591
 
        _getAttr : function(name) {
592
 
            var host = this, // help compression
593
 
                fullName = name,
594
 
                state = host._state,
595
 
                path,
596
 
                getter,
597
 
                val,
598
 
                cfg;
599
 
 
600
 
            if (name.indexOf(DOT) !== -1) {
601
 
                path = name.split(DOT);
602
 
                name = path.shift();
603
 
            }
604
 
 
605
 
            // On Demand - Should be rare - handles out of order valueFn references
606
 
            if (host._tCfgs && host._tCfgs[name]) {
607
 
                cfg = {};
608
 
                cfg[name] = host._tCfgs[name];
609
 
                delete host._tCfgs[name];
610
 
                host._addAttrs(cfg, host._tVals);
611
 
            }
612
 
 
613
 
            // Lazy Init
614
 
            if (host._isLazyAttr(name)) {
615
 
                host._addLazyAttr(name);
616
 
            }
617
 
 
618
 
            val = host._getStateVal(name);
619
 
            getter = state.get(name, GETTER);
620
 
 
621
 
            if (getter && !getter.call) {
622
 
                getter = this[getter];
623
 
            }
624
 
 
625
 
            val = (getter) ? getter.call(host, val, fullName) : val;
626
 
            val = (path) ? O.getValue(val, path) : val;
627
 
 
628
 
            return val;
629
 
        },
630
 
 
631
 
        /**
632
 
         * Provides the common implementation for the public set and protected _set methods.
633
 
         *
634
 
         * See <a href="#method_set">set</a> for argument details.
635
 
         *
636
 
         * @method _setAttr
637
 
         * @protected
638
 
         * @chainable
639
 
         *
640
 
         * @param {String} name The name of the attribute.
641
 
         * @param {Any} value The value to set the attribute to.
642
 
         * @param {Object} opts (Optional) Optional event data to be mixed into
643
 
         * the event facade passed to subscribers of the attribute's change event.
644
 
         * @param {boolean} force If true, allows the caller to set values for 
645
 
         * readOnly or writeOnce attributes which have already been set.
646
 
         *
647
 
         * @return {Object} A reference to the host object.
648
 
         */
649
 
        _setAttr : function(name, val, opts, force) {
650
 
            var allowSet = true,
651
 
                state = this._state,
652
 
                stateProxy = this._stateProxy,
653
 
                data = state.data,
654
 
                initialSet,
655
 
                strPath,
656
 
                path,
657
 
                currVal,
658
 
                writeOnce,
659
 
                initializing;
660
 
 
661
 
            if (name.indexOf(DOT) !== -1) {
662
 
                strPath = name;
663
 
                path = name.split(DOT);
664
 
                name = path.shift();
665
 
            }
666
 
 
667
 
            if (this._isLazyAttr(name)) {
668
 
                this._addLazyAttr(name);
669
 
            }
670
 
 
671
 
            initialSet = (!data.value || !(name in data.value));
672
 
 
673
 
            if (stateProxy && name in stateProxy && !this._state.get(name, BYPASS_PROXY)) {
674
 
                // TODO: Value is always set for proxy. Can we do any better? Maybe take a snapshot as the initial value for the first call to set? 
675
 
                initialSet = false;
676
 
            }
677
 
 
678
 
            if (this._requireAddAttr && !this.attrAdded(name)) {
679
 
            } else {
680
 
 
681
 
                writeOnce = state.get(name, WRITE_ONCE);
682
 
                initializing = state.get(name, INITIALIZING);
683
 
 
684
 
                if (!initialSet && !force) {
685
 
 
686
 
                    if (writeOnce) {
687
 
                        allowSet = false;
688
 
                    }
689
 
 
690
 
                    if (state.get(name, READ_ONLY)) {
691
 
                        allowSet = false;
692
 
                    }
693
 
                }
694
 
 
695
 
                if (!initializing && !force && writeOnce === INIT_ONLY) {
696
 
                    allowSet = false;
697
 
                }
698
 
 
699
 
                if (allowSet) {
700
 
                    // Don't need currVal if initialSet (might fail in custom getter if it always expects a non-undefined/non-null value)
701
 
                    if (!initialSet) {
702
 
                        currVal =  this.get(name);
703
 
                    }
704
 
 
705
 
                    if (path) {
706
 
                       val = O.setValue(Y.clone(currVal), path, val);
707
 
 
708
 
                       if (val === undefined) {
709
 
                           allowSet = false;
710
 
                       }
711
 
                    }
712
 
 
713
 
                    if (allowSet) {
714
 
                        if (initializing) {
715
 
                            this._setAttrVal(name, strPath, currVal, val);
716
 
                        } else {
717
 
                            this._fireAttrChange(name, strPath, currVal, val, opts);
718
 
                        }
719
 
                    }
720
 
                }
721
 
            }
722
 
 
723
 
            return this;
724
 
        },
725
 
 
726
 
        /**
727
 
         * Utility method to help setup the event payload and fire the attribute change event.
728
 
         * 
729
 
         * @method _fireAttrChange
730
 
         * @private
731
 
         * @param {String} attrName The name of the attribute
732
 
         * @param {String} subAttrName The full path of the property being changed, 
733
 
         * if this is a sub-attribute value being change. Otherwise null.
734
 
         * @param {Any} currVal The current value of the attribute
735
 
         * @param {Any} newVal The new value of the attribute
736
 
         * @param {Object} opts Any additional event data to mix into the attribute change event's event facade.
737
 
         */
738
 
        _fireAttrChange : function(attrName, subAttrName, currVal, newVal, opts) {
739
 
            var host = this,
740
 
                eventName = attrName + CHANGE,
741
 
                state = host._state,
742
 
                facade;
743
 
 
744
 
            if (!state.get(attrName, PUBLISHED)) {
745
 
                host.publish(eventName, {
746
 
                    queuable:false,
747
 
                    defaultTargetOnly: true, 
748
 
                    defaultFn:host._defAttrChangeFn, 
749
 
                    silent:true,
750
 
                    broadcast : state.get(attrName, BROADCAST)
751
 
                });
752
 
                state.add(attrName, PUBLISHED, true);
753
 
            }
754
 
 
755
 
            facade = (opts) ? Y.merge(opts) : host._ATTR_E_FACADE;
756
 
 
757
 
            // Not using the single object signature for fire({type:..., newVal:...}), since 
758
 
            // we don't want to override type. Changed to the fire(type, {newVal:...}) signature.
759
 
 
760
 
            // facade.type = eventName;
761
 
            facade.attrName = attrName;
762
 
            facade.subAttrName = subAttrName;
763
 
            facade.prevVal = currVal;
764
 
            facade.newVal = newVal;
765
 
 
766
 
            // host.fire(facade);
767
 
            host.fire(eventName, facade);
768
 
        },
769
 
 
770
 
        /**
771
 
         * Default function for attribute change events.
772
 
         *
773
 
         * @private
774
 
         * @method _defAttrChangeFn
775
 
         * @param {EventFacade} e The event object for attribute change events.
776
 
         */
777
 
        _defAttrChangeFn : function(e) {
778
 
            if (!this._setAttrVal(e.attrName, e.subAttrName, e.prevVal, e.newVal)) {
779
 
                // Prevent "after" listeners from being invoked since nothing changed.
780
 
                e.stopImmediatePropagation();
781
 
            } else {
782
 
                e.newVal = this.get(e.attrName);
783
 
            }
784
 
        },
785
 
 
786
 
        /**
787
 
         * Gets the stored value for the attribute, from either the 
788
 
         * internal state object, or the state proxy if it exits
789
 
         * 
790
 
         * @method _getStateVal
791
 
         * @private
792
 
         * @param {String} name The name of the attribute
793
 
         * @return {Any} The stored value of the attribute
794
 
         */
795
 
        _getStateVal : function(name) {
796
 
            var stateProxy = this._stateProxy;
797
 
            return stateProxy && (name in stateProxy) && !this._state.get(name, BYPASS_PROXY) ? stateProxy[name] : this._state.get(name, VALUE);
798
 
        },
799
 
 
800
 
        /**
801
 
         * Sets the stored value for the attribute, in either the 
802
 
         * internal state object, or the state proxy if it exits
803
 
         *
804
 
         * @method _setStateVal
805
 
         * @private
806
 
         * @param {String} name The name of the attribute
807
 
         * @param {Any} value The value of the attribute
808
 
         */
809
 
        _setStateVal : function(name, value) {
810
 
            var stateProxy = this._stateProxy;
811
 
            if (stateProxy && (name in stateProxy) && !this._state.get(name, BYPASS_PROXY)) {
812
 
                stateProxy[name] = value;
813
 
            } else {
814
 
                this._state.add(name, VALUE, value);
815
 
            }
816
 
        },
817
 
 
818
 
        /**
819
 
         * Updates the stored value of the attribute in the privately held State object,
820
 
         * if validation and setter passes.
821
 
         *
822
 
         * @method _setAttrVal
823
 
         * @private
824
 
         * @param {String} attrName The attribute name.
825
 
         * @param {String} subAttrName The sub-attribute name, if setting a sub-attribute property ("x.y.z").
826
 
         * @param {Any} prevVal The currently stored value of the attribute.
827
 
         * @param {Any} newVal The value which is going to be stored.
828
 
         * 
829
 
         * @return {booolean} true if the new attribute value was stored, false if not.
830
 
         */
831
 
        _setAttrVal : function(attrName, subAttrName, prevVal, newVal) {
832
 
 
833
 
            var host = this,
834
 
                allowSet = true,
835
 
                state = host._state,
836
 
 
837
 
                validator = state.get(attrName, VALIDATOR),
838
 
                setter = state.get(attrName, SETTER),
839
 
                initializing = state.get(attrName, INITIALIZING),
840
 
                prevValRaw = this._getStateVal(attrName),
841
 
 
842
 
                name = subAttrName || attrName,
843
 
                retVal,
844
 
                valid;
845
 
 
846
 
            if (validator) {
847
 
                if (!validator.call) { 
848
 
                    // Assume string - trying to keep critical path tight, so avoiding Lang check
849
 
                    validator = this[validator];
850
 
                }
851
 
                if (validator) {
852
 
                    valid = validator.call(host, newVal, name);
853
 
 
854
 
                    if (!valid && initializing) {
855
 
                        newVal = state.get(attrName, DEF_VALUE);
856
 
                        valid = true; // Assume it's valid, for perf.
857
 
                    }
858
 
                }
859
 
            }
860
 
 
861
 
            if (!validator || valid) {
862
 
                if (setter) {
863
 
                    if (!setter.call) {
864
 
                        // Assume string - trying to keep critical path tight, so avoiding Lang check
865
 
                        setter = this[setter];
866
 
                    }
867
 
                    if (setter) {
868
 
                        retVal = setter.call(host, newVal, name);
869
 
 
870
 
                        if (retVal === INVALID_VALUE) {
871
 
                            allowSet = false;
872
 
                        } else if (retVal !== undefined){
873
 
                            newVal = retVal;
874
 
                        }
875
 
                    }
876
 
                }
877
 
 
878
 
                if (allowSet) {
879
 
                    if(!subAttrName && (newVal === prevValRaw) && !Lang.isObject(newVal)) {
880
 
                        allowSet = false;
881
 
                    } else {
882
 
                        // Store value
883
 
                        if (state.get(attrName, INIT_VALUE) === undefined) {
884
 
                            state.add(attrName, INIT_VALUE, newVal);
885
 
                        }
886
 
                        host._setStateVal(attrName, newVal);
887
 
                    }
888
 
                }
889
 
 
890
 
            } else {
891
 
                allowSet = false;
892
 
            }
893
 
 
894
 
            return allowSet;
895
 
        },
896
 
 
897
 
        /**
898
 
         * Sets multiple attribute values.
899
 
         *
900
 
         * @method setAttrs
901
 
         * @param {Object} attrs  An object with attributes name/value pairs.
902
 
         * @return {Object} A reference to the host object.
903
 
         * @chainable
904
 
         */
905
 
        setAttrs : function(attrs, opts) {
906
 
            return this._setAttrs(attrs, opts);
907
 
        },
908
 
 
909
 
        /**
910
 
         * Implementation behind the public setAttrs method, to set multiple attribute values.
911
 
         *
912
 
         * @method _setAttrs
913
 
         * @protected
914
 
         * @param {Object} attrs  An object with attributes name/value pairs.
915
 
         * @return {Object} A reference to the host object.
916
 
         * @chainable
917
 
         */
918
 
        _setAttrs : function(attrs, opts) {
919
 
            for (var attr in attrs) {
920
 
                if ( attrs.hasOwnProperty(attr) ) {
921
 
                    this.set(attr, attrs[attr]);
922
 
                }
923
 
            }
924
 
            return this;
925
 
        },
926
 
 
927
 
        /**
928
 
         * Gets multiple attribute values.
929
 
         *
930
 
         * @method getAttrs
931
 
         * @param {Array | boolean} attrs Optional. An array of attribute names. If omitted, all attribute values are
932
 
         * returned. If set to true, all attributes modified from their initial values are returned.
933
 
         * @return {Object} An object with attribute name/value pairs.
934
 
         */
935
 
        getAttrs : function(attrs) {
936
 
            return this._getAttrs(attrs);
937
 
        },
938
 
 
939
 
        /**
940
 
         * Implementation behind the public getAttrs method, to get multiple attribute values.
941
 
         *
942
 
         * @method _getAttrs
943
 
         * @protected
944
 
         * @param {Array | boolean} attrs Optional. An array of attribute names. If omitted, all attribute values are
945
 
         * returned. If set to true, all attributes modified from their initial values are returned.
946
 
         * @return {Object} An object with attribute name/value pairs.
947
 
         */
948
 
        _getAttrs : function(attrs) {
949
 
            var host = this,
950
 
                o = {}, 
951
 
                i, l, attr, val,
952
 
                modifiedOnly = (attrs === true);
953
 
 
954
 
            attrs = (attrs && !modifiedOnly) ? attrs : O.keys(host._state.data.added);
955
 
 
956
 
            for (i = 0, l = attrs.length; i < l; i++) {
957
 
                // Go through get, to honor cloning/normalization
958
 
                attr = attrs[i];
959
 
                val = host.get(attr);
960
 
 
961
 
                if (!modifiedOnly || host._getStateVal(attr) != host._state.get(attr, INIT_VALUE)) {
962
 
                    o[attr] = host.get(attr); 
963
 
                }
964
 
            }
965
 
 
966
 
            return o;
967
 
        },
968
 
 
969
 
        /**
970
 
         * Configures a group of attributes, and sets initial values.
971
 
         *
972
 
         * <p>
973
 
         * <strong>NOTE:</strong> This method does not isolate the configuration object by merging/cloning. 
974
 
         * The caller is responsible for merging/cloning the configuration object if required.
975
 
         * </p>
976
 
         *
977
 
         * @method addAttrs
978
 
         * @chainable
979
 
         *
980
 
         * @param {Object} cfgs An object with attribute name/configuration pairs.
981
 
         * @param {Object} values An object with attribute name/value pairs, defining the initial values to apply.
982
 
         * Values defined in the cfgs argument will be over-written by values in this argument unless defined as read only.
983
 
         * @param {boolean} lazy Whether or not to delay the intialization of these attributes until the first call to get/set.
984
 
         * Individual attributes can over-ride this behavior by defining a lazyAdd configuration property in their configuration.
985
 
         * See <a href="#method_addAttr">addAttr</a>.
986
 
         * 
987
 
         * @return {Object} A reference to the host object.
988
 
         */
989
 
        addAttrs : function(cfgs, values, lazy) {
990
 
            var host = this; // help compression
991
 
            if (cfgs) {
992
 
                host._tCfgs = cfgs;
993
 
                host._tVals = host._normAttrVals(values);
994
 
                host._addAttrs(cfgs, host._tVals, lazy);
995
 
                host._tCfgs = host._tVals = null;
996
 
            }
997
 
 
998
 
            return host;
999
 
        },
1000
 
 
1001
 
        /**
1002
 
         * Implementation behind the public addAttrs method. 
1003
 
         * 
1004
 
         * This method is invoked directly by get if it encounters a scenario 
1005
 
         * in which an attribute's valueFn attempts to obtain the 
1006
 
         * value an attribute in the same group of attributes, which has not yet 
1007
 
         * been added (on demand initialization).
1008
 
         *
1009
 
         * @method _addAttrs
1010
 
         * @private
1011
 
         * @param {Object} cfgs An object with attribute name/configuration pairs.
1012
 
         * @param {Object} values An object with attribute name/value pairs, defining the initial values to apply.
1013
 
         * Values defined in the cfgs argument will be over-written by values in this argument unless defined as read only.
1014
 
         * @param {boolean} lazy Whether or not to delay the intialization of these attributes until the first call to get/set.
1015
 
         * Individual attributes can over-ride this behavior by defining a lazyAdd configuration property in their configuration.
1016
 
         * See <a href="#method_addAttr">addAttr</a>.
1017
 
         */
1018
 
        _addAttrs : function(cfgs, values, lazy) {
1019
 
            var host = this, // help compression
1020
 
                attr,
1021
 
                attrCfg,
1022
 
                value;
1023
 
 
1024
 
            for (attr in cfgs) {
1025
 
                if (cfgs.hasOwnProperty(attr)) {
1026
 
 
1027
 
                    // Not Merging. Caller is responsible for isolating configs
1028
 
                    attrCfg = cfgs[attr];
1029
 
                    attrCfg.defaultValue = attrCfg.value;
1030
 
 
1031
 
                    // Handle simple, complex and user values, accounting for read-only
1032
 
                    value = host._getAttrInitVal(attr, attrCfg, host._tVals);
1033
 
 
1034
 
                    if (value !== undefined) {
1035
 
                        attrCfg.value = value;
1036
 
                    }
1037
 
 
1038
 
                    if (host._tCfgs[attr]) {
1039
 
                        delete host._tCfgs[attr];
1040
 
                    }
1041
 
 
1042
 
                    host.addAttr(attr, attrCfg, lazy);
1043
 
                }
1044
 
            }
1045
 
        },
1046
 
 
1047
 
        /**
1048
 
         * Utility method to protect an attribute configuration
1049
 
         * hash, by merging the entire object and the individual 
1050
 
         * attr config objects. 
1051
 
         *
1052
 
         * @method _protectAttrs
1053
 
         * @protected
1054
 
         * @param {Object} attrs A hash of attribute to configuration object pairs.
1055
 
         * @return {Object} A protected version of the attrs argument.
1056
 
         */
1057
 
        _protectAttrs : function(attrs) {
1058
 
            if (attrs) {
1059
 
                attrs = Y.merge(attrs);
1060
 
                for (var attr in attrs) {
1061
 
                    if (attrs.hasOwnProperty(attr)) {
1062
 
                        attrs[attr] = Y.merge(attrs[attr]);
1063
 
                    }
1064
 
                }
1065
 
            }
1066
 
            return attrs;
1067
 
        },
1068
 
 
1069
 
        /**
1070
 
         * Utility method to normalize attribute values. The base implementation 
1071
 
         * simply merges the hash to protect the original.
1072
 
         *
1073
 
         * @method _normAttrVals
1074
 
         * @param {Object} valueHash An object with attribute name/value pairs
1075
 
         *
1076
 
         * @return {Object}
1077
 
         *
1078
 
         * @private
1079
 
         */
1080
 
        _normAttrVals : function(valueHash) {
1081
 
            return (valueHash) ? Y.merge(valueHash) : null;
1082
 
        },
1083
 
 
1084
 
        /**
1085
 
         * Returns the initial value of the given attribute from
1086
 
         * either the default configuration provided, or the 
1087
 
         * over-ridden value if it exists in the set of initValues 
1088
 
         * provided and the attribute is not read-only.
1089
 
         *
1090
 
         * @param {String} attr The name of the attribute
1091
 
         * @param {Object} cfg The attribute configuration object
1092
 
         * @param {Object} initValues The object with simple and complex attribute name/value pairs returned from _normAttrVals
1093
 
         *
1094
 
         * @return {Any} The initial value of the attribute.
1095
 
         *
1096
 
         * @method _getAttrInitVal
1097
 
         * @private
1098
 
         */
1099
 
        _getAttrInitVal : function(attr, cfg, initValues) {
1100
 
            var val, valFn;
1101
 
            // init value is provided by the user if it exists, else, provided by the config
1102
 
            if (!cfg[READ_ONLY] && initValues && initValues.hasOwnProperty(attr)) {
1103
 
                val = initValues[attr];
1104
 
            } else {
1105
 
                val = cfg[VALUE];
1106
 
                valFn = cfg[VALUE_FN];
1107
 
 
1108
 
                if (valFn) {
1109
 
                    if (!valFn.call) {
1110
 
                        valFn = this[valFn];
1111
 
                    }
1112
 
                    if (valFn) {
1113
 
                        val = valFn.call(this);
1114
 
                    }
1115
 
                }
1116
 
            }
1117
 
 
1118
 
 
1119
 
            return val;
1120
 
        },
1121
 
 
1122
 
        /**
1123
 
         * Returns an object with the configuration properties (and value)
1124
 
         * for the given attrubute. If attrName is not provided, returns the
1125
 
         * configuration properties for all attributes.
1126
 
         *
1127
 
         * @method _getAttrCfg
1128
 
         * @protected
1129
 
         * @param {String} name Optional. The attribute name. If not provided, the method will return the configuration for all attributes.
1130
 
         * @return {Object} The configuration properties for the given attribute, or all attributes.
1131
 
         */
1132
 
        _getAttrCfg : function(name) {
1133
 
            var o,
1134
 
                data = this._state.data;
1135
 
 
1136
 
            if (data) {
1137
 
                o = {};
1138
 
 
1139
 
                Y.each(data, function(cfg, cfgProp) {
1140
 
                    if (name) {
1141
 
                        if(name in cfg) {
1142
 
                            o[cfgProp] = cfg[name];
1143
 
                        }
1144
 
                    } else {
1145
 
                        Y.each(cfg, function(attrCfg, attr) {
1146
 
                           o[attr] = o[attr] || {};
1147
 
                           o[attr][cfgProp] = attrCfg;
1148
 
                        });
1149
 
                    }
1150
 
                });
1151
 
            }
1152
 
 
1153
 
            return o;
1154
 
        },
1155
 
 
1156
 
        /**
1157
 
         * Utility method to set up initial attributes defined during construction, either through the constructor.ATTRS property, or explicitly passed in.
1158
 
         * 
1159
 
         * @method _initAttrs
1160
 
         * @protected
1161
 
         * @param attrs {Object} The attributes to add during construction (passed through to <a href="#method_addAttrs">addAttrs</a>). These can also be defined on the constructor being augmented with Attribute by defining the ATTRS property on the constructor.
1162
 
         * @param values {Object} The initial attribute values to apply (passed through to <a href="#method_addAttrs">addAttrs</a>). These are not merged/cloned. The caller is responsible for isolating user provided values if required.
1163
 
         * @param lazy {boolean} Whether or not to add attributes lazily (passed through to <a href="#method_addAttrs">addAttrs</a>).
1164
 
         */
1165
 
        _initAttrs : function(attrs, values, lazy) {
1166
 
            // ATTRS support for Node, which is not Base based
1167
 
            attrs = attrs || this.constructor.ATTRS;
1168
 
    
1169
 
            var Base = Y.Base;
1170
 
            if ( attrs && !(Base && Y.instanceOf(this, Base))) {
1171
 
                this.addAttrs(this._protectAttrs(attrs), values, lazy);
1172
 
            }
1173
 
        }
1174
 
    };
1175
 
 
1176
 
    // Basic prototype augment - no lazy constructor invocation.
1177
 
    Y.mix(Attribute, EventTarget, false, null, 1);
1178
 
 
1179
 
    Y.Attribute = Attribute;
1180
 
 
1181
 
 
1182
 
}, '3.4.1' ,{requires:['event-custom']});