Merge branch 'MDL-32509' of git://github.com/danpoltawski/moodle
[moodle.git] / lib / yui / 3.5.0 / build / loader-rollup / loader-rollup-debug.js
blob399bd2a13071abff663cbf3e1a84858558f141e3
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('loader-rollup', function(Y) {
9 /**
10  * Optional automatic rollup logic for reducing http connections
11  * when not using a combo service.
12  * @module loader
13  * @submodule rollup
14  */
16 /**
17  * Look for rollup packages to determine if all of the modules a
18  * rollup supersedes are required.  If so, include the rollup to
19  * help reduce the total number of connections required.  Called
20  * by calculate().  This is an optional feature, and requires the
21  * appropriate submodule to function.
22  * @method _rollup
23  * @for Loader
24  * @private
25  */
26 Y.Loader.prototype._rollup = function() {
27     var i, j, m, s, r = this.required, roll,
28         info = this.moduleInfo, rolled, c, smod;
30     // find and cache rollup modules
31     if (this.dirty || !this.rollups) {
32         this.rollups = {};
33         for (i in info) {
34             if (info.hasOwnProperty(i)) {
35                 m = this.getModule(i);
36                 // if (m && m.rollup && m.supersedes) {
37                 if (m && m.rollup) {
38                     this.rollups[i] = m;
39                 }
40             }
41         }
42     }
44     // make as many passes as needed to pick up rollup rollups
45     for (;;) {
46         rolled = false;
48         // go through the rollup candidates
49         for (i in this.rollups) {
50             if (this.rollups.hasOwnProperty(i)) {
51                 // there can be only one, unless forced
52                 if (!r[i] && ((!this.loaded[i]) || this.forceMap[i])) {
53                     m = this.getModule(i);
54                     s = m.supersedes || [];
55                     roll = false;
57                     // @TODO remove continue
58                     if (!m.rollup) {
59                         continue;
60                     }
62                     c = 0;
64                     // check the threshold
65                     for (j = 0; j < s.length; j++) {
66                         smod = info[s[j]];
68                         // if the superseded module is loaded, we can't
69                         // load the rollup unless it has been forced.
70                         if (this.loaded[s[j]] && !this.forceMap[s[j]]) {
71                             roll = false;
72                             break;
73                         // increment the counter if this module is required.
74                         // if we are beyond the rollup threshold, we will
75                         // use the rollup module
76                         } else if (r[s[j]] && m.type == smod.type) {
77                             c++;
78                             // Y.log("adding to thresh: " + c + ", " + s[j]);
79                             roll = (c >= m.rollup);
80                             if (roll) {
81                                 // Y.log("over thresh " + c + ", " + s[j]);
82                                 break;
83                             }
84                         }
85                     }
87                     if (roll) {
88                         // Y.log("adding rollup: " +  i);
89                         // add the rollup
90                         r[i] = true;
91                         rolled = true;
93                         // expand the rollup's dependencies
94                         this.getRequires(m);
95                     }
96                 }
97             }
98         }
100         // if we made it here w/o rolling up something, we are done
101         if (!rolled) {
102             break;
103         }
104     }
108 }, '3.5.0' ,{requires:['loader-base']});