liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/***
* amd loader plugin which is used to load modules by sequence.
* mainly, this plugin is used to load js files which is not a amd module.
***/
define([
  "dojo/Deferred",
  "dojo/promise/all"
], function(Deferred, all) {
  var require;
  function doLoad(modules){
    var currentIndex = 0, allDefs = [], i, def;
    for(i = 0; i < modules.length; i++){
      def = new Deferred();
      def.module = modules[i];
      allDefs.push(def);
    }
 
    loadModule(allDefs, currentIndex);
 
    return allDefs;
  }
 
  function loadModule(allDefs, currentIndex){
    if(currentIndex + 1 > allDefs.length){
      return;
    }
    require([allDefs[currentIndex].module], function(){
      allDefs[currentIndex].resolve();
      currentIndex ++;
      loadModule(allDefs, currentIndex);
    });
  }
  return {
    load: function(id, _require, callback) {
      var parts = id.split(",");
      require = _require;
      if (parts.length === 0) {
        callback(null);
      } else {
        all(doLoad(parts)).then(function(){
          callback();
        });
      }
    }
  };
});