requirejs-rails 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile.lock +2 -2
- data/app/helpers/requirejs_helper.rb +4 -4
- data/bin/r.js +300 -106
- data/lib/requirejs/rails/engine.rb +9 -0
- data/lib/requirejs/rails/rjs_driver.js.erb +1 -2
- data/lib/requirejs/rails/version.rb +2 -2
- data/lib/tasks/requirejs-rails_tasks.rake +1 -17
- data/requirejs-rails.gemspec +3 -3
- data/vendor/assets/javascripts/almond.js +379 -363
- data/vendor/assets/javascripts/require.js +7 -7
- metadata +2 -15
@@ -20,6 +20,15 @@ module Requirejs
|
|
20
20
|
|
21
21
|
config.assets.precompile += config.requirejs.precompile
|
22
22
|
|
23
|
+
# Check for the existence of the requirejs:precompile:all top-level Rake task and disable asset pipeline
|
24
|
+
# compression to ensure that `r.js` gets uncompressed assets.
|
25
|
+
Rake.application.top_level_tasks.each do |task_name|
|
26
|
+
case task_name
|
27
|
+
when "requirejs:precompile:all"
|
28
|
+
config.assets.js_compressor = false
|
29
|
+
end
|
30
|
+
end if defined?(Rake.application)
|
31
|
+
|
23
32
|
manifest_directory = config.assets.manifest || File.join(::Rails.public_path, config.assets.prefix)
|
24
33
|
manifest_path = File.join(manifest_directory, "rjs_manifest.yml")
|
25
34
|
config.requirejs.manifest_path = Pathname.new(manifest_path)
|
@@ -35,11 +35,10 @@ var errback = function(error) {
|
|
35
35
|
// Do a series of builds of individual files, using the args suggested by:
|
36
36
|
// http://requirejs.org/docs/optimization.html#onejs
|
37
37
|
//
|
38
|
-
// r.js will eventually need a nested call idiom to handle async
|
38
|
+
// r.js will eventually need a nested call idiom to handle async
|
39
39
|
// builds. Anticipating that need.
|
40
40
|
var async_runner = module_specs.reduceRight(function(prev, curr) {
|
41
41
|
return function (buildReportText) {
|
42
|
-
requirejs.optimize(mix(curr), prev);
|
43
42
|
requirejs.optimize(mix(curr), prev, errback);
|
44
43
|
};
|
45
44
|
}, function(buildReportText) {} );
|
@@ -11,7 +11,7 @@ require 'active_support/ordered_options'
|
|
11
11
|
|
12
12
|
namespace :requirejs do
|
13
13
|
# This method was backported from an earlier version of Sprockets.
|
14
|
-
def ruby_rake_task(task)
|
14
|
+
def ruby_rake_task(task, force = true)
|
15
15
|
env = ENV["RAILS_ENV"] || "production"
|
16
16
|
groups = ENV["RAILS_GROUPS"] || "assets"
|
17
17
|
args = [$0, task, "RAILS_ENV=#{env}", "RAILS_GROUPS=#{groups}"]
|
@@ -77,19 +77,6 @@ OS X Homebrew users can use 'brew install node'.
|
|
77
77
|
"requirejs:precompile:run_rjs",
|
78
78
|
"requirejs:precompile:digestify_and_compress"]
|
79
79
|
|
80
|
-
task :disable_js_compressor do
|
81
|
-
# Ensure that Sprockets doesn't try to compress assets before they hit
|
82
|
-
# r.js. Failure to do this can cause a build which works in dev, but
|
83
|
-
# emits require.js "notloaded" errors, etc. in production.
|
84
|
-
#
|
85
|
-
# Note that a configuration block is used here to ensure that it runs
|
86
|
-
# after the environment ("config/application.rb",
|
87
|
-
# "config/environments/*.rb") has been set up.
|
88
|
-
Rails.application.config.assets.configure do |env|
|
89
|
-
env.js_compressor = nil
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
80
|
# Invoke another ruby process if we're called from inside
|
94
81
|
# assets:precompile so we don't clobber the environment
|
95
82
|
#
|
@@ -160,6 +147,3 @@ OS X Homebrew users can use 'brew install node'.
|
|
160
147
|
end
|
161
148
|
|
162
149
|
task "assets:precompile" => ["requirejs:precompile:external"]
|
163
|
-
if ARGV[0] == "requirejs:precompile:all"
|
164
|
-
task "assets:environment" => ["requirejs:precompile:disable_js_compressor"]
|
165
|
-
end
|
data/requirejs-rails.gemspec
CHANGED
@@ -16,10 +16,10 @@ Gem::Specification.new do |s|
|
|
16
16
|
git_test_files, git_files = `git ls-files`.split("\n").partition { |f| f =~ /^test/ }
|
17
17
|
s.test_files = git_test_files
|
18
18
|
s.files = git_files
|
19
|
-
s.require_path = 'lib'
|
19
|
+
s.require_path = 'lib'
|
20
20
|
|
21
|
-
s.add_dependency "railties", ">= 3.1.1"
|
22
|
-
s.add_development_dependency "rails", ">= 3.1.1"
|
21
|
+
s.add_dependency "railties", ">= 3.1.1"
|
22
|
+
s.add_development_dependency "rails", ">= 3.1.1"
|
23
23
|
s.add_development_dependency "sqlite3"
|
24
24
|
|
25
25
|
s.requirements << "node.js is required for 'rake assets:precompile', used to run the r.js build"
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* almond 0.2.
|
2
|
+
* @license almond 0.2.9 Copyright (c) 2011-2014, 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,396 +10,412 @@
|
|
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
|
-
* 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;
|
73
|
-
}
|
74
|
-
}
|
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
|
-
}
|
13
|
+
var main, req, makeMap, handlers,
|
14
|
+
defined = {},
|
15
|
+
waiting = {},
|
16
|
+
config = {},
|
17
|
+
defining = {},
|
18
|
+
hasOwn = Object.prototype.hasOwnProperty,
|
19
|
+
aps = [].slice,
|
20
|
+
jsSuffixRegExp = /\.js$/;
|
21
|
+
|
22
|
+
function hasProp(obj, prop) {
|
23
|
+
return hasOwn.call(obj, prop);
|
84
24
|
}
|
85
25
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
26
|
+
/**
|
27
|
+
* Given a relative module name, like ./something, normalize it to
|
28
|
+
* a real name that can be mapped to a path.
|
29
|
+
* @param {String} name the relative name
|
30
|
+
* @param {String} baseName a real name that the name arg is relative
|
31
|
+
* to.
|
32
|
+
* @returns {String} normalized name
|
33
|
+
*/
|
34
|
+
function normalize(name, baseName) {
|
35
|
+
var nameParts, nameSegment, mapValue, foundMap, lastIndex,
|
36
|
+
foundI, foundStarMap, starI, i, j, part,
|
37
|
+
baseParts = baseName && baseName.split("/"),
|
38
|
+
map = config.map,
|
39
|
+
starMap = (map && map['*']) || {};
|
40
|
+
|
41
|
+
//Adjust any relative paths.
|
42
|
+
if (name && name.charAt(0) === ".") {
|
43
|
+
//If have a base name, try to normalize against it,
|
44
|
+
//otherwise, assume it is a top-level require that will
|
45
|
+
//be relative to baseUrl in the end.
|
46
|
+
if (baseName) {
|
47
|
+
//Convert baseName to array, and lop off the last part,
|
48
|
+
//so that . matches that "directory" and not name of the baseName's
|
49
|
+
//module. For instance, baseName of "one/two/three", maps to
|
50
|
+
//"one/two/three.js", but we want the directory, "one/two" for
|
51
|
+
//this normalization.
|
52
|
+
baseParts = baseParts.slice(0, baseParts.length - 1);
|
53
|
+
name = name.split('/');
|
54
|
+
lastIndex = name.length - 1;
|
55
|
+
|
56
|
+
// Node .js allowance:
|
57
|
+
if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
|
58
|
+
name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
|
59
|
+
}
|
60
|
+
|
61
|
+
name = baseParts.concat(name);
|
62
|
+
|
63
|
+
//start trimDots
|
64
|
+
for (i = 0; i < name.length; i += 1) {
|
65
|
+
part = name[i];
|
66
|
+
if (part === ".") {
|
67
|
+
name.splice(i, 1);
|
68
|
+
i -= 1;
|
69
|
+
} else if (part === "..") {
|
70
|
+
if (i === 1 && (name[2] === '..' || name[0] === '..')) {
|
71
|
+
//End of the line. Keep at least one non-dot
|
72
|
+
//path segment at the front so it can be mapped
|
73
|
+
//correctly to disk. Otherwise, there is likely
|
74
|
+
//no path mapping for a path starting with '..'.
|
75
|
+
//This can still fail, but catches the most reasonable
|
76
|
+
//uses of ..
|
77
|
+
break;
|
78
|
+
} else if (i > 0) {
|
79
|
+
name.splice(i - 1, 2);
|
80
|
+
i -= 2;
|
81
|
+
}
|
82
|
+
}
|
83
|
+
}
|
84
|
+
//end trimDots
|
85
|
+
|
86
|
+
name = name.join("/");
|
87
|
+
} else if (name.indexOf('./') === 0) {
|
88
|
+
// No baseName, so this is ID is resolved relative
|
89
|
+
// to baseUrl, pull off the leading dot.
|
90
|
+
name = name.substring(2);
|
109
91
|
}
|
110
|
-
}
|
111
92
|
}
|
112
93
|
|
113
|
-
if
|
114
|
-
|
115
|
-
|
94
|
+
//Apply map config if available.
|
95
|
+
if ((baseParts || starMap) && map) {
|
96
|
+
nameParts = name.split('/');
|
97
|
+
|
98
|
+
for (i = nameParts.length; i > 0; i -= 1) {
|
99
|
+
nameSegment = nameParts.slice(0, i).join("/");
|
100
|
+
|
101
|
+
if (baseParts) {
|
102
|
+
//Find the longest baseName segment match in the config.
|
103
|
+
//So, do joins on the biggest to smallest lengths of baseParts.
|
104
|
+
for (j = baseParts.length; j > 0; j -= 1) {
|
105
|
+
mapValue = map[baseParts.slice(0, j).join('/')];
|
106
|
+
|
107
|
+
//baseName segment has config, find if it has one for
|
108
|
+
//this name.
|
109
|
+
if (mapValue) {
|
110
|
+
mapValue = mapValue[nameSegment];
|
111
|
+
if (mapValue) {
|
112
|
+
//Match, update name to the new value.
|
113
|
+
foundMap = mapValue;
|
114
|
+
foundI = i;
|
115
|
+
break;
|
116
|
+
}
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
if (foundMap) {
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
|
125
|
+
//Check for a star map match, but just hold on to it,
|
126
|
+
//if there is a shorter segment match later in a matching
|
127
|
+
//config, then favor over this star map.
|
128
|
+
if (!foundStarMap && starMap && starMap[nameSegment]) {
|
129
|
+
foundStarMap = starMap[nameSegment];
|
130
|
+
starI = i;
|
131
|
+
}
|
132
|
+
}
|
116
133
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
134
|
+
if (!foundMap && foundStarMap) {
|
135
|
+
foundMap = foundStarMap;
|
136
|
+
foundI = starI;
|
137
|
+
}
|
138
|
+
|
139
|
+
if (foundMap) {
|
140
|
+
nameParts.splice(0, foundI, foundMap);
|
141
|
+
name = nameParts.join('/');
|
142
|
+
}
|
123
143
|
}
|
124
|
-
}
|
125
144
|
|
126
|
-
|
127
|
-
|
128
|
-
foundI = starI;
|
129
|
-
}
|
145
|
+
return name;
|
146
|
+
}
|
130
147
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
148
|
+
function makeRequire(relName, forceSync) {
|
149
|
+
return function () {
|
150
|
+
//A version of a require function that passes a moduleName
|
151
|
+
//value for items that may need to
|
152
|
+
//look up paths relative to the moduleName
|
153
|
+
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
|
154
|
+
};
|
135
155
|
}
|
136
156
|
|
137
|
-
|
138
|
-
|
157
|
+
function makeNormalize(relName) {
|
158
|
+
return function (name) {
|
159
|
+
return normalize(name, relName);
|
160
|
+
};
|
161
|
+
}
|
139
162
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
return req.apply(undef, aps.call(arguments, 0).concat([relName, forceSync]));
|
146
|
-
};
|
147
|
-
}
|
163
|
+
function makeLoad(depName) {
|
164
|
+
return function (value) {
|
165
|
+
defined[depName] = value;
|
166
|
+
};
|
167
|
+
}
|
148
168
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
169
|
+
function callDep(name) {
|
170
|
+
if (hasProp(waiting, name)) {
|
171
|
+
var args = waiting[name];
|
172
|
+
delete waiting[name];
|
173
|
+
defining[name] = true;
|
174
|
+
main.apply(undef, args);
|
175
|
+
}
|
154
176
|
|
155
|
-
|
156
|
-
|
157
|
-
|
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);
|
177
|
+
if (!hasProp(defined, name) && !hasProp(defining, name)) {
|
178
|
+
throw new Error('No ' + name);
|
179
|
+
}
|
180
|
+
return defined[name];
|
167
181
|
}
|
168
182
|
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
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);
|
183
|
+
//Turns a plugin!resource to [plugin, resource]
|
184
|
+
//with the plugin being undefined if the name
|
185
|
+
//did not have a plugin prefix.
|
186
|
+
function splitPrefix(name) {
|
187
|
+
var prefix,
|
188
|
+
index = name ? name.indexOf('!') : -1;
|
189
|
+
if (index > -1) {
|
190
|
+
prefix = name.substring(0, index);
|
191
|
+
name = name.substring(index + 1, name.length);
|
192
|
+
}
|
193
|
+
return [prefix, name];
|
203
194
|
}
|
204
195
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
196
|
+
/**
|
197
|
+
* Makes a name map, normalizing the name, and using a plugin
|
198
|
+
* for normalization if necessary. Grabs a ref to plugin
|
199
|
+
* too, as an optimization.
|
200
|
+
*/
|
201
|
+
makeMap = function (name, relName) {
|
202
|
+
var plugin,
|
203
|
+
parts = splitPrefix(name),
|
204
|
+
prefix = parts[0];
|
205
|
+
|
206
|
+
name = parts[1];
|
207
|
+
|
208
|
+
if (prefix) {
|
209
|
+
prefix = normalize(prefix, relName);
|
210
|
+
plugin = callDep(prefix);
|
211
|
+
}
|
212
|
+
|
213
|
+
//Normalize according
|
214
|
+
if (prefix) {
|
215
|
+
if (plugin && plugin.normalize) {
|
216
|
+
name = plugin.normalize(name, makeNormalize(relName));
|
217
|
+
} else {
|
218
|
+
name = normalize(name, relName);
|
219
|
+
}
|
220
|
+
} else {
|
221
|
+
name = normalize(name, relName);
|
222
|
+
parts = splitPrefix(name);
|
223
|
+
prefix = parts[0];
|
224
|
+
name = parts[1];
|
225
|
+
if (prefix) {
|
226
|
+
plugin = callDep(prefix);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
|
230
|
+
//Using ridiculous property names for space reasons
|
231
|
+
return {
|
232
|
+
f: prefix ? prefix + '!' + name : name, //fullName
|
233
|
+
n: name,
|
234
|
+
pr: prefix,
|
235
|
+
p: plugin
|
236
|
+
};
|
237
|
+
};
|
238
|
+
|
239
|
+
function makeConfig(name) {
|
240
|
+
return function () {
|
241
|
+
return (config && config.config && config.config[name]) || {};
|
242
|
+
};
|
220
243
|
}
|
221
244
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
245
|
+
handlers = {
|
246
|
+
require: function (name) {
|
247
|
+
return makeRequire(name);
|
248
|
+
},
|
249
|
+
exports: function (name) {
|
250
|
+
var e = defined[name];
|
251
|
+
if (typeof e !== 'undefined') {
|
252
|
+
return e;
|
253
|
+
} else {
|
254
|
+
return (defined[name] = {});
|
255
|
+
}
|
256
|
+
},
|
257
|
+
module: function (name) {
|
258
|
+
return {
|
259
|
+
id: name,
|
260
|
+
uri: '',
|
261
|
+
exports: defined[name],
|
262
|
+
config: makeConfig(name)
|
263
|
+
};
|
264
|
+
}
|
228
265
|
};
|
229
|
-
};
|
230
266
|
|
231
|
-
|
232
|
-
|
233
|
-
|
267
|
+
main = function (name, deps, callback, relName) {
|
268
|
+
var cjsModule, depName, ret, map, i,
|
269
|
+
args = [],
|
270
|
+
callbackType = typeof callback,
|
271
|
+
usingExports;
|
272
|
+
|
273
|
+
//Use name if no relName
|
274
|
+
relName = relName || name;
|
275
|
+
|
276
|
+
//Call the callback to define the module, if necessary.
|
277
|
+
if (callbackType === 'undefined' || callbackType === 'function') {
|
278
|
+
//Pull out the defined dependencies and pass the ordered
|
279
|
+
//values to the callback.
|
280
|
+
//Default to [require, exports, module] if no deps
|
281
|
+
deps = !deps.length && callback.length ? ['require', 'exports', 'module'] : deps;
|
282
|
+
for (i = 0; i < deps.length; i += 1) {
|
283
|
+
map = makeMap(deps[i], relName);
|
284
|
+
depName = map.f;
|
285
|
+
|
286
|
+
//Fast path CommonJS standard dependencies.
|
287
|
+
if (depName === "require") {
|
288
|
+
args[i] = handlers.require(name);
|
289
|
+
} else if (depName === "exports") {
|
290
|
+
//CommonJS module spec 1.1
|
291
|
+
args[i] = handlers.exports(name);
|
292
|
+
usingExports = true;
|
293
|
+
} else if (depName === "module") {
|
294
|
+
//CommonJS module spec 1.1
|
295
|
+
cjsModule = args[i] = handlers.module(name);
|
296
|
+
} else if (hasProp(defined, depName) ||
|
297
|
+
hasProp(waiting, depName) ||
|
298
|
+
hasProp(defining, depName)) {
|
299
|
+
args[i] = callDep(depName);
|
300
|
+
} else if (map.p) {
|
301
|
+
map.p.load(map.n, makeRequire(relName, true), makeLoad(depName), {});
|
302
|
+
args[i] = defined[depName];
|
303
|
+
} else {
|
304
|
+
throw new Error(name + ' missing ' + depName);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
|
308
|
+
ret = callback ? callback.apply(defined[name], args) : undefined;
|
309
|
+
|
310
|
+
if (name) {
|
311
|
+
//If setting exports via "module" is in play,
|
312
|
+
//favor that over return value and exports. After that,
|
313
|
+
//favor a non-undefined return value over exports use.
|
314
|
+
if (cjsModule && cjsModule.exports !== undef &&
|
315
|
+
cjsModule.exports !== defined[name]) {
|
316
|
+
defined[name] = cjsModule.exports;
|
317
|
+
} else if (ret !== undef || !usingExports) {
|
318
|
+
//Use the return value from the function.
|
319
|
+
defined[name] = ret;
|
320
|
+
}
|
321
|
+
}
|
322
|
+
} else if (name) {
|
323
|
+
//May just be an object definition for the module. Only
|
324
|
+
//worry about defining if have a module name.
|
325
|
+
defined[name] = callback;
|
326
|
+
}
|
234
327
|
};
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
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];
|
295
|
-
} else {
|
296
|
-
throw new Error(name + ' missing ' + depName);
|
328
|
+
|
329
|
+
requirejs = require = req = function (deps, callback, relName, forceSync, alt) {
|
330
|
+
if (typeof deps === "string") {
|
331
|
+
if (handlers[deps]) {
|
332
|
+
//callback in this case is really relName
|
333
|
+
return handlers[deps](callback);
|
334
|
+
}
|
335
|
+
//Just return the module wanted. In this scenario, the
|
336
|
+
//deps arg is the module name, and second arg (if passed)
|
337
|
+
//is just the relName.
|
338
|
+
//Normalize module name, if it contains . or ..
|
339
|
+
return callDep(makeMap(deps, callback).f);
|
340
|
+
} else if (!deps.splice) {
|
341
|
+
//deps is a config object, not an array.
|
342
|
+
config = deps;
|
343
|
+
if (config.deps) {
|
344
|
+
req(config.deps, config.callback);
|
345
|
+
}
|
346
|
+
if (!callback) {
|
347
|
+
return;
|
348
|
+
}
|
349
|
+
|
350
|
+
if (callback.splice) {
|
351
|
+
//callback is an array, which means it is a dependency list.
|
352
|
+
//Adjust args if there are dependencies
|
353
|
+
deps = callback;
|
354
|
+
callback = relName;
|
355
|
+
relName = null;
|
356
|
+
} else {
|
357
|
+
deps = undef;
|
358
|
+
}
|
297
359
|
}
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
//
|
304
|
-
|
305
|
-
|
306
|
-
|
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;
|
360
|
+
|
361
|
+
//Support require(['a'])
|
362
|
+
callback = callback || function () {};
|
363
|
+
|
364
|
+
//If relName is a function, it is an errback handler,
|
365
|
+
//so remove it.
|
366
|
+
if (typeof relName === 'function') {
|
367
|
+
relName = forceSync;
|
368
|
+
forceSync = alt;
|
312
369
|
}
|
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
|
-
}
|
345
370
|
|
346
|
-
|
347
|
-
|
371
|
+
//Simulate async callback;
|
372
|
+
if (forceSync) {
|
373
|
+
main(undef, deps, callback, relName);
|
374
|
+
} else {
|
375
|
+
//Using a non-zero value because of concern for what old browsers
|
376
|
+
//do, and latest browsers "upgrade" to 4 if lower value is used:
|
377
|
+
//http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#dom-windowtimers-settimeout:
|
378
|
+
//If want a value immediately, use require('id') instead -- something
|
379
|
+
//that works in almond on the global level, but not guaranteed and
|
380
|
+
//unlikely to work in other AMD implementations.
|
381
|
+
setTimeout(function () {
|
382
|
+
main(undef, deps, callback, relName);
|
383
|
+
}, 4);
|
384
|
+
}
|
348
385
|
|
349
|
-
|
350
|
-
|
351
|
-
if (typeof relName === 'function') {
|
352
|
-
relName = forceSync;
|
353
|
-
forceSync = alt;
|
354
|
-
}
|
386
|
+
return req;
|
387
|
+
};
|
355
388
|
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
//If want a value immediately, use require('id') instead -- something
|
364
|
-
//that works in almond on the global level, but not guaranteed and
|
365
|
-
//unlikely to work in other AMD implementations.
|
366
|
-
setTimeout(function () {
|
367
|
-
main(undef, deps, callback, relName);
|
368
|
-
}, 4);
|
369
|
-
}
|
389
|
+
/**
|
390
|
+
* Just drops the config on the floor, but returns req in case
|
391
|
+
* the config return value is used.
|
392
|
+
*/
|
393
|
+
req.config = function (cfg) {
|
394
|
+
return req(cfg);
|
395
|
+
};
|
370
396
|
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
* Just drops the config on the floor, but returns req in case
|
376
|
-
* the config return value is used.
|
377
|
-
*/
|
378
|
-
req.config = function (cfg) {
|
379
|
-
config = cfg;
|
380
|
-
if (config.deps) {
|
381
|
-
req(config.deps, config.callback);
|
382
|
-
}
|
383
|
-
return req;
|
384
|
-
};
|
385
|
-
|
386
|
-
define = function (name, deps, callback) {
|
387
|
-
|
388
|
-
//This module may not have dependencies
|
389
|
-
if (!deps.splice) {
|
390
|
-
//deps is not an array, so probably means
|
391
|
-
//an object literal or factory function for
|
392
|
-
//the value. Adjust args.
|
393
|
-
callback = deps;
|
394
|
-
deps = [];
|
395
|
-
}
|
397
|
+
/**
|
398
|
+
* Expose module registry for debugging and tooling
|
399
|
+
*/
|
400
|
+
requirejs._defined = defined;
|
396
401
|
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
402
|
+
define = function (name, deps, callback) {
|
403
|
+
|
404
|
+
//This module may not have dependencies
|
405
|
+
if (!deps.splice) {
|
406
|
+
//deps is not an array, so probably means
|
407
|
+
//an object literal or factory function for
|
408
|
+
//the value. Adjust args.
|
409
|
+
callback = deps;
|
410
|
+
deps = [];
|
411
|
+
}
|
401
412
|
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
}
|
413
|
+
if (!hasProp(defined, name) && !hasProp(waiting, name)) {
|
414
|
+
waiting[name] = [name, deps, callback];
|
415
|
+
}
|
416
|
+
};
|
417
|
+
|
418
|
+
define.amd = {
|
419
|
+
jQuery: true
|
420
|
+
};
|
421
|
+
}());
|