-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap.js
32 lines (29 loc) · 996 Bytes
/
wrap.js
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
/** @license
* RequireJS Wrap Plugin
* Author: Gabriel Giannattasio
* Created on: 2012/04/05
* Version: 0.0.2
* Released under the MIT license
*/
(function () {define({
load : function(name, req, onLoad, config){
if(!config.wrapper) config.wrapper = {};
var cfg = config.wrapper;
if(!cfg.globals) cfg.globals = {};
if(!cfg.deps) cfg.deps = {};
var toLoad = (cfg.deps[name] instanceof Array)? cfg.deps[name] : [];
toLoad.push(name);
req(toLoad, function () {
var name = toLoad[arguments.length-1];
var r = arguments[arguments.length-1];
var global;
if(cfg.globals[name] && typeof cfg.globals[name] === "function") {
global = cfg.globals[name]();
} else if(cfg.globals[name]) {
if(r) this[cfg.globals[name]] = r;
global = this[cfg.globals[name]];
}
onLoad(r || global);
});
}
});}());