requirejs-rails 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rvmrc +1 -1
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +49 -49
- data/README.md +1 -1
- data/bin/r.js +19560 -11580
- data/lib/requirejs/rails/config.rb +3 -0
- data/lib/requirejs/rails/engine.rb +36 -13
- data/lib/requirejs/rails/version.rb +2 -2
- data/lib/tasks/requirejs-rails_tasks.rake +1 -1
- data/vendor/assets/javascripts/almond.js +355 -273
- data/vendor/assets/javascripts/require.js +1802 -1846
- metadata +32 -11
@@ -32,10 +32,12 @@ module Requirejs::Rails
|
|
32
32
|
baseUrl
|
33
33
|
callback
|
34
34
|
catchError
|
35
|
+
config
|
35
36
|
context
|
36
37
|
deps
|
37
38
|
jQuery
|
38
39
|
locale
|
40
|
+
map
|
39
41
|
packages
|
40
42
|
paths
|
41
43
|
priority
|
@@ -61,6 +63,7 @@ module Requirejs::Rails
|
|
61
63
|
inlineText
|
62
64
|
locale
|
63
65
|
mainConfigFile
|
66
|
+
map
|
64
67
|
modules
|
65
68
|
name
|
66
69
|
namespace
|
@@ -7,24 +7,18 @@ module Requirejs
|
|
7
7
|
class Engine < ::Rails::Engine
|
8
8
|
|
9
9
|
### Configuration setup
|
10
|
-
config.before_configuration do
|
10
|
+
config.before_configuration do
|
11
11
|
config.requirejs = Requirejs::Rails::Config.new
|
12
12
|
config.requirejs.precompile = [/require\.js$/]
|
13
|
-
|
14
|
-
# Location of the user-supplied config parameters, which will be
|
15
|
-
# merged with the default params. It should be a YAML file with
|
16
|
-
# a single top-level hash, keys/values corresponding to require.js
|
17
|
-
# config parameters.
|
18
|
-
config.requirejs.user_config_file = Pathname.new(app.paths["config"].first)+'requirejs.yml'
|
19
|
-
if config.requirejs.user_config_file.exist?
|
20
|
-
config.requirejs.user_config = YAML.load(config.requirejs.user_config_file.read)
|
21
|
-
else
|
22
|
-
config.requirejs.user_config = {}
|
23
|
-
end
|
24
13
|
end
|
25
14
|
|
26
15
|
config.before_initialize do |app|
|
27
16
|
config = app.config
|
17
|
+
|
18
|
+
# Process the user config file in #before_initalization (instead of #before_configuration) so that
|
19
|
+
# environment-specific configuration can be injected into the user configuration file
|
20
|
+
process_user_config_file(app, config)
|
21
|
+
|
28
22
|
config.assets.precompile += config.requirejs.precompile
|
29
23
|
|
30
24
|
manifest_path = File.join(::Rails.public_path, config.assets.prefix, "rjs_manifest.yml")
|
@@ -43,11 +37,40 @@ module Requirejs
|
|
43
37
|
initializer "requirejs.manifest", :after => "sprockets.environment" do |app|
|
44
38
|
config = app.config
|
45
39
|
if config.requirejs.manifest_path.exist? && config.assets.digests
|
46
|
-
rjs_digests = YAML.
|
40
|
+
rjs_digests = YAML.load(ERB.new(File.new(config.requirejs.manifest_path).read).result)
|
47
41
|
config.assets.digests.merge!(rjs_digests)
|
48
42
|
end
|
49
43
|
end
|
50
44
|
|
45
|
+
private
|
46
|
+
|
47
|
+
# Process the user-supplied config parameters, which will be
|
48
|
+
# merged with the default params. It should be a YAML file with
|
49
|
+
# a single top-level hash, keys/values corresponding to require.js
|
50
|
+
# config parameters.
|
51
|
+
def process_user_config_file(app, config)
|
52
|
+
config_path = Pathname.new(app.paths["config"].first)
|
53
|
+
config.requirejs.user_config_file = config_path+'requirejs.yml'
|
54
|
+
|
55
|
+
yaml_file_contents = nil
|
56
|
+
if config.requirejs.user_config_file.exist?
|
57
|
+
yaml_file_contents = config.requirejs.user_config_file.read
|
58
|
+
else
|
59
|
+
# if requirejs.yml doesn't exist, look for requirejs.yml.erb and process it as an erb
|
60
|
+
config.requirejs.user_config_file = config_path+'requirejs.yml.erb'
|
61
|
+
|
62
|
+
if config.requirejs.user_config_file.exist?
|
63
|
+
yaml_file_contents = ERB.new(config.requirejs.user_config_file.read).result
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if yaml_file_contents.nil?
|
68
|
+
# If we couldn't find any matching file contents to process, empty user config
|
69
|
+
config.requirejs.user_config = {}
|
70
|
+
else
|
71
|
+
config.requirejs.user_config = YAML.load(yaml_file_contents)
|
72
|
+
end
|
73
|
+
end
|
51
74
|
end # class Engine
|
52
75
|
end
|
53
76
|
end
|
@@ -107,7 +107,7 @@ EOM
|
|
107
107
|
"requirejs:test_node"] do
|
108
108
|
requirejs.config.target_dir.mkpath
|
109
109
|
|
110
|
-
`node #{requirejs.config.driver_path}`
|
110
|
+
`node "#{requirejs.config.driver_path}"`
|
111
111
|
unless $?.success?
|
112
112
|
raise RuntimeError, "Asset compilation with node failed."
|
113
113
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* almond 0.
|
2
|
+
* almond 0.2.3 Copyright (c) 2011-2012, The Dojo Foundation All Rights Reserved.
|
3
3
|
* Available via the MIT or new BSD license.
|
4
4
|
* see: http://github.com/jrburke/almond for details
|
5
5
|
*/
|
@@ -10,305 +10,387 @@
|
|
10
10
|
|
11
11
|
var requirejs, require, define;
|
12
12
|
(function (undef) {
|
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
|
-
|
13
|
+
var main, req, makeMap, handlers,
|
14
|
+
defined = {},
|
15
|
+
waiting = {},
|
16
|
+
config = {},
|
17
|
+
defining = {},
|
18
|
+
hasOwn = Object.prototype.hasOwnProperty,
|
19
|
+
aps = [].slice;
|
20
|
+
|
21
|
+
function hasProp(obj, prop) {
|
22
|
+
return hasOwn.call(obj, prop);
|
23
|
+
}
|
24
|
+
|
25
|
+
/**
|
26
|
+
* Given a relative module name, like ./something, normalize it to
|
27
|
+
* a real name that can be mapped to a path.
|
28
|
+
* @param {String} name the relative name
|
29
|
+
* @param {String} baseName a real name that the name arg is relative
|
30
|
+
* to.
|
31
|
+
* @returns {String} normalized name
|
32
|
+
*/
|
33
|
+
function normalize(name, baseName) {
|
34
|
+
var nameParts, nameSegment, mapValue, foundMap,
|
35
|
+
foundI, foundStarMap, starI, i, j, part,
|
36
|
+
baseParts = baseName && baseName.split("/"),
|
37
|
+
map = config.map,
|
38
|
+
starMap = (map && map['*']) || {};
|
39
|
+
|
40
|
+
//Adjust any relative paths.
|
41
|
+
if (name && name.charAt(0) === ".") {
|
42
|
+
//If have a base name, try to normalize against it,
|
43
|
+
//otherwise, assume it is a top-level require that will
|
44
|
+
//be relative to baseUrl in the end.
|
45
|
+
if (baseName) {
|
46
|
+
//Convert baseName to array, and lop off the last part,
|
47
|
+
//so that . matches that "directory" and not name of the baseName's
|
48
|
+
//module. For instance, baseName of "one/two/three", maps to
|
49
|
+
//"one/two/three.js", but we want the directory, "one/two" for
|
50
|
+
//this normalization.
|
51
|
+
baseParts = baseParts.slice(0, baseParts.length - 1);
|
52
|
+
|
53
|
+
name = baseParts.concat(name.split("/"));
|
54
|
+
|
55
|
+
//start trimDots
|
56
|
+
for (i = 0; i < name.length; i += 1) {
|
57
|
+
part = name[i];
|
58
|
+
if (part === ".") {
|
59
|
+
name.splice(i, 1);
|
60
|
+
i -= 1;
|
61
|
+
} else if (part === "..") {
|
62
|
+
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
|
63
|
+
//End of the line. Keep at least one non-dot
|
64
|
+
//path segment at the front so it can be mapped
|
65
|
+
//correctly to disk. Otherwise, there is likely
|
66
|
+
//no path mapping for a path starting with '..'.
|
67
|
+
//This can still fail, but catches the most reasonable
|
68
|
+
//uses of ..
|
69
|
+
break;
|
70
|
+
} else if (i > 0) {
|
71
|
+
name.splice(i - 1, 2);
|
72
|
+
i -= 2;
|
72
73
|
}
|
74
|
+
}
|
73
75
|
}
|
76
|
+
//end trimDots
|
77
|
+
|
78
|
+
name = name.join("/");
|
79
|
+
} else if (name.indexOf('./') === 0) {
|
80
|
+
// No baseName, so this is ID is resolved relative
|
81
|
+
// to baseUrl, pull off the leading dot.
|
82
|
+
name = name.substring(2);
|
83
|
+
}
|
84
|
+
}
|
74
85
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
}
|
99
|
-
}
|
100
|
-
|
101
|
-
foundMap = foundMap || starMap[nameSegment];
|
102
|
-
|
103
|
-
if (foundMap) {
|
104
|
-
nameParts.splice(0, i, foundMap);
|
105
|
-
name = nameParts.join('/');
|
106
|
-
break;
|
107
|
-
}
|
86
|
+
//Apply map config if available.
|
87
|
+
if ((baseParts || starMap) && map) {
|
88
|
+
nameParts = name.split('/');
|
89
|
+
|
90
|
+
for (i = nameParts.length; i > 0; i -= 1) {
|
91
|
+
nameSegment = nameParts.slice(0, i).join("/");
|
92
|
+
|
93
|
+
if (baseParts) {
|
94
|
+
//Find the longest baseName segment match in the config.
|
95
|
+
//So, do joins on the biggest to smallest lengths of baseParts.
|
96
|
+
for (j = baseParts.length; j > 0; j -= 1) {
|
97
|
+
mapValue = map[baseParts.slice(0, j).join('/')];
|
98
|
+
|
99
|
+
//baseName segment has config, find if it has one for
|
100
|
+
//this name.
|
101
|
+
if (mapValue) {
|
102
|
+
mapValue = mapValue[nameSegment];
|
103
|
+
if (mapValue) {
|
104
|
+
//Match, update name to the new value.
|
105
|
+
foundMap = mapValue;
|
106
|
+
foundI = i;
|
107
|
+
break;
|
108
|
+
}
|
108
109
|
}
|
110
|
+
}
|
109
111
|
}
|
110
112
|
|
111
|
-
|
112
|
-
|
113
|
+
if (foundMap) {
|
114
|
+
break;
|
115
|
+
}
|
113
116
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
}
|
121
|
-
|
117
|
+
//Check for a star map match, but just hold on to it,
|
118
|
+
//if there is a shorter segment match later in a matching
|
119
|
+
//config, then favor over this star map.
|
120
|
+
if (!foundStarMap && starMap && starMap[nameSegment]) {
|
121
|
+
foundStarMap = starMap[nameSegment];
|
122
|
+
starI = i;
|
123
|
+
}
|
124
|
+
}
|
122
125
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
}
|
126
|
+
if (!foundMap && foundStarMap) {
|
127
|
+
foundMap = foundStarMap;
|
128
|
+
foundI = starI;
|
129
|
+
}
|
128
130
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
131
|
+
if (foundMap) {
|
132
|
+
nameParts.splice(0, foundI, foundMap);
|
133
|
+
name = nameParts.join('/');
|
134
|
+
}
|
133
135
|
}
|
134
136
|
|
135
|
-
|
136
|
-
|
137
|
-
var args = waiting[name];
|
138
|
-
delete waiting[name];
|
139
|
-
defining[name] = true;
|
140
|
-
main.apply(undef, args);
|
141
|
-
}
|
137
|
+
return name;
|
138
|
+
}
|
142
139
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
140
|
+
function makeRequire(relName, forceSync) {
|
141
|
+
return function () {
|
142
|
+
//A version of a require function that passes a moduleName
|
143
|
+
//value for items that may need to
|
144
|
+
//look up paths relative to the moduleName
|
145
|
+
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
|
146
|
+
};
|
147
|
+
}
|
148
148
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
function makeMap(name, relName) {
|
155
|
-
var prefix, plugin,
|
156
|
-
index = name.indexOf('!');
|
157
|
-
|
158
|
-
if (index !== -1) {
|
159
|
-
prefix = normalize(name.slice(0, index), relName);
|
160
|
-
name = name.slice(index + 1);
|
161
|
-
plugin = callDep(prefix);
|
162
|
-
|
163
|
-
//Normalize according
|
164
|
-
if (plugin && plugin.normalize) {
|
165
|
-
name = plugin.normalize(name, makeNormalize(relName));
|
166
|
-
} else {
|
167
|
-
name = normalize(name, relName);
|
168
|
-
}
|
169
|
-
} else {
|
170
|
-
name = normalize(name, relName);
|
171
|
-
}
|
149
|
+
function makeNormalize(relName) {
|
150
|
+
return function (name) {
|
151
|
+
return normalize(name, relName);
|
152
|
+
};
|
153
|
+
}
|
172
154
|
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
155
|
+
function makeLoad(depName) {
|
156
|
+
return function (value) {
|
157
|
+
defined[depName] = value;
|
158
|
+
};
|
159
|
+
}
|
160
|
+
|
161
|
+
function callDep(name) {
|
162
|
+
if (hasProp(waiting, name)) {
|
163
|
+
var args = waiting[name];
|
164
|
+
delete waiting[name];
|
165
|
+
defining[name] = true;
|
166
|
+
main.apply(undef, args);
|
179
167
|
}
|
180
168
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
169
|
+
if (!hasProp(defined, name) && !hasProp(defining, name)) {
|
170
|
+
throw new Error('No ' + name);
|
171
|
+
}
|
172
|
+
return defined[name];
|
173
|
+
}
|
174
|
+
|
175
|
+
//Turns a plugin!resource to [plugin, resource]
|
176
|
+
//with the plugin being undefined if the name
|
177
|
+
//did not have a plugin prefix.
|
178
|
+
function splitPrefix(name) {
|
179
|
+
var prefix,
|
180
|
+
index = name ? name.indexOf('!') : -1;
|
181
|
+
if (index > -1) {
|
182
|
+
prefix = name.substring(0, index);
|
183
|
+
name = name.substring(index + 1, name.length);
|
184
|
+
}
|
185
|
+
return [prefix, name];
|
186
|
+
}
|
187
|
+
|
188
|
+
/**
|
189
|
+
* Makes a name map, normalizing the name, and using a plugin
|
190
|
+
* for normalization if necessary. Grabs a ref to plugin
|
191
|
+
* too, as an optimization.
|
192
|
+
*/
|
193
|
+
makeMap = function (name, relName) {
|
194
|
+
var plugin,
|
195
|
+
parts = splitPrefix(name),
|
196
|
+
prefix = parts[0];
|
197
|
+
|
198
|
+
name = parts[1];
|
199
|
+
|
200
|
+
if (prefix) {
|
201
|
+
prefix = normalize(prefix, relName);
|
202
|
+
plugin = callDep(prefix);
|
185
203
|
}
|
186
204
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
map = makeMap(deps[i], relName);
|
204
|
-
depName = map.f;
|
205
|
-
|
206
|
-
//Fast path CommonJS standard dependencies.
|
207
|
-
if (depName === "require") {
|
208
|
-
args[i] = makeRequire(name);
|
209
|
-
} else if (depName === "exports") {
|
210
|
-
//CommonJS module spec 1.1
|
211
|
-
args[i] = defined[name] = {};
|
212
|
-
usingExports = true;
|
213
|
-
} else if (depName === "module") {
|
214
|
-
//CommonJS module spec 1.1
|
215
|
-
cjsModule = args[i] = {
|
216
|
-
id: name,
|
217
|
-
uri: '',
|
218
|
-
exports: defined[name],
|
219
|
-
config: makeConfig(name)
|
220
|
-
};
|
221
|
-
} else if (defined.hasOwnProperty(depName) || waiting.hasOwnProperty(depName)) {
|
222
|
-
args[i] = callDep(depName);
|
223
|
-
} else if (map.p) {
|
224
|
-
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
225
|
-
args[i] = defined[depName];
|
226
|
-
} else if (!defining[depName]) {
|
227
|
-
throw new Error(name + ' missing ' + depName);
|
228
|
-
}
|
229
|
-
}
|
205
|
+
//Normalize according
|
206
|
+
if (prefix) {
|
207
|
+
if (plugin && plugin.normalize) {
|
208
|
+
name = plugin.normalize(name, makeNormalize(relName));
|
209
|
+
} else {
|
210
|
+
name = normalize(name, relName);
|
211
|
+
}
|
212
|
+
} else {
|
213
|
+
name = normalize(name, relName);
|
214
|
+
parts = splitPrefix(name);
|
215
|
+
prefix = parts[0];
|
216
|
+
name = parts[1];
|
217
|
+
if (prefix) {
|
218
|
+
plugin = callDep(prefix);
|
219
|
+
}
|
220
|
+
}
|
230
221
|
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
if (cjsModule && cjsModule.exports !== undef &&
|
238
|
-
cjsModule.exports !== defined[name]) {
|
239
|
-
defined[name] = cjsModule.exports;
|
240
|
-
} else if (ret !== undef || !usingExports) {
|
241
|
-
//Use the return value from the function.
|
242
|
-
defined[name] = ret;
|
243
|
-
}
|
244
|
-
}
|
245
|
-
} else if (name) {
|
246
|
-
//May just be an object definition for the module. Only
|
247
|
-
//worry about defining if have a module name.
|
248
|
-
defined[name] = callback;
|
249
|
-
}
|
222
|
+
//Using ridiculous property names for space reasons
|
223
|
+
return {
|
224
|
+
f: prefix ? prefix + '!' + name : name, //fullName
|
225
|
+
n: name,
|
226
|
+
pr: prefix,
|
227
|
+
p: plugin
|
250
228
|
};
|
229
|
+
};
|
251
230
|
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
231
|
+
function makeConfig(name) {
|
232
|
+
return function () {
|
233
|
+
return (config && config.config && config.config[name]) || {};
|
234
|
+
};
|
235
|
+
}
|
236
|
+
|
237
|
+
handlers = {
|
238
|
+
require: function (name) {
|
239
|
+
return makeRequire(name);
|
240
|
+
},
|
241
|
+
exports: function (name) {
|
242
|
+
var e = defined[name];
|
243
|
+
if (typeof e !== 'undefined') {
|
244
|
+
return e;
|
245
|
+
} else {
|
246
|
+
return (defined[name] = {});
|
247
|
+
}
|
248
|
+
},
|
249
|
+
module: function (name) {
|
250
|
+
return {
|
251
|
+
id: name,
|
252
|
+
uri: '',
|
253
|
+
exports: defined[name],
|
254
|
+
config: makeConfig(name)
|
255
|
+
};
|
256
|
+
}
|
257
|
+
};
|
258
|
+
|
259
|
+
main = function (name, deps, callback, relName) {
|
260
|
+
var cjsModule, depName, ret, map, i,
|
261
|
+
args = [],
|
262
|
+
usingExports;
|
263
|
+
|
264
|
+
//Use name if no relName
|
265
|
+
relName = relName || name;
|
266
|
+
|
267
|
+
//Call the callback to define the module, if necessary.
|
268
|
+
if (typeof callback === 'function') {
|
269
|
+
|
270
|
+
//Pull out the defined dependencies and pass the ordered
|
271
|
+
//values to the callback.
|
272
|
+
//Default to [require, exports, module] if no deps
|
273
|
+
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
|
274
|
+
for (i = 0; i < deps.length; i += 1) {
|
275
|
+
map = makeMap(deps[i], relName);
|
276
|
+
depName = map.f;
|
277
|
+
|
278
|
+
//Fast path CommonJS standard dependencies.
|
279
|
+
if (depName === "require") {
|
280
|
+
args[i] = handlers.require(name);
|
281
|
+
} else if (depName === "exports") {
|
282
|
+
//CommonJS module spec 1.1
|
283
|
+
args[i] = handlers.exports(name);
|
284
|
+
usingExports = true;
|
285
|
+
} else if (depName === "module") {
|
286
|
+
//CommonJS module spec 1.1
|
287
|
+
cjsModule = args[i] = handlers.module(name);
|
288
|
+
} else if (hasProp(defined, depName) ||
|
289
|
+
hasProp(waiting, depName) ||
|
290
|
+
hasProp(defining, depName)) {
|
291
|
+
args[i] = callDep(depName);
|
292
|
+
} else if (map.p) {
|
293
|
+
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
294
|
+
args[i] = defined[depName];
|
279
295
|
} else {
|
280
|
-
|
281
|
-
|
282
|
-
|
296
|
+
throw new Error(name + ' missing ' + depName);
|
297
|
+
}
|
298
|
+
}
|
299
|
+
|
300
|
+
ret = callback.apply(defined[name], args);
|
301
|
+
|
302
|
+
if (name) {
|
303
|
+
//If setting exports via "module" is in play,
|
304
|
+
//favor that over return value and exports. After that,
|
305
|
+
//favor a non-undefined return value over exports use.
|
306
|
+
if (cjsModule && cjsModule.exports !== undef &&
|
307
|
+
cjsModule.exports !== defined[name]) {
|
308
|
+
defined[name] = cjsModule.exports;
|
309
|
+
} else if (ret !== undef || !usingExports) {
|
310
|
+
//Use the return value from the function.
|
311
|
+
defined[name] = ret;
|
283
312
|
}
|
313
|
+
}
|
314
|
+
} else if (name) {
|
315
|
+
//May just be an object definition for the module. Only
|
316
|
+
//worry about defining if have a module name.
|
317
|
+
defined[name] = callback;
|
318
|
+
}
|
319
|
+
};
|
320
|
+
|
321
|
+
requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
|
322
|
+
if (typeof deps === "string") {
|
323
|
+
if (handlers[deps]) {
|
324
|
+
//callback in this case is really relName
|
325
|
+
return handlers[deps](callback);
|
326
|
+
}
|
327
|
+
//Just return the module wanted. In this scenario, the
|
328
|
+
//deps arg is the module name, and second arg (if passed)
|
329
|
+
//is just the relName.
|
330
|
+
//Normalize module name, if it contains . or ..
|
331
|
+
return callDep(makeMap(deps, callback).f);
|
332
|
+
} else if (!deps.splice) {
|
333
|
+
//deps is a config object, not an array.
|
334
|
+
config = deps;
|
335
|
+
if (callback.splice) {
|
336
|
+
//callback is an array, which means it is a dependency list.
|
337
|
+
//Adjust args if there are dependencies
|
338
|
+
deps = callback;
|
339
|
+
callback = relName;
|
340
|
+
relName = null;
|
341
|
+
} else {
|
342
|
+
deps = undef;
|
343
|
+
}
|
344
|
+
}
|
284
345
|
|
285
|
-
|
286
|
-
};
|
346
|
+
//Support require(['a'])
|
347
|
+
callback = callback || function () {};
|
287
348
|
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
return req;
|
295
|
-
};
|
349
|
+
//If relName is a function, it is an errback handler,
|
350
|
+
//so remove it.
|
351
|
+
if (typeof relName === 'function') {
|
352
|
+
relName = forceSync;
|
353
|
+
forceSync = alt;
|
354
|
+
}
|
296
355
|
|
297
|
-
|
356
|
+
//Simulate async callback;
|
357
|
+
if (forceSync) {
|
358
|
+
main(undef, deps, callback, relName);
|
359
|
+
} else {
|
360
|
+
setTimeout(function () {
|
361
|
+
main(undef, deps, callback, relName);
|
362
|
+
}, 15);
|
363
|
+
}
|
298
364
|
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
365
|
+
return req;
|
366
|
+
};
|
367
|
+
|
368
|
+
/**
|
369
|
+
* Just drops the config on the floor, but returns req in case
|
370
|
+
* the config return value is used.
|
371
|
+
*/
|
372
|
+
req.config = function (cfg) {
|
373
|
+
config = cfg;
|
374
|
+
return req;
|
375
|
+
};
|
376
|
+
|
377
|
+
define = function (name, deps, callback) {
|
378
|
+
|
379
|
+
//This module may not have dependencies
|
380
|
+
if (!deps.splice) {
|
381
|
+
//deps is not an array, so probably means
|
382
|
+
//an object literal or factory function for
|
383
|
+
//the value. Adjust args.
|
384
|
+
callback = deps;
|
385
|
+
deps = [];
|
386
|
+
}
|
307
387
|
|
308
|
-
|
309
|
-
|
388
|
+
if (!hasProp(defined, name) && !hasProp(waiting, name)) {
|
389
|
+
waiting[name] = [name, deps, callback];
|
390
|
+
}
|
391
|
+
};
|
310
392
|
|
311
|
-
|
312
|
-
|
313
|
-
|
393
|
+
define.amd = {
|
394
|
+
jQuery: true
|
395
|
+
};
|
314
396
|
}());
|