]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - jssource/src_files/include/javascript/yui3/build/loader/loader-rollup.js
Release 6.5.0
[Github/sugarcrm.git] / jssource / src_files / include / javascript / yui3 / build / loader / loader-rollup.js
1 /*
2 Copyright (c) 2010, Yahoo! Inc. All rights reserved.
3 Code licensed under the BSD License:
4 http://developer.yahoo.com/yui/license.html
5 version: 3.3.0
6 build: 3167
7 */
8 YUI.add('loader-rollup', function(Y) {
9
10 /**
11  * Optional automatic rollup logic for reducing http connections
12  * when not using a combo service.
13  * @module loader
14  * @submodule rollup
15  */
16
17 /**
18  * Look for rollup packages to determine if all of the modules a
19  * rollup supersedes are required.  If so, include the rollup to
20  * help reduce the total number of connections required.  Called
21  * by calculate().  This is an optional feature, and requires the
22  * appropriate submodule to function.
23  * @method _rollup
24  * @for Loader
25  * @private
26  */
27 Y.Loader.prototype._rollup = function() {
28     var i, j, m, s, r = this.required, roll,
29         info = this.moduleInfo, rolled, c, smod;
30
31     // find and cache rollup modules
32     if (this.dirty || !this.rollups) {
33         this.rollups = {};
34         for (i in info) {
35             if (info.hasOwnProperty(i)) {
36                 m = this.getModule(i);
37                 // if (m && m.rollup && m.supersedes) {
38                 if (m && m.rollup) {
39                     this.rollups[i] = m;
40                 }
41             }
42         }
43
44         this.forceMap = (this.force) ? Y.Array.hash(this.force) : {};
45     }
46
47     // make as many passes as needed to pick up rollup rollups
48     for (;;) {
49         rolled = false;
50
51         // go through the rollup candidates
52         for (i in this.rollups) {
53             if (this.rollups.hasOwnProperty(i)) {
54                 // there can be only one, unless forced
55                 if (!r[i] && ((!this.loaded[i]) || this.forceMap[i])) {
56                     m = this.getModule(i);
57                     s = m.supersedes || [];
58                     roll = false;
59
60                     // @TODO remove continue
61                     if (!m.rollup) {
62                         continue;
63                     }
64
65                     c = 0;
66
67                     // check the threshold
68                     for (j = 0; j < s.length; j++) {
69                         smod = info[s[j]];
70
71                         // if the superseded module is loaded, we can't
72                         // load the rollup unless it has been forced.
73                         if (this.loaded[s[j]] && !this.forceMap[s[j]]) {
74                             roll = false;
75                             break;
76                         // increment the counter if this module is required.
77                         // if we are beyond the rollup threshold, we will
78                         // use the rollup module
79                         } else if (r[s[j]] && m.type == smod.type) {
80                             c++;
81                             roll = (c >= m.rollup);
82                             if (roll) {
83                                 break;
84                             }
85                         }
86                     }
87
88                     if (roll) {
89                         // add the rollup
90                         r[i] = true;
91                         rolled = true;
92
93                         // expand the rollup's dependencies
94                         this.getRequires(m);
95                     }
96                 }
97             }
98         }
99
100         // if we made it here w/o rolling up something, we are done
101         if (!rolled) {
102             break;
103         }
104     }
105 };
106
107
108
109 }, '3.3.0' ,{requires:['loader-base']});