-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwagon.js
94 lines (62 loc) · 1.37 KB
/
wagon.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
var Wagon = (function (j) {
// utils
// edited comented
// test
function buildErr(msg) {
return new Error(msg).toString();
}
function toArray(collection) {
return Array.prototype.slice.call(collection);
}
// loader features
var settedModules = new Object();
var setModule = function(key, value) {
settedModules[key] = value;
}
var exports = function(exp) {
var args = toArray(arguments);
try {
if(args.length == 1) {
if(j.isPlainObject(exp) || j.isFunction(exp)) {
return exp;
} else {
throw buildErr("export() argument must be function or object");
}
} else {
throw buildErr("export() argument must me single");
}
} catch(e) {
throw buildErr(e);
}
}
var require = function (path_p) {
var hold_data;
var hold_path = path_p;
function getScript() {
j.ajax(hold_path, {
async: false,
cache: false,
dataType: 'text',
success: function(data_p) {
hold_data = data_p
},
error: function(xhr, status, error) {
if(error == "Not Found") {
hold_path = settedModules[path_p];
if(!hold_path) {
throw buildErr("Path could not be found");
} else {
getScript();
}
}
}
})
} getScript();
return eval(hold_data);
}
return {
require: require,
exports: exports,
setModule: setModule
}
})(jQuery);