Skip to content
This repository was archived by the owner on Jul 6, 2019. It is now read-only.

Commit 93f49c5

Browse files
committed
Upgrade RequireJS to 2.1.6. Upgrade RequireJS Text to 2.0.6.
1 parent 3a658f6 commit 93f49c5

File tree

2 files changed

+168
-64
lines changed

2 files changed

+168
-64
lines changed

app/js/lib/require/require.js

+90-45
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/** vim: et:ts=4:sw=4:sts=4
2-
* @license RequireJS 2.1.4 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
2+
* @license RequireJS 2.1.6 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
33
* Available via the MIT or new BSD license.
44
* see: http://github.com/jrburke/requirejs for details
55
*/
@@ -12,7 +12,7 @@ var requirejs, require, define;
1212
(function (global) {
1313
var req, s, head, baseElement, dataMain, src,
1414
interactiveScript, currentlyAddingScript, mainScript, subPath,
15-
version = '2.1.4',
15+
version = '2.1.6',
1616
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
1717
cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
1818
jsSuffixRegExp = /\.js$/,
@@ -22,7 +22,7 @@ var requirejs, require, define;
2222
hasOwn = op.hasOwnProperty,
2323
ap = Array.prototype,
2424
apsp = ap.splice,
25-
isBrowser = !!(typeof window !== 'undefined' && navigator && document),
25+
isBrowser = !!(typeof window !== 'undefined' && navigator && window.document),
2626
isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
2727
//PS3 indicates loaded and complete, but need to wait for complete
2828
//specifically. Sequence is 'loading', 'loaded', execution,
@@ -134,6 +134,10 @@ var requirejs, require, define;
134134
return document.getElementsByTagName('script');
135135
}
136136

137+
function defaultOnError(err) {
138+
throw err;
139+
}
140+
137141
//Allow getting a global that expressed in
138142
//dot notation, like 'a.b.c'.
139143
function getGlobal(value) {
@@ -191,15 +195,21 @@ var requirejs, require, define;
191195
var inCheckLoaded, Module, context, handlers,
192196
checkLoadedTimeoutId,
193197
config = {
198+
//Defaults. Do not set a default for map
199+
//config to speed up normalize(), which
200+
//will run faster if there is no default.
194201
waitSeconds: 7,
195202
baseUrl: './',
196203
paths: {},
197204
pkgs: {},
198205
shim: {},
199-
map: {},
200206
config: {}
201207
},
202208
registry = {},
209+
//registry of just enabled modules, to speed
210+
//cycle breaking code when lots of modules
211+
//are registered, but not activated.
212+
enabledRegistry = {},
203213
undefEvents = {},
204214
defQueue = [],
205215
defined = {},
@@ -295,7 +305,7 @@ var requirejs, require, define;
295305
}
296306

297307
//Apply map config if available.
298-
if (applyMap && (baseParts || starMap) && map) {
308+
if (applyMap && map && (baseParts || starMap)) {
299309
nameParts = name.split('/');
300310

301311
for (i = nameParts.length; i > 0; i -= 1) {
@@ -494,7 +504,12 @@ var requirejs, require, define;
494504
fn(defined[id]);
495505
}
496506
} else {
497-
getModule(depMap).on(name, fn);
507+
mod = getModule(depMap);
508+
if (mod.error && name === 'error') {
509+
fn(mod.error);
510+
} else {
511+
mod.on(name, fn);
512+
}
498513
}
499514
}
500515

@@ -565,7 +580,13 @@ var requirejs, require, define;
565580
id: mod.map.id,
566581
uri: mod.map.url,
567582
config: function () {
568-
return (config.config && getOwn(config.config, mod.map.id)) || {};
583+
var c,
584+
pkg = getOwn(config.pkgs, mod.map.id);
585+
// For packages, only support config targeted
586+
// at the main module.
587+
c = pkg ? getOwn(config.config, mod.map.id + '/' + pkg.main) :
588+
getOwn(config.config, mod.map.id);
589+
return c || {};
569590
},
570591
exports: defined[mod.map.id]
571592
});
@@ -576,6 +597,7 @@ var requirejs, require, define;
576597
function cleanRegistry(id) {
577598
//Clean up machinery used for waiting modules.
578599
delete registry[id];
600+
delete enabledRegistry[id];
579601
}
580602

581603
function breakCycle(mod, traced, processed) {
@@ -624,7 +646,7 @@ var requirejs, require, define;
624646
inCheckLoaded = true;
625647

626648
//Figure out the state of all the modules.
627-
eachProp(registry, function (mod) {
649+
eachProp(enabledRegistry, function (mod) {
628650
map = mod.map;
629651
modId = map.id;
630652

@@ -805,7 +827,7 @@ var requirejs, require, define;
805827
},
806828

807829
/**
808-
* Checks is the module is ready to define itself, and if so,
830+
* Checks if the module is ready to define itself, and if so,
809831
* define it.
810832
*/
811833
check: function () {
@@ -833,8 +855,13 @@ var requirejs, require, define;
833855
if (this.depCount < 1 && !this.defined) {
834856
if (isFunction(factory)) {
835857
//If there is an error listener, favor passing
836-
//to that instead of throwing an error.
837-
if (this.events.error) {
858+
//to that instead of throwing an error. However,
859+
//only do it for define()'d modules. require
860+
//errbacks should not be called for failures in
861+
//their callbacks (#699). However if a global
862+
//onError is set, use that.
863+
if ((this.events.error && this.map.isDefine) ||
864+
req.onError !== defaultOnError) {
838865
try {
839866
exports = context.execCb(id, factory, depExports, exports);
840867
} catch (e) {
@@ -862,8 +889,8 @@ var requirejs, require, define;
862889

863890
if (err) {
864891
err.requireMap = this.map;
865-
err.requireModules = [this.map.id];
866-
err.requireType = 'define';
892+
err.requireModules = this.map.isDefine ? [this.map.id] : null;
893+
err.requireType = this.map.isDefine ? 'define' : 'require';
867894
return onError((this.error = err));
868895
}
869896

@@ -883,7 +910,7 @@ var requirejs, require, define;
883910
}
884911

885912
//Clean up
886-
delete registry[id];
913+
cleanRegistry(id);
887914

888915
this.defined = true;
889916
}
@@ -1049,6 +1076,7 @@ var requirejs, require, define;
10491076
},
10501077

10511078
enable: function () {
1079+
enabledRegistry[this.map.id] = this;
10521080
this.enabled = true;
10531081

10541082
//Set flag mentioning that the module is enabling,
@@ -1085,7 +1113,7 @@ var requirejs, require, define;
10851113
}));
10861114

10871115
if (this.errback) {
1088-
on(depMap, 'error', this.errback);
1116+
on(depMap, 'error', bind(this, this.errback));
10891117
}
10901118
}
10911119

@@ -1208,6 +1236,7 @@ var requirejs, require, define;
12081236
Module: Module,
12091237
makeModuleMap: makeModuleMap,
12101238
nextTick: req.nextTick,
1239+
onError: onError,
12111240

12121241
/**
12131242
* Set a configuration for the context.
@@ -1234,6 +1263,9 @@ var requirejs, require, define;
12341263
eachProp(cfg, function (value, prop) {
12351264
if (objs[prop]) {
12361265
if (prop === 'map') {
1266+
if (!config.map) {
1267+
config.map = {};
1268+
}
12371269
mixin(config[prop], value, true, true);
12381270
} else {
12391271
mixin(config[prop], value, true);
@@ -1345,7 +1377,7 @@ var requirejs, require, define;
13451377
//Synchronous access to one module. If require.get is
13461378
//available (as in the Node adapter), prefer that.
13471379
if (req.get) {
1348-
return req.get(context, deps, relMap);
1380+
return req.get(context, deps, relMap, localRequire);
13491381
}
13501382

13511383
//Normalize module name, if it contains . or ..
@@ -1396,7 +1428,7 @@ var requirejs, require, define;
13961428
* plain URLs like nameToUrl.
13971429
*/
13981430
toUrl: function (moduleNamePlusExt) {
1399-
var ext, url,
1431+
var ext,
14001432
index = moduleNamePlusExt.lastIndexOf('.'),
14011433
segment = moduleNamePlusExt.split('/')[0],
14021434
isRelative = segment === '.' || segment === '..';
@@ -1408,9 +1440,8 @@ var requirejs, require, define;
14081440
moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
14091441
}
14101442

1411-
url = context.nameToUrl(normalize(moduleNamePlusExt,
1412-
relMap && relMap.id, true), ext || '.fake');
1413-
return ext ? url : url.substring(0, url.length - 5);
1443+
return context.nameToUrl(normalize(moduleNamePlusExt,
1444+
relMap && relMap.id, true), ext, true);
14141445
},
14151446

14161447
defined: function (id) {
@@ -1529,7 +1560,7 @@ var requirejs, require, define;
15291560
* it is assumed to have already been normalized. This is an
15301561
* internal API, not a public one. Use toUrl for the public API.
15311562
*/
1532-
nameToUrl: function (moduleName, ext) {
1563+
nameToUrl: function (moduleName, ext, skipExt) {
15331564
var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
15341565
parentPath;
15351566

@@ -1578,7 +1609,7 @@ var requirejs, require, define;
15781609

15791610
//Join the path parts together, then figure out if baseUrl is needed.
15801611
url = syms.join('/');
1581-
url += (ext || (/\?/.test(url) ? '' : '.js'));
1612+
url += (ext || (/\?/.test(url) || skipExt ? '' : '.js'));
15821613
url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
15831614
}
15841615

@@ -1594,7 +1625,7 @@ var requirejs, require, define;
15941625
},
15951626

15961627
/**
1597-
* Executes a module callack function. Broken out as a separate function
1628+
* Executes a module callback function. Broken out as a separate function
15981629
* solely to allow the build system to sequence the files in the built
15991630
* layer in the right sequence.
16001631
*
@@ -1632,7 +1663,7 @@ var requirejs, require, define;
16321663
onScriptError: function (evt) {
16331664
var data = getScriptData(evt);
16341665
if (!hasPathFallback(data.id)) {
1635-
return onError(makeError('scripterror', 'Script error', evt, [data.id]));
1666+
return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id]));
16361667
}
16371668
}
16381669
};
@@ -1761,9 +1792,7 @@ var requirejs, require, define;
17611792
* function. Intercept/override it if you want custom error handling.
17621793
* @param {Error} err the error object.
17631794
*/
1764-
req.onError = function (err) {
1765-
throw err;
1766-
};
1795+
req.onError = defaultOnError;
17671796

17681797
/**
17691798
* Does the request to load a module for the browser case.
@@ -1817,7 +1846,7 @@ var requirejs, require, define;
18171846
node.attachEvent('onreadystatechange', context.onScriptLoad);
18181847
//It would be great to add an error handler here to catch
18191848
//404s in IE9+. However, onreadystatechange will fire before
1820-
//the error handler, so that does not help. If addEvenListener
1849+
//the error handler, so that does not help. If addEventListener
18211850
//is used, then IE will fire error before load, but we cannot
18221851
//use that pathway given the connect.microsoft.com issue
18231852
//mentioned above about not doing the 'script execute,
@@ -1846,16 +1875,24 @@ var requirejs, require, define;
18461875

18471876
return node;
18481877
} else if (isWebWorker) {
1849-
//In a web worker, use importScripts. This is not a very
1850-
//efficient use of importScripts, importScripts will block until
1851-
//its script is downloaded and evaluated. However, if web workers
1852-
//are in play, the expectation that a build has been done so that
1853-
//only one script needs to be loaded anyway. This may need to be
1854-
//reevaluated if other use cases become common.
1855-
importScripts(url);
1856-
1857-
//Account for anonymous modules
1858-
context.completeLoad(moduleName);
1878+
try {
1879+
//In a web worker, use importScripts. This is not a very
1880+
//efficient use of importScripts, importScripts will block until
1881+
//its script is downloaded and evaluated. However, if web workers
1882+
//are in play, the expectation that a build has been done so that
1883+
//only one script needs to be loaded anyway. This may need to be
1884+
//reevaluated if other use cases become common.
1885+
importScripts(url);
1886+
1887+
//Account for anonymous modules
1888+
context.completeLoad(moduleName);
1889+
} catch (e) {
1890+
context.onError(makeError('importscripts',
1891+
'importScripts failed for ' +
1892+
moduleName + ' at ' + url,
1893+
e,
1894+
[moduleName]));
1895+
}
18591896
}
18601897
};
18611898

@@ -1887,24 +1924,31 @@ var requirejs, require, define;
18871924
//baseUrl, if it is not already set.
18881925
dataMain = script.getAttribute('data-main');
18891926
if (dataMain) {
1927+
//Preserve dataMain in case it is a path (i.e. contains '?')
1928+
mainScript = dataMain;
1929+
18901930
//Set final baseUrl if there is not already an explicit one.
18911931
if (!cfg.baseUrl) {
18921932
//Pull off the directory of data-main for use as the
18931933
//baseUrl.
1894-
src = dataMain.split('/');
1934+
src = mainScript.split('/');
18951935
mainScript = src.pop();
18961936
subPath = src.length ? src.join('/') + '/' : './';
18971937

18981938
cfg.baseUrl = subPath;
1899-
dataMain = mainScript;
19001939
}
19011940

1902-
//Strip off any trailing .js since dataMain is now
1941+
//Strip off any trailing .js since mainScript is now
19031942
//like a module name.
1904-
dataMain = dataMain.replace(jsSuffixRegExp, '');
1943+
mainScript = mainScript.replace(jsSuffixRegExp, '');
1944+
1945+
//If mainScript is still a path, fall back to dataMain
1946+
if (req.jsExtRegExp.test(mainScript)) {
1947+
mainScript = dataMain;
1948+
}
19051949

19061950
//Put the data-main script in the files to load.
1907-
cfg.deps = cfg.deps ? cfg.deps.concat(dataMain) : [dataMain];
1951+
cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript];
19081952

19091953
return true;
19101954
}
@@ -1932,12 +1976,13 @@ var requirejs, require, define;
19321976
//This module may not have dependencies
19331977
if (!isArray(deps)) {
19341978
callback = deps;
1935-
deps = [];
1979+
deps = null;
19361980
}
19371981

19381982
//If no name, and callback is a function, then figure out if it a
19391983
//CommonJS thing with dependencies.
1940-
if (!deps.length && isFunction(callback)) {
1984+
if (!deps && isFunction(callback)) {
1985+
deps = [];
19411986
//Remove comments from the callback string,
19421987
//look for require calls, and pull them into the dependencies,
19431988
//but only if there are function args.

0 commit comments

Comments
 (0)