Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

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