1
1
/** 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.
3
3
* Available via the MIT or new BSD license.
4
4
* see: http://github.com/jrburke/requirejs for details
5
5
*/
@@ -12,7 +12,7 @@ var requirejs, require, define;
12
12
( function ( global ) {
13
13
var req , s , head , baseElement , dataMain , src ,
14
14
interactiveScript , currentlyAddingScript , mainScript , subPath ,
15
- version = '2.1.4 ' ,
15
+ version = '2.1.6 ' ,
16
16
commentRegExp = / ( \/ \* ( [ \s \S ] * ?) \* \/ | ( [ ^ : ] | ^ ) \/ \/ ( .* ) $ ) / mg,
17
17
cjsRequireRegExp = / [ ^ . ] \s * r e q u i r e \s * \( \s * [ " ' ] ( [ ^ ' " \s ] + ) [ " ' ] \s * \) / g,
18
18
jsSuffixRegExp = / \. j s $ / ,
@@ -22,7 +22,7 @@ var requirejs, require, define;
22
22
hasOwn = op . hasOwnProperty ,
23
23
ap = Array . prototype ,
24
24
apsp = ap . splice ,
25
- isBrowser = ! ! ( typeof window !== 'undefined' && navigator && document ) ,
25
+ isBrowser = ! ! ( typeof window !== 'undefined' && navigator && window . document ) ,
26
26
isWebWorker = ! isBrowser && typeof importScripts !== 'undefined' ,
27
27
//PS3 indicates loaded and complete, but need to wait for complete
28
28
//specifically. Sequence is 'loading', 'loaded', execution,
@@ -134,6 +134,10 @@ var requirejs, require, define;
134
134
return document . getElementsByTagName ( 'script' ) ;
135
135
}
136
136
137
+ function defaultOnError ( err ) {
138
+ throw err ;
139
+ }
140
+
137
141
//Allow getting a global that expressed in
138
142
//dot notation, like 'a.b.c'.
139
143
function getGlobal ( value ) {
@@ -191,15 +195,21 @@ var requirejs, require, define;
191
195
var inCheckLoaded , Module , context , handlers ,
192
196
checkLoadedTimeoutId ,
193
197
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.
194
201
waitSeconds : 7 ,
195
202
baseUrl : './' ,
196
203
paths : { } ,
197
204
pkgs : { } ,
198
205
shim : { } ,
199
- map : { } ,
200
206
config : { }
201
207
} ,
202
208
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 = { } ,
203
213
undefEvents = { } ,
204
214
defQueue = [ ] ,
205
215
defined = { } ,
@@ -295,7 +305,7 @@ var requirejs, require, define;
295
305
}
296
306
297
307
//Apply map config if available.
298
- if ( applyMap && ( baseParts || starMap ) && map ) {
308
+ if ( applyMap && map && ( baseParts || starMap ) ) {
299
309
nameParts = name . split ( '/' ) ;
300
310
301
311
for ( i = nameParts . length ; i > 0 ; i -= 1 ) {
@@ -494,7 +504,12 @@ var requirejs, require, define;
494
504
fn ( defined [ id ] ) ;
495
505
}
496
506
} 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
+ }
498
513
}
499
514
}
500
515
@@ -565,7 +580,13 @@ var requirejs, require, define;
565
580
id : mod . map . id ,
566
581
uri : mod . map . url ,
567
582
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 || { } ;
569
590
} ,
570
591
exports : defined [ mod . map . id ]
571
592
} ) ;
@@ -576,6 +597,7 @@ var requirejs, require, define;
576
597
function cleanRegistry ( id ) {
577
598
//Clean up machinery used for waiting modules.
578
599
delete registry [ id ] ;
600
+ delete enabledRegistry [ id ] ;
579
601
}
580
602
581
603
function breakCycle ( mod , traced , processed ) {
@@ -624,7 +646,7 @@ var requirejs, require, define;
624
646
inCheckLoaded = true ;
625
647
626
648
//Figure out the state of all the modules.
627
- eachProp ( registry , function ( mod ) {
649
+ eachProp ( enabledRegistry , function ( mod ) {
628
650
map = mod . map ;
629
651
modId = map . id ;
630
652
@@ -805,7 +827,7 @@ var requirejs, require, define;
805
827
} ,
806
828
807
829
/**
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,
809
831
* define it.
810
832
*/
811
833
check : function ( ) {
@@ -833,8 +855,13 @@ var requirejs, require, define;
833
855
if ( this . depCount < 1 && ! this . defined ) {
834
856
if ( isFunction ( factory ) ) {
835
857
//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 ) {
838
865
try {
839
866
exports = context . execCb ( id , factory , depExports , exports ) ;
840
867
} catch ( e ) {
@@ -862,8 +889,8 @@ var requirejs, require, define;
862
889
863
890
if ( err ) {
864
891
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 ';
867
894
return onError ( ( this . error = err ) ) ;
868
895
}
869
896
@@ -883,7 +910,7 @@ var requirejs, require, define;
883
910
}
884
911
885
912
//Clean up
886
- delete registry [ id ] ;
913
+ cleanRegistry ( id ) ;
887
914
888
915
this . defined = true ;
889
916
}
@@ -1049,6 +1076,7 @@ var requirejs, require, define;
1049
1076
} ,
1050
1077
1051
1078
enable : function ( ) {
1079
+ enabledRegistry [ this . map . id ] = this ;
1052
1080
this . enabled = true ;
1053
1081
1054
1082
//Set flag mentioning that the module is enabling,
@@ -1085,7 +1113,7 @@ var requirejs, require, define;
1085
1113
} ) ) ;
1086
1114
1087
1115
if ( this . errback ) {
1088
- on ( depMap , 'error' , this . errback ) ;
1116
+ on ( depMap , 'error' , bind ( this , this . errback ) ) ;
1089
1117
}
1090
1118
}
1091
1119
@@ -1208,6 +1236,7 @@ var requirejs, require, define;
1208
1236
Module : Module ,
1209
1237
makeModuleMap : makeModuleMap ,
1210
1238
nextTick : req . nextTick ,
1239
+ onError : onError ,
1211
1240
1212
1241
/**
1213
1242
* Set a configuration for the context.
@@ -1234,6 +1263,9 @@ var requirejs, require, define;
1234
1263
eachProp ( cfg , function ( value , prop ) {
1235
1264
if ( objs [ prop ] ) {
1236
1265
if ( prop === 'map' ) {
1266
+ if ( ! config . map ) {
1267
+ config . map = { } ;
1268
+ }
1237
1269
mixin ( config [ prop ] , value , true , true ) ;
1238
1270
} else {
1239
1271
mixin ( config [ prop ] , value , true ) ;
@@ -1345,7 +1377,7 @@ var requirejs, require, define;
1345
1377
//Synchronous access to one module. If require.get is
1346
1378
//available (as in the Node adapter), prefer that.
1347
1379
if ( req . get ) {
1348
- return req . get ( context , deps , relMap ) ;
1380
+ return req . get ( context , deps , relMap , localRequire ) ;
1349
1381
}
1350
1382
1351
1383
//Normalize module name, if it contains . or ..
@@ -1396,7 +1428,7 @@ var requirejs, require, define;
1396
1428
* plain URLs like nameToUrl.
1397
1429
*/
1398
1430
toUrl : function ( moduleNamePlusExt ) {
1399
- var ext , url ,
1431
+ var ext ,
1400
1432
index = moduleNamePlusExt . lastIndexOf ( '.' ) ,
1401
1433
segment = moduleNamePlusExt . split ( '/' ) [ 0 ] ,
1402
1434
isRelative = segment === '.' || segment === '..' ;
@@ -1408,9 +1440,8 @@ var requirejs, require, define;
1408
1440
moduleNamePlusExt = moduleNamePlusExt . substring ( 0 , index ) ;
1409
1441
}
1410
1442
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 ) ;
1414
1445
} ,
1415
1446
1416
1447
defined : function ( id ) {
@@ -1529,7 +1560,7 @@ var requirejs, require, define;
1529
1560
* it is assumed to have already been normalized. This is an
1530
1561
* internal API, not a public one. Use toUrl for the public API.
1531
1562
*/
1532
- nameToUrl : function ( moduleName , ext ) {
1563
+ nameToUrl : function ( moduleName , ext , skipExt ) {
1533
1564
var paths , pkgs , pkg , pkgPath , syms , i , parentModule , url ,
1534
1565
parentPath ;
1535
1566
@@ -1578,7 +1609,7 @@ var requirejs, require, define;
1578
1609
1579
1610
//Join the path parts together, then figure out if baseUrl is needed.
1580
1611
url = syms . join ( '/' ) ;
1581
- url += ( ext || ( / \? / . test ( url ) ? '' : '.js' ) ) ;
1612
+ url += ( ext || ( / \? / . test ( url ) || skipExt ? '' : '.js' ) ) ;
1582
1613
url = ( url . charAt ( 0 ) === '/' || url . match ( / ^ [ \w \+ \. \- ] + : / ) ? '' : config . baseUrl ) + url ;
1583
1614
}
1584
1615
@@ -1594,7 +1625,7 @@ var requirejs, require, define;
1594
1625
} ,
1595
1626
1596
1627
/**
1597
- * Executes a module callack function. Broken out as a separate function
1628
+ * Executes a module callback function. Broken out as a separate function
1598
1629
* solely to allow the build system to sequence the files in the built
1599
1630
* layer in the right sequence.
1600
1631
*
@@ -1632,7 +1663,7 @@ var requirejs, require, define;
1632
1663
onScriptError : function ( evt ) {
1633
1664
var data = getScriptData ( evt ) ;
1634
1665
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 ] ) ) ;
1636
1667
}
1637
1668
}
1638
1669
} ;
@@ -1761,9 +1792,7 @@ var requirejs, require, define;
1761
1792
* function. Intercept/override it if you want custom error handling.
1762
1793
* @param {Error } err the error object.
1763
1794
*/
1764
- req . onError = function ( err ) {
1765
- throw err ;
1766
- } ;
1795
+ req . onError = defaultOnError ;
1767
1796
1768
1797
/**
1769
1798
* Does the request to load a module for the browser case.
@@ -1817,7 +1846,7 @@ var requirejs, require, define;
1817
1846
node . attachEvent ( 'onreadystatechange' , context . onScriptLoad ) ;
1818
1847
//It would be great to add an error handler here to catch
1819
1848
//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
1821
1850
//is used, then IE will fire error before load, but we cannot
1822
1851
//use that pathway given the connect.microsoft.com issue
1823
1852
//mentioned above about not doing the 'script execute,
@@ -1846,16 +1875,24 @@ var requirejs, require, define;
1846
1875
1847
1876
return node ;
1848
1877
} 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
+ }
1859
1896
}
1860
1897
} ;
1861
1898
@@ -1887,24 +1924,31 @@ var requirejs, require, define;
1887
1924
//baseUrl, if it is not already set.
1888
1925
dataMain = script . getAttribute ( 'data-main' ) ;
1889
1926
if ( dataMain ) {
1927
+ //Preserve dataMain in case it is a path (i.e. contains '?')
1928
+ mainScript = dataMain ;
1929
+
1890
1930
//Set final baseUrl if there is not already an explicit one.
1891
1931
if ( ! cfg . baseUrl ) {
1892
1932
//Pull off the directory of data-main for use as the
1893
1933
//baseUrl.
1894
- src = dataMain . split ( '/' ) ;
1934
+ src = mainScript . split ( '/' ) ;
1895
1935
mainScript = src . pop ( ) ;
1896
1936
subPath = src . length ? src . join ( '/' ) + '/' : './' ;
1897
1937
1898
1938
cfg . baseUrl = subPath ;
1899
- dataMain = mainScript ;
1900
1939
}
1901
1940
1902
- //Strip off any trailing .js since dataMain is now
1941
+ //Strip off any trailing .js since mainScript is now
1903
1942
//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
+ }
1905
1949
1906
1950
//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 ] ;
1908
1952
1909
1953
return true ;
1910
1954
}
@@ -1932,12 +1976,13 @@ var requirejs, require, define;
1932
1976
//This module may not have dependencies
1933
1977
if ( ! isArray ( deps ) ) {
1934
1978
callback = deps ;
1935
- deps = [ ] ;
1979
+ deps = null ;
1936
1980
}
1937
1981
1938
1982
//If no name, and callback is a function, then figure out if it a
1939
1983
//CommonJS thing with dependencies.
1940
- if ( ! deps . length && isFunction ( callback ) ) {
1984
+ if ( ! deps && isFunction ( callback ) ) {
1985
+ deps = [ ] ;
1941
1986
//Remove comments from the callback string,
1942
1987
//look for require calls, and pull them into the dependencies,
1943
1988
//but only if there are function args.
0 commit comments