-
Notifications
You must be signed in to change notification settings - Fork 0
/
eemd.js
94 lines (74 loc) · 2.1 KB
/
eemd.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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// Copyright (c) 2016 12 Quarters Consulting
//
// eeny meeny miney AMD loader
//
(function(win,doc){
var pending = {}, loaded = { require: 1, module: 1 };
(win.define = function( name, deps, body ) {
if( name in loaded )
throw Error( "Already defined: " + name );
loaded[name] = [ deps, body ];
(pending[name] || [])
.forEach( function(cb) { cb( deps ) } );
delete pending[name]
}).amd={}
function require_config( config ) {
var require = _require.bind( null, load ),
ready = { require: require, module: 1 };
require.config = require_config;
require.bundled = _require.bind( null, 0 );
return require;
function _require( load, module_dependencies, cb ) {
var count = 1;
provide( module_dependencies );
function provide( deps ) {
if( !(count += deps.filter(
function( dep ) {
return !(dep in loaded) && (
pending[dep] || (
load && load( dep ),
pending[dep]=[]
)
).push( provide )
}
).length - 1)
)
cb.apply( null, module_dependencies.map( init ) );
}
}
function init( mdl ) {
var deps, body, cfg;
return ready[mdl] || (ready[mdl] = (
deps = loaded[mdl][0].map( initDependency ),
typeof (body = loaded[mdl][1]) == 'function'
? body.apply( null, deps )
: body
))
function initDependency( dep ) {
return dep == "module"
? {
config: function() {
return cfg || matchPath( config.config, mdl, function( val ) { return cfg = val || {} } )
},
id: mdl
}
: init( dep )
}
}
function load( mdl ) {
var s = doc.createElement( "script" );
s.src = matchPath( config.paths || {}, mdl, function( base, pfx ) {
return (base || "") + mdl.substr( pfx.length )
} ) + ".js?" + (config.urlArgs || "");
s.async = true;
doc.head.appendChild( s );
}
}
win.require = require_config({});
function matchPath( cfg, path, cb ) {
while( path && !cfg[path] )
path = path.replace( /\/?[^/]*$/, "" );
return cb( cfg[path], path );
}
})(window,document)