~ubuntu-branches/ubuntu/saucy/whoopsie-daisy/saucy

« back to all changes in this revision

Viewing changes to backend/stats/static/js/yui/build/base-base/base-base.js

  • Committer: Package Import Robot
  • Author(s): Evan Dandrea
  • Date: 2012-04-18 13:04:36 UTC
  • Revision ID: package-import@ubuntu.com-20120418130436-vmt93p8fds516lws
Tags: 0.1.32
Fix failing tests on powerpc and ARM.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
YUI 3.5.0 (build 5089)
 
3
Copyright 2012 Yahoo! Inc. All rights reserved.
 
4
Licensed under the BSD License.
 
5
http://yuilibrary.com/license/
 
6
*/
 
7
YUI.add('base-base', function(Y) {
 
8
 
 
9
    /**
 
10
     * The base module provides the Base class, which objects requiring attribute and custom event support can extend. 
 
11
     * The module also provides two ways to reuse code - It augments Base with the Plugin.Host interface which provides 
 
12
     * plugin support and also provides the BaseCore.build method which provides a way to build custom classes using extensions.
 
13
     *
 
14
     * @module base
 
15
     */
 
16
 
 
17
    /**
 
18
     * The base-base submodule provides the Base class without the Plugin support, provided by Plugin.Host, 
 
19
     * and without the extension support provided by BaseCore.build.
 
20
     *
 
21
     * @module base
 
22
     * @submodule base-base
 
23
     */
 
24
 
 
25
    /**
 
26
     * The base module provides the Base class, which objects requiring attribute and custom event support can extend. 
 
27
     * The module also provides two ways to reuse code - It augments Base with the Plugin.Host interface which provides 
 
28
     * plugin support and also provides the Base.build method which provides a way to build custom classes using extensions.
 
29
     *
 
30
     * @module base
 
31
     */
 
32
 
 
33
    /**
 
34
     * The base-base submodule provides the Base class without the Plugin support, provided by Plugin.Host, 
 
35
     * and without the extension support provided by Base.build.
 
36
     *
 
37
     * @module base
 
38
     * @submodule base-base
 
39
     */
 
40
    var L = Y.Lang,
 
41
 
 
42
        DESTROY = "destroy",
 
43
        INIT = "init",
 
44
 
 
45
        BUBBLETARGETS = "bubbleTargets",
 
46
        _BUBBLETARGETS = "_bubbleTargets",
 
47
 
 
48
        BaseCore = Y.BaseCore,
 
49
        AttributeCore = Y.AttributeCore,
 
50
        Attribute = Y.Attribute;
 
51
 
 
52
    /**
 
53
     * <p>
 
54
     * A base class which objects requiring attributes and custom event support can 
 
55
     * extend. Base also handles the chaining of initializer and destructor methods across 
 
56
     * the hierarchy as part of object construction and destruction. Additionally, attributes configured 
 
57
     * through the static <a href="#property_Base.ATTRS">ATTRS</a> property for each class 
 
58
     * in the hierarchy will be initialized by Base.
 
59
     * </p>
 
60
     *
 
61
     * <p>
 
62
     * The static <a href="#property_Base.NAME">NAME</a> property of each class extending 
 
63
     * from Base will be used as the identifier for the class, and is used by Base to prefix 
 
64
     * all events fired by instances of that class.
 
65
     * </p>
 
66
     *
 
67
     * @class Base
 
68
     * @constructor
 
69
     * @uses BaseCore
 
70
     * @uses Attribute
 
71
     * @uses AttributeCore
 
72
     * @uses AttributeEvents
 
73
     * @uses AttributeExtras
 
74
     * @uses EventTarget
 
75
     *
 
76
     * @param {Object} config Object with configuration property name/value pairs. The object can be 
 
77
     * used to provide default values for the objects published attributes.
 
78
     *
 
79
     * <p>
 
80
     * The config object can also contain the following non-attribute properties, providing a convenient 
 
81
     * way to configure events listeners and plugins for the instance, as part of the constructor call:
 
82
     * </p>
 
83
     *
 
84
     * <dl>
 
85
     *     <dt>on</dt>
 
86
     *     <dd>An event name to listener function map, to register event listeners for the "on" moment of the event. A constructor convenience property for the <a href="Base.html#method_on">on</a> method.</dd>
 
87
     *     <dt>after</dt>
 
88
     *     <dd>An event name to listener function map, to register event listeners for the "after" moment of the event. A constructor convenience property for the <a href="Base.html#method_after">after</a> method.</dd>
 
89
     *     <dt>bubbleTargets</dt>
 
90
     *     <dd>An object, or array of objects, to register as bubble targets for bubbled events fired by this instance. A constructor convenience property for the <a href="EventTarget.html#method_addTarget">addTarget</a> method.</dd>
 
91
     *     <dt>plugins</dt>
 
92
     *     <dd>A plugin, or array of plugins to be plugged into the instance (see PluginHost's plug method for signature details). A constructor convenience property for the <a href="Plugin.Host.html#method_plug">plug</a> method.</dd>
 
93
     * </dl>
 
94
     */
 
95
    function Base() {
 
96
        BaseCore.apply(this, arguments);
 
97
    }
 
98
 
 
99
    /**
 
100
     * The list of properties which can be configured for 
 
101
     * each attribute (e.g. setter, getter, writeOnce, readOnly etc.)
 
102
     *
 
103
     * @property _ATTR_CFG
 
104
     * @type Array
 
105
     * @static
 
106
     * @private
 
107
     */
 
108
    Base._ATTR_CFG = Attribute._ATTR_CFG.concat("cloneDefaultValue");
 
109
    Base._ATTR_CFG_HASH = Y.Array.hash(Base._ATTR_CFG);
 
110
 
 
111
    /**
 
112
     * The array of non-attribute configuration properties supported by this class. 
 
113
     * 
 
114
     * `Base` supports "on", "after", "plugins" and "bubbleTargets" properties, 
 
115
     * which are not set up as attributes. 
 
116
     *
 
117
     * This property is primarily required so that when 
 
118
     * <a href="#property__allowAdHocAttrs">`_allowAdHocAttrs`</a> is enabled by
 
119
     * a class, non-attribute configurations don't get added as ad-hoc attributes.  
 
120
     *
 
121
     * @property _NON_ATTRS_CFG
 
122
     * @type Array
 
123
     * @static
 
124
     * @private
 
125
     */
 
126
    Base._NON_ATTRS_CFG = BaseCore._NON_ATTRS_CFG.concat(["on", "after", "bubbleTargets"]);
 
127
 
 
128
    /**
 
129
     * <p>
 
130
     * The string to be used to identify instances of 
 
131
     * this class, for example in prefixing events.
 
132
     * </p>
 
133
     * <p>
 
134
     * Classes extending Base, should define their own
 
135
     * static NAME property, which should be camelCase by
 
136
     * convention (e.g. MyClass.NAME = "myClass";).
 
137
     * </p>
 
138
     * @property NAME
 
139
     * @type String
 
140
     * @static
 
141
     */
 
142
    Base.NAME = "base";
 
143
 
 
144
    /**
 
145
     * The default set of attributes which will be available for instances of this class, and 
 
146
     * their configuration. In addition to the configuration properties listed by 
 
147
     * Attribute's <a href="Attribute.html#method_addAttr">addAttr</a> method, the attribute 
 
148
     * can also be configured with a "cloneDefaultValue" property, which defines how the statically
 
149
     * defined value field should be protected ("shallow", "deep" and false are supported values). 
 
150
     *
 
151
     * By default if the value is an object literal or an array it will be "shallow" cloned, to 
 
152
     * protect the default value.
 
153
     *
 
154
     * @property ATTRS
 
155
     * @type Object
 
156
     * @static
 
157
     */
 
158
    Base.ATTRS = AttributeCore.prototype._protectAttrs(BaseCore.ATTRS);
 
159
 
 
160
    Base.prototype = {
 
161
 
 
162
        /**
 
163
         * Internal construction logic for Base.
 
164
         *
 
165
         * @method _initBase
 
166
         * @param {Object} config The constructor configuration object
 
167
         * @private
 
168
         */
 
169
        _initBase: function(cfg) {
 
170
 
 
171
            this._eventPrefix = this.constructor.EVENT_PREFIX || this.constructor.NAME;
 
172
 
 
173
            Y.BaseCore.prototype._initBase.call(this, cfg);
 
174
        },
 
175
 
 
176
        /**
 
177
         * Initializes Attribute 
 
178
         * 
 
179
         * @method _initAttribute
 
180
         * @private
 
181
         */
 
182
        _initAttribute: function(cfg) {
 
183
            Attribute.call(this);
 
184
            this._yuievt.config.prefix = this._eventPrefix;
 
185
        },
 
186
 
 
187
        /**
 
188
         * Utility method to define the attribute hash used to filter/whitelist property mixes for 
 
189
         * this class. 
 
190
         * 
 
191
         * @method _attrCfgHash
 
192
         * @private
 
193
         */
 
194
        _attrCfgHash: function() {
 
195
            return Base._ATTR_CFG_HASH;
 
196
        },
 
197
 
 
198
        /**
 
199
         * Init lifecycle method, invoked during construction.
 
200
         * Fires the init event prior to setting up attributes and 
 
201
         * invoking initializers for the class hierarchy.
 
202
         *
 
203
         * @method init
 
204
         * @chainable
 
205
         * @param {Object} config Object with configuration property name/value pairs
 
206
         * @return {Base} A reference to this object
 
207
         */
 
208
        init: function(config) {
 
209
            /**
 
210
             * <p>
 
211
             * Lifecycle event for the init phase, fired prior to initialization. 
 
212
             * Invoking the preventDefault() method on the event object provided 
 
213
             * to subscribers will prevent initialization from occuring.
 
214
             * </p>
 
215
             * <p>
 
216
             * Subscribers to the "after" momemt of this event, will be notified
 
217
             * after initialization of the object is complete (and therefore
 
218
             * cannot prevent initialization).
 
219
             * </p>
 
220
             *
 
221
             * @event init
 
222
             * @preventable _defInitFn
 
223
             * @param {EventFacade} e Event object, with a cfg property which 
 
224
             * refers to the configuration object passed to the constructor.
 
225
             */
 
226
            this.publish(INIT, {
 
227
                queuable:false,
 
228
                fireOnce:true,
 
229
                defaultTargetOnly:true,
 
230
                defaultFn:this._defInitFn
 
231
            });
 
232
 
 
233
            this._preInitEventCfg(config);
 
234
 
 
235
            this.fire(INIT, {cfg: config});
 
236
 
 
237
            return this;
 
238
        },
 
239
 
 
240
        /**
 
241
         * Handles the special on, after and target properties which allow the user to
 
242
         * easily configure on and after listeners as well as bubble targets during 
 
243
         * construction, prior to init.
 
244
         *
 
245
         * @private
 
246
         * @method _preInitEventCfg
 
247
         * @param {Object} config The user configuration object
 
248
         */
 
249
        _preInitEventCfg : function(config) {
 
250
            if (config) {
 
251
                if (config.on) {
 
252
                    this.on(config.on);
 
253
                }
 
254
                if (config.after) {
 
255
                    this.after(config.after);
 
256
                }
 
257
            }
 
258
 
 
259
            var i, l, target,
 
260
                userTargets = (config && BUBBLETARGETS in config);
 
261
 
 
262
            if (userTargets || _BUBBLETARGETS in this) {
 
263
                target = userTargets ? (config && config.bubbleTargets) : this._bubbleTargets;
 
264
                if (L.isArray(target)) {
 
265
                    for (i = 0, l = target.length; i < l; i++) { 
 
266
                        this.addTarget(target[i]);
 
267
                    }
 
268
                } else if (target) {
 
269
                    this.addTarget(target);
 
270
                }
 
271
            }
 
272
        },
 
273
 
 
274
        /**
 
275
         * <p>
 
276
         * Destroy lifecycle method. Fires the destroy
 
277
         * event, prior to invoking destructors for the
 
278
         * class hierarchy.
 
279
         * </p>
 
280
         * <p>
 
281
         * Subscribers to the destroy
 
282
         * event can invoke preventDefault on the event object, to prevent destruction
 
283
         * from proceeding.
 
284
         * </p>
 
285
         * @method destroy
 
286
         * @return {Base} A reference to this object
 
287
         * @chainable
 
288
         */
 
289
        destroy: function() {
 
290
 
 
291
            /**
 
292
             * <p>
 
293
             * Lifecycle event for the destroy phase, 
 
294
             * fired prior to destruction. Invoking the preventDefault 
 
295
             * method on the event object provided to subscribers will 
 
296
             * prevent destruction from proceeding.
 
297
             * </p>
 
298
             * <p>
 
299
             * Subscribers to the "after" moment of this event, will be notified
 
300
             * after destruction is complete (and as a result cannot prevent
 
301
             * destruction).
 
302
             * </p>
 
303
             * @event destroy
 
304
             * @preventable _defDestroyFn
 
305
             * @param {EventFacade} e Event object
 
306
             */
 
307
            this.publish(DESTROY, {
 
308
                queuable:false,
 
309
                fireOnce:true,
 
310
                defaultTargetOnly:true,
 
311
                defaultFn: this._defDestroyFn
 
312
            });
 
313
            this.fire(DESTROY);
 
314
 
 
315
            this.detachAll();
 
316
            return this;
 
317
        },
 
318
 
 
319
        /**
 
320
         * Default init event handler
 
321
         *
 
322
         * @method _defInitFn
 
323
         * @param {EventFacade} e Event object, with a cfg property which 
 
324
         * refers to the configuration object passed to the constructor.
 
325
         * @protected
 
326
         */
 
327
        _defInitFn : function(e) {
 
328
            this._baseInit(e.cfg);
 
329
        },
 
330
 
 
331
        /**
 
332
         * Default destroy event handler
 
333
         *
 
334
         * @method _defDestroyFn
 
335
         * @param {EventFacade} e Event object
 
336
         * @protected
 
337
         */
 
338
        _defDestroyFn : function(e) {
 
339
            this._baseDestroy(e.cfg);
 
340
        }
 
341
    };
 
342
 
 
343
    Y.mix(Base, Attribute, false, null, 1);
 
344
    Y.mix(Base, BaseCore, false, null, 1);
 
345
 
 
346
    // Fix constructor
 
347
    Base.prototype.constructor = Base;
 
348
 
 
349
    Y.Base = Base;
 
350
 
 
351
 
 
352
}, '3.5.0' ,{requires:['base-core', 'attribute-base']});