~ahasenack/lazr-js/lazr-js-11.03-packaging

« back to all changes in this revision

Viewing changes to src-js/lazrjs/yui/base/base-build-debug.js

  • Committer: Sidnei da Silva
  • Date: 2010-04-08 14:44:59 UTC
  • mfrom: (166.8.13 yui-3.1.0)
  • Revision ID: sidnei.da.silva@canonical.com-20100408144459-qozybvnrgr7iee7k
Merged yui-3.1.0 [r=therve,rockstar] [f=558457].

Updates lazr-js to use YUI 3.1.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
Copyright (c) 2009, Yahoo! Inc. All rights reserved.
 
2
Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3
3
Code licensed under the BSD License:
4
 
http://developer.yahoo.net/yui/license.txt
5
 
version: 3.0.0
6
 
build: 1549
 
4
http://developer.yahoo.com/yui/license.html
 
5
version: 3.1.0
 
6
build: 2026
7
7
*/
8
8
YUI.add('base-build', function(Y) {
9
9
 
16
16
     * @submodule base-build
17
17
     * @for Base
18
18
     */
19
 
 
20
19
    var Base = Y.Base,
21
 
        L = Y.Lang;
22
 
 
23
 
    /**
24
 
     * The build configuration for the Base class.
25
 
     *
26
 
     * Defines the static fields which need to be aggregated
27
 
     * when the Base class is used as the main class passed to 
28
 
     * the <a href="#method_Base.build">Base.build</a> method.
29
 
     *
30
 
     * @property Base._buildCfg
31
 
     * @type Object
32
 
     * @static
33
 
     * @final
34
 
     * @private
35
 
     */
36
 
    Base._buildCfg = {
37
 
        aggregates : ["ATTRS", "_PLUG", "_UNPLUG"]
38
 
    };
39
 
 
40
 
    /**
41
 
     * <p>
42
 
     * Builds a custom constructor function (class) from the
43
 
     * main function, and array of extension functions (classes)
44
 
     * provided. The NAME field for the constructor function is 
45
 
     * defined by the first argument passed in.
46
 
     * </p>
47
 
     * <p>
48
 
     * The cfg object supports the following properties
49
 
     * </p>
50
 
     * <dl>
51
 
     *    <dt>dynamic &#60;boolean&#62;</dt>
52
 
     *    <dd>
53
 
     *    <p>If true (default), a completely new class
54
 
     *    is created which extends the main class, and acts as the 
55
 
     *    host on which the extension classes are augmented.</p>
56
 
     *    <p>If false, the extensions classes are augmented directly to
57
 
     *    the main class, modifying the main class' prototype.</p>
58
 
     *    </dd>
59
 
     *    <dt>aggregates &#60;String[]&#62;</dt>
60
 
     *    <dd>An array of static property names, which will get aggregated
61
 
     *    on to the built class, in addition to the default properties build 
62
 
     *    will always aggregate as defined by the main class' static _buildCfg
63
 
     *    property.
64
 
     *    </dd>
65
 
     * </dl>
66
 
     *
67
 
     * @method Base.build
68
 
     * @static
69
 
     * @param {Function} name The name of the new class. Used to defined the NAME property for the new class.
70
 
     * @param {Function} main The main class on which to base the built class
71
 
     * @param {Function[]} extensions The set of extension classes which will be
72
 
     * augmented/aggregated to the built class.
73
 
     * @param {Object} cfg Optional. Build configuration for the class (see description).
74
 
     * @return {Function} A custom class, created from the provided main and extension classes
75
 
     */
76
 
    Base.build = function(name, main, extensions, cfg) {
77
 
 
78
 
        var build = Base.build,
79
 
            builtClass = build._getClass(main, cfg),
80
 
            aggregates = build._getAggregates(main, cfg),
 
20
        L = Y.Lang,
 
21
        build;
 
22
 
 
23
    Base._build = function(name, main, extensions, px, sx, cfg) {
 
24
 
 
25
        var build = Base._build,
 
26
 
 
27
            builtClass = build._ctor(main, cfg),
 
28
            buildCfg = build._cfg(main, cfg),
 
29
 
 
30
            _mixCust = build._mixCust,
 
31
 
 
32
            aggregates = buildCfg.aggregates,
 
33
            custom = buildCfg.custom,
 
34
 
81
35
            dynamic = builtClass._yuibuild.dynamic,
 
36
 
82
37
            i, l, val, extClass;
83
38
 
84
 
        // Shallow isolate aggregates
85
 
        if (dynamic) {
86
 
            if (aggregates) {
87
 
                for (i = 0, l = aggregates.length; i < l; ++i) {
88
 
                    val = aggregates[i];
89
 
                    if (main.hasOwnProperty(val)) {
90
 
                        builtClass[val] = L.isArray(main[val]) ? [] : {};
91
 
                    }
 
39
        if (dynamic && aggregates) {
 
40
            for (i = 0, l = aggregates.length; i < l; ++i) {
 
41
                val = aggregates[i];
 
42
                if (main.hasOwnProperty(val)) {
 
43
                    builtClass[val] = L.isArray(main[val]) ? [] : {};
92
44
                }
93
 
                Y.aggregate(builtClass, main, true, aggregates);
94
45
            }
95
46
        }
96
47
 
98
49
        for (i = 0, l = extensions.length; i < l; i++) {
99
50
            extClass = extensions[i];
100
51
 
101
 
            if (aggregates) {
102
 
                Y.aggregate(builtClass, extClass, true, aggregates);
103
 
            }
104
 
 
105
 
            // Old augment
 
52
            // Prototype, old non-displacing augment
106
53
            Y.mix(builtClass, extClass, true, null, 1);
 
54
             // Custom Statics
 
55
            _mixCust(builtClass, extClass, aggregates, custom);
107
56
 
108
57
            builtClass._yuibuild.exts.push(extClass);
109
58
        }
110
59
 
111
 
        builtClass.prototype.hasImpl = build._hasImpl;
 
60
        if (px) {
 
61
            Y.mix(builtClass.prototype, px, true);
 
62
        }
 
63
 
 
64
        if (sx) {
 
65
            Y.mix(builtClass, build._clean(sx, aggregates, custom), true);
 
66
            _mixCust(builtClass, sx, aggregates, custom);
 
67
        }
 
68
 
 
69
        builtClass.prototype.hasImpl = build._impl;
112
70
 
113
71
        if (dynamic) {
114
72
            builtClass.NAME = name;
118
76
        return builtClass;
119
77
    };
120
78
 
121
 
    Y.mix(Base.build, {
122
 
 
123
 
        _template: function(main) {
 
79
    build = Base._build;
 
80
 
 
81
    Y.mix(build, {
 
82
 
 
83
        _mixCust: function(r, s, aggregates, custom) {
 
84
 
 
85
            if (aggregates) {
 
86
                Y.aggregate(r, s, true, aggregates);
 
87
            }
 
88
 
 
89
            if (custom) {
 
90
                for (var j in custom) {
 
91
                    if (custom.hasOwnProperty(j)) {
 
92
                        custom[j](j, r, s);
 
93
                    }
 
94
                }
 
95
            }
 
96
        },
 
97
 
 
98
        _tmpl: function(main) {
124
99
 
125
100
            function BuiltClass() {
126
 
 
127
101
                BuiltClass.superclass.constructor.apply(this, arguments);
128
 
 
129
 
                var f = BuiltClass._yuibuild.exts, 
130
 
                    l = f.length,
131
 
                    i;
132
 
 
133
 
                for (i = 0; i < l; i++) {
134
 
                    f[i].apply(this, arguments);
135
 
                }
136
 
 
137
 
                return this;
138
102
            }
139
103
            Y.extend(BuiltClass, main);
140
104
 
141
105
            return BuiltClass;
142
106
        },
143
107
 
144
 
        _hasImpl : function(extClass) {
145
 
            var classes = this._getClasses();
146
 
            for (var i = 0, l = classes.length; i < l; i++) {
147
 
                var cls = classes[i];
148
 
                 
 
108
        _impl : function(extClass) {
 
109
            var classes = this._getClasses(), i, l, cls, exts, ll, j;
 
110
            for (i = 0, l = classes.length; i < l; i++) {
 
111
                cls = classes[i];
149
112
                if (cls._yuibuild) {
150
 
                    var exts = cls._yuibuild.exts,
151
 
                        ll = exts.length,
152
 
                        j;
 
113
                    exts = cls._yuibuild.exts;
 
114
                    ll = exts.length;
153
115
    
154
116
                    for (j = 0; j < ll; j++) {
155
117
                        if (exts[j] === extClass) {
161
123
            return false;
162
124
        },
163
125
 
164
 
        _getClass : function(main, cfg) {
 
126
        _ctor : function(main, cfg) {
165
127
 
166
128
           var dynamic = (cfg && false === cfg.dynamic) ? false : true,
167
 
                builtClass = (dynamic) ? Base.build._template(main) : main;
 
129
                builtClass = (dynamic) ? build._tmpl(main) : main;
168
130
 
169
131
            builtClass._yuibuild = {
170
132
                id: null,
171
133
                exts : [],
172
 
                dynamic : dynamic
 
134
                dynamic: dynamic
173
135
            };
174
136
 
175
137
            return builtClass;
176
138
        },
177
139
 
178
 
        _getAggregates : function(main, cfg) {
179
 
            var aggr = [],
 
140
        _cfg : function(main, cfg) {
 
141
            var aggr = [], 
 
142
                cust = {},
 
143
                buildCfg,
180
144
                cfgAggr = (cfg && cfg.aggregates),
181
 
                c = main,
182
 
                classAggr;
 
145
                cfgCustBuild = (cfg && cfg.custom),
 
146
                c = main;
183
147
 
184
148
            while (c && c.prototype) {
185
 
                classAggr = c._buildCfg && c._buildCfg.aggregates;
186
 
                if (classAggr) {
187
 
                    aggr = aggr.concat(classAggr);
 
149
                buildCfg = c._buildCfg; 
 
150
                if (buildCfg) {
 
151
                    if (buildCfg.aggregates) {
 
152
                        aggr = aggr.concat(buildCfg.aggregates);
 
153
                    }
 
154
                    if (buildCfg.custom) {
 
155
                        Y.mix(cust, buildCfg.custom, true);
 
156
                    }
188
157
                }
189
158
                c = c.superclass ? c.superclass.constructor : null;
190
159
            }
192
161
            if (cfgAggr) {
193
162
                aggr = aggr.concat(cfgAggr);
194
163
            }
195
 
 
196
 
            return aggr;
 
164
            if (cfgCustBuild) {
 
165
                Y.mix(cust, cfg.cfgBuild, true);
 
166
            }
 
167
 
 
168
            return {
 
169
                aggregates: aggr,
 
170
                custom: cust
 
171
            };
 
172
        },
 
173
 
 
174
        _clean : function(sx, aggregates, custom) {
 
175
            var prop, i, l, sxclone = Y.merge(sx);
 
176
 
 
177
            for (prop in custom) {
 
178
                if (sxclone.hasOwnProperty(prop)) {
 
179
                    delete sxclone[prop];
 
180
                }
 
181
            }
 
182
 
 
183
            for (i = 0, l = aggregates.length; i < l; i++) {
 
184
                prop = aggregates[i];
 
185
                if (sxclone.hasOwnProperty(prop)) {
 
186
                    delete sxclone[prop];
 
187
                }
 
188
            }
 
189
 
 
190
            return sxclone;
197
191
        }
198
192
    });
199
193
 
200
 
 
201
 
}, '3.0.0' ,{requires:['base-base']});
 
194
    /**
 
195
     * <p>
 
196
     * Builds a custom constructor function (class) from the
 
197
     * main function, and array of extension functions (classes)
 
198
     * provided. The NAME field for the constructor function is 
 
199
     * defined by the first argument passed in.
 
200
     * </p>
 
201
     * <p>
 
202
     * The cfg object supports the following properties
 
203
     * </p>
 
204
     * <dl>
 
205
     *    <dt>dynamic &#60;boolean&#62;</dt>
 
206
     *    <dd>
 
207
     *    <p>If true (default), a completely new class
 
208
     *    is created which extends the main class, and acts as the 
 
209
     *    host on which the extension classes are augmented.</p>
 
210
     *    <p>If false, the extensions classes are augmented directly to
 
211
     *    the main class, modifying the main class' prototype.</p>
 
212
     *    </dd>
 
213
     *    <dt>aggregates &#60;String[]&#62;</dt>
 
214
     *    <dd>An array of static property names, which will get aggregated
 
215
     *    on to the built class, in addition to the default properties build 
 
216
     *    will always aggregate as defined by the main class' static _buildCfg
 
217
     *    property.
 
218
     *    </dd>
 
219
     * </dl>
 
220
     *
 
221
     * @method Base.build
 
222
     * @static
 
223
     * @param {Function} name The name of the new class. Used to defined the NAME property for the new class.
 
224
     * @param {Function} main The main class on which to base the built class
 
225
     * @param {Function[]} extensions The set of extension classes which will be
 
226
     * augmented/aggregated to the built class.
 
227
     * @param {Object} cfg Optional. Build configuration for the class (see description).
 
228
     * @return {Function} A custom class, created from the provided main and extension classes
 
229
     */
 
230
    Base.build = function(name, main, extensions, cfg) {
 
231
        return build(name, main, extensions, null, null, cfg);
 
232
    };
 
233
 
 
234
    /**
 
235
     * <p>Creates a new class (constructor function) which extends the base class passed in as the second argument, 
 
236
     * and mixes in the array of extensions provided.</p>
 
237
     * <p>Prototype properties or methods can be added to the new class, using the px argument (similar to Y.extend).</p>
 
238
     * <p>Static properties or methods can be added to the new class, using the sx argument (similar to Y.extend).</p>
 
239
     * <p>
 
240
     * 
 
241
     * </p>
 
242
     * @method Base.create
 
243
     * @static
 
244
     * @param {Function} name The name of the newly created class. Used to defined the NAME property for the new class.
 
245
     * @param {Function} main The base class which the new class should extend. This class needs to be Base or a class derived from base (e.g. Widget).
 
246
     * @param {Function[]} extensions The list of extensions which will be mixed into the built class.
 
247
     * @return {Function} The newly created class.
 
248
     */
 
249
    Base.create = function(name, base, extensions, px, sx) {
 
250
        return build(name, base, extensions, px, sx);
 
251
    };
 
252
 
 
253
    /**
 
254
     * <p>Mixes in a list of extensions to an existing class.</p>
 
255
     * @method Base.mix
 
256
     * @static
 
257
     * @param {Function} main The existing class into which the extensions should be mixed.  The class needs to be Base or class derived from base (e.g. Widget)
 
258
     * @param {Function[]} extensions The set of extension classes which will mixed into the existing main class.
 
259
     * @return {Function} The modified main class, with extensions mixed in.
 
260
     */
 
261
    Base.mix = function(main, extensions) {
 
262
        return build(null, main, extensions, null, null, {dynamic:false});
 
263
    };
 
264
 
 
265
    /**
 
266
     * The build configuration for the Base class.
 
267
     *
 
268
     * Defines the static fields which need to be aggregated
 
269
     * when the Base class is used as the main class passed to
 
270
     * the <a href="#method_Base.build">Base.build</a> method.
 
271
     *
 
272
     * @property Base._buildCfg
 
273
     * @type Object
 
274
     * @static
 
275
     * @final
 
276
     * @private
 
277
     */
 
278
    Base._buildCfg = {
 
279
        custom : { 
 
280
            ATTRS : function(prop, r, s) {
 
281
                r[prop] = r[prop] || {};
 
282
                if (s[prop]) {
 
283
                    Y.aggregate(r[prop], s[prop], true);
 
284
                }
 
285
            }
 
286
        },
 
287
        aggregates : ["_PLUG", "_UNPLUG"]
 
288
    };
 
289
 
 
290
 
 
291
}, '3.1.0' ,{requires:['base-base']});