forked from requirejs/requirejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindexBuilder.js
More file actions
44 lines (36 loc) · 1.22 KB
/
indexBuilder.js
File metadata and controls
44 lines (36 loc) · 1.22 KB
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
(function () {
function parse(name) {
var parts = name.split('?'),
index = parseInt(parts[0], 10),
choices = parts[1].split(':'),
choice = choices[index];
return {
index: index,
choices: choices,
choice: choice
};
}
define({
normalize: function (name, normalize) {
var parsed = parse(name),
choices = parsed.choices;
//Normalize each path choice.
for (i = 0; i < choices.length; i++) {
choices[i] = normalize(choices[i]);
}
return parsed.index + '?' + choices.join(':');
},
load: function (name, req, load, config) {
req([parse(name).choice], function (value) {
load(value);
});
},
//This is strictly not necessary (and *not* recommended),
//but just doing it as a test.
write: function (pluginName, moduleName, write) {
var parsed = parse(moduleName);
write("define('" + pluginName + "!" + moduleName +
"', ['" + parsed.choice + "'], function (value) { return value;});\n");
}
});
}());