-
Notifications
You must be signed in to change notification settings - Fork 2
/
require.js
1884 lines (1678 loc) · 76.4 KB
/
require.js
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
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
72
73
74
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** vim: et:ts=4:sw=4:sts=4
* @license RequireJS 0.24.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
/*jslint strict: false, plusplus: false */
/*global window: false, navigator: false, document: false, importScripts: false,
jQuery: false, clearInterval: false, setInterval: false, self: false,
setTimeout: false, opera: false */
var require, define;
(function () {
//Change this version number for each release.
var version = "0.24.0",
commentRegExp = /(\/\*([\s\S]*?)\*\/|\/\/(.*)$)/mg,
cjsRequireRegExp = /require\(["']([^'"\s]+)["']\)/g,
currDirRegExp = /^\.\//,
jsSuffixRegExp = /\.js$/,
ostring = Object.prototype.toString,
ap = Array.prototype,
aps = ap.slice,
apsp = ap.splice,
isBrowser = !!(typeof window !== "undefined" && navigator && document),
isWebWorker = !isBrowser && typeof importScripts !== "undefined",
//PS3 indicates loaded and complete, but need to wait for complete
//specifically. Sequence is "loading", "loaded", execution,
// then "complete". The UA check is unfortunate, but not sure how
//to feature test w/o causing perf issues.
readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
/^complete$/ : /^(complete|loaded)$/,
defContextName = "_",
//Oh the tragedy, detecting opera. See the usage of isOpera for reason.
isOpera = typeof opera !== "undefined" && opera.toString() === "[object Opera]",
reqWaitIdPrefix = "_r@@",
empty = {},
contexts = {},
globalDefQueue = [],
interactiveScript = null,
isDone = false,
useInteractive = false,
req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script,
src, subPath, mainScript, dataMain, i, scrollIntervalId, setReadyState, ctx;
function isFunction(it) {
return ostring.call(it) === "[object Function]";
}
function isArray(it) {
return ostring.call(it) === "[object Array]";
}
/**
* Simple function to mix in properties from source into target,
* but only if target does not already have a property of the same name.
* This is not robust in IE for transferring methods that match
* Object.prototype names, but the uses of mixin here seem unlikely to
* trigger a problem related to that.
*/
function mixin(target, source, force) {
for (var prop in source) {
if (!(prop in empty) && (!(prop in target) || force)) {
target[prop] = source[prop];
}
}
return req;
}
/**
* Used to set up package paths from a packagePaths or packages config object.
* @param {Object} pkgs the object to store the new package config
* @param {Array} currentPackages an array of packages to configure
* @param {String} [dir] a prefix dir to use.
*/
function configurePackageDir(pkgs, currentPackages, dir) {
var i, location, pkgObj;
for (i = 0; (pkgObj = currentPackages[i]); i++) {
pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
location = pkgObj.location;
//Add dir to the path, but avoid paths that start with a slash
//or have a colon (indicates a protocol)
if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
location = dir + "/" + (location || pkgObj.name);
}
//Create a brand new object on pkgs, since currentPackages can
//be passed in again, and config.pkgs is the internal transformed
//state for all package configs.
pkgs[pkgObj.name] = {
name: pkgObj.name,
location: location || pkgObj.name,
lib: pkgObj.lib || "lib",
//Remove leading dot in main, so main paths are normalized,
//and remove any trailing .js, since different package
//envs have different conventions: some use a module name,
//some use a file name.
main: (pkgObj.main || "lib/main")
.replace(currDirRegExp, '')
.replace(jsSuffixRegExp, '')
};
}
}
//Check for an existing version of require. If so, then exit out. Only allow
//one version of require to be active in a page. However, allow for a require
//config object, just exit quickly if require is an actual function.
if (typeof require !== "undefined") {
if (isFunction(require)) {
return;
} else {
//assume it is a config object.
cfg = require;
}
}
/**
* Creates a new context for use in require and define calls.
* Handle most of the heavy lifting. Do not want to use an object
* with prototype here to avoid using "this" in require, in case it
* needs to be used in more super secure envs that do not want this.
* Also there should not be that many contexts in the page. Usually just
* one for the default context, but could be extra for multiversion cases
* or if a package needs a special context for a dependency that conflicts
* with the standard context.
*/
function newContext(contextName) {
var context, resume,
config = {
waitSeconds: 7,
baseUrl: s.baseUrl || "./",
paths: {},
pkgs: {}
},
defQueue = [],
specified = {
"require": true,
"exports": true,
"module": true
},
urlMap = {},
defined = {},
loaded = {},
waiting = {},
waitAry = [],
waitIdCounter = 0,
managerCallbacks = {},
plugins = {},
pluginsQueue = {},
resumeDepth = 0,
normalizedWaiting = {};
/**
* Trims the . and .. from an array of path segments.
* It will keep a leading path segment if a .. will become
* the first path segment, to help with module name lookups,
* which act like paths, but can be remapped. But the end result,
* all paths that use this function should look normalized.
* NOTE: this method MODIFIES the input array.
* @param {Array} ary the array of path segments.
*/
function trimDots(ary) {
var i, part;
for (i = 0; (part = ary[i]); i++) {
if (part === ".") {
ary.splice(i, 1);
i -= 1;
} else if (part === "..") {
if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
//End of the line. Keep at least one non-dot
//path segment at the front so it can be mapped
//correctly to disk. Otherwise, there is likely
//no path mapping for a path starting with '..'.
//This can still fail, but catches the most reasonable
//uses of ..
break;
} else if (i > 0) {
ary.splice(i - 1, 2);
i -= 2;
}
}
}
}
/**
* Given a relative module name, like ./something, normalize it to
* a real name that can be mapped to a path.
* @param {String} name the relative name
* @param {String} baseName a real name that the name arg is relative
* to.
* @returns {String} normalized name
*/
function normalize(name, baseName) {
var pkgName, pkgConfig;
//Adjust any relative paths.
if (name.charAt(0) === ".") {
//If have a base name, try to normalize against it,
//otherwise, assume it is a top-level require that will
//be relative to baseUrl in the end.
if (baseName) {
if (config.pkgs[baseName]) {
//If the baseName is a package name, then just treat it as one
//name to concat the name with.
baseName = [baseName];
} else {
//Convert baseName to array, and lop off the last part,
//so that . matches that "directory" and not name of the baseName's
//module. For instance, baseName of "one/two/three", maps to
//"one/two/three.js", but we want the directory, "one/two" for
//this normalization.
baseName = baseName.split("/");
baseName = baseName.slice(0, baseName.length - 1);
}
name = baseName.concat(name.split("/"));
trimDots(name);
//Some use of packages may use a . path to reference the
//"main" module name, so normalize for that.
pkgConfig = config.pkgs[(pkgName = name[0])];
name = name.join("/");
if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
name = pkgName;
}
}
}
return name;
}
/**
* Creates a module mapping that includes plugin prefix, module
* name, and path. If parentModuleMap is provided it will
* also normalize the name via require.normalize()
*
* @param {String} name the module name
* @param {String} [parentModuleMap] parent module map
* for the module name, used to resolve relative names.
*
* @returns {Object}
*/
function makeModuleMap(name, parentModuleMap) {
var index = name ? name.indexOf("!") : -1,
prefix = null,
parentName = parentModuleMap ? parentModuleMap.name : null,
originalName = name,
normalizedName, url, pluginModule;
if (index !== -1) {
prefix = name.substring(0, index);
name = name.substring(index + 1, name.length);
}
if (prefix) {
prefix = normalize(prefix, parentName);
}
//Account for relative paths if there is a base name.
if (name) {
if (prefix) {
pluginModule = defined[prefix];
if (pluginModule) {
//Plugin is loaded, use its normalize method, otherwise,
//normalize name as usual.
if (pluginModule.normalize) {
normalizedName = pluginModule.normalize(name, function (name) {
return normalize(name, parentName);
});
} else {
normalizedName = normalize(name, parentName);
}
} else {
//Plugin is not loaded yet, so do not normalize
//the name, wait for plugin to load to see if
//it has a normalize method. To avoid possible
//ambiguity with relative names loaded from another
//plugin, use the parent's name as part of this name.
normalizedName = '__$p' + parentName + '@' + name;
}
} else {
normalizedName = normalize(name, parentName);
}
url = urlMap[normalizedName];
if (!url) {
//Calculate url for the module, if it has a name.
if (req.toModuleUrl) {
//Special logic required for a particular engine,
//like Node.
url = req.toModuleUrl(context, name, parentModuleMap);
} else {
url = context.nameToUrl(name, null, parentModuleMap);
}
//Store the URL mapping for later.
urlMap[normalizedName] = url;
}
}
return {
prefix: prefix,
name: normalizedName,
parentMap: parentModuleMap,
url: url,
originalName: originalName,
fullName: prefix ? prefix + "!" + normalizedName : normalizedName
};
}
/**
* Determine if priority loading is done. If so clear the priorityWait
*/
function isPriorityDone() {
var priorityDone = true,
priorityWait = config.priorityWait,
priorityName, i;
if (priorityWait) {
for (i = 0; (priorityName = priorityWait[i]); i++) {
if (!loaded[priorityName]) {
priorityDone = false;
break;
}
}
if (priorityDone) {
delete config.priorityWait;
}
}
return priorityDone;
}
/**
* Helper function that creates a setExports function for a "module"
* CommonJS dependency. Do this here to avoid creating a closure that
* is part of a loop.
*/
function makeSetExports(moduleObj) {
return function (exports) {
moduleObj.exports = exports;
};
}
function makeContextModuleFunc(func, relModuleMap, enableBuildCallback) {
return function () {
//A version of a require function that passes a moduleName
//value for items that may need to
//look up paths relative to the moduleName
var args = [].concat(aps.call(arguments, 0)), lastArg;
if (enableBuildCallback &&
isFunction((lastArg = args[args.length - 1]))) {
lastArg.__requireJsBuild = true;
}
args.push(relModuleMap);
return func.apply(null, args);
};
}
/**
* Helper function that creates a require function object to give to
* modules that ask for it as a dependency. It needs to be specific
* per module because of the implication of path mappings that may
* need to be relative to the module name.
*/
function makeRequire(relModuleMap, enableBuildCallback) {
var modRequire = makeContextModuleFunc(context.require, relModuleMap, enableBuildCallback);
mixin(modRequire, {
nameToUrl: makeContextModuleFunc(context.nameToUrl, relModuleMap),
toUrl: makeContextModuleFunc(context.toUrl, relModuleMap),
isDefined: makeContextModuleFunc(context.isDefined, relModuleMap),
ready: req.ready,
isBrowser: req.isBrowser
});
//Something used by node.
if (req.paths) {
modRequire.paths = req.paths;
}
return modRequire;
}
/**
* Used to update the normalized name for plugin-based dependencies
* after a plugin loads, since it can have its own normalization structure.
* @param {String} pluginName the normalized plugin module name.
*/
function updateNormalizedNames(pluginName) {
var oldFullName, oldModuleMap, moduleMap, fullName, callbacks,
i, j, k, depArray, existingCallbacks,
maps = normalizedWaiting[pluginName];
if (maps) {
for (i = 0; (oldModuleMap = maps[i]); i++) {
oldFullName = oldModuleMap.fullName;
moduleMap = makeModuleMap(oldModuleMap.originalName, oldModuleMap.parentMap);
fullName = moduleMap.fullName;
//Callbacks could be undefined if the same plugin!name was
//required twice in a row, so use empty array in that case.
callbacks = managerCallbacks[oldFullName] || [];
existingCallbacks = managerCallbacks[fullName];
if (fullName !== oldFullName) {
//Update the specified object, but only if it is already
//in there. In sync environments, it may not be yet.
if (oldFullName in specified) {
delete specified[oldFullName];
specified[fullName] = true;
}
//Update managerCallbacks to use the correct normalized name.
//If there are already callbacks for the normalized name,
//just add to them.
if (existingCallbacks) {
managerCallbacks[fullName] = existingCallbacks.concat(callbacks);
} else {
managerCallbacks[fullName] = callbacks;
}
delete managerCallbacks[oldFullName];
//In each manager callback, update the normalized name in the depArray.
for (j = 0; j < callbacks.length; j++) {
depArray = callbacks[j].depArray;
for (k = 0; k < depArray.length; k++) {
if (depArray[k] === oldFullName) {
depArray[k] = fullName;
}
}
}
}
}
}
delete normalizedWaiting[pluginName];
}
/*
* Queues a dependency for checking after the loader is out of a
* "paused" state, for example while a script file is being loaded
* in the browser, where it may have many modules defined in it.
*
* depName will be fully qualified, no relative . or .. path.
*/
function queueDependency(dep) {
//Make sure to load any plugin and associate the dependency
//with that plugin.
var prefix = dep.prefix,
fullName = dep.fullName;
//Do not bother if the depName is already in transit
if (specified[fullName] || fullName in defined) {
return;
}
if (prefix && !plugins[prefix]) {
//Queue up loading of the dependency, track it
//via context.plugins. Mark it as a plugin so
//that the build system will know to treat it
//special.
plugins[prefix] = undefined;
//Remember this dep that needs to have normaliztion done
//after the plugin loads.
(normalizedWaiting[prefix] || (normalizedWaiting[prefix] = []))
.push(dep);
//Register an action to do once the plugin loads, to update
//all managerCallbacks to use a properly normalized module
//name.
(managerCallbacks[prefix] ||
(managerCallbacks[prefix] = [])).push({
onDep: function (name, value) {
if (name === prefix) {
updateNormalizedNames(prefix);
}
}
});
queueDependency(makeModuleMap(prefix));
}
context.paused.push(dep);
}
function execManager(manager) {
var i, ret, waitingCallbacks,
cb = manager.callback,
fullName = manager.fullName,
args = [],
ary = manager.depArray;
//Call the callback to define the module, if necessary.
if (cb && isFunction(cb)) {
//Pull out the defined dependencies and pass the ordered
//values to the callback.
if (ary) {
for (i = 0; i < ary.length; i++) {
args.push(manager.deps[ary[i]]);
}
}
ret = req.execCb(fullName, manager.callback, args);
if (fullName) {
//If using exports and the function did not return a value,
//and the "module" object for this definition function did not
//define an exported value, then use the exports object.
if (manager.usingExports && ret === undefined && (!manager.cjsModule || !("exports" in manager.cjsModule))) {
ret = defined[fullName];
} else {
if (manager.cjsModule && "exports" in manager.cjsModule) {
ret = defined[fullName] = manager.cjsModule.exports;
} else {
if (fullName in defined && !manager.usingExports) {
return req.onError(new Error(fullName + " has already been defined"));
}
defined[fullName] = ret;
}
}
}
} else if (fullName) {
//May just be an object definition for the module. Only
//worry about defining if have a module name.
ret = defined[fullName] = cb;
}
if (fullName) {
//If anything was waiting for this module to be defined,
//notify them now.
waitingCallbacks = managerCallbacks[fullName];
if (waitingCallbacks) {
for (i = 0; i < waitingCallbacks.length; i++) {
waitingCallbacks[i].onDep(fullName, ret);
}
delete managerCallbacks[fullName];
}
}
//Clean up waiting.
if (waiting[manager.waitId]) {
delete waiting[manager.waitId];
manager.isDone = true;
context.waitCount -= 1;
if (context.waitCount === 0) {
//Clear the wait array used for cycles.
waitAry = [];
}
}
return undefined;
}
function main(inName, depArray, callback, relModuleMap) {
var moduleMap = makeModuleMap(inName, relModuleMap),
name = moduleMap.name,
fullName = moduleMap.fullName,
uniques = {},
manager = {
//Use a wait ID because some entries are anon
//async require calls.
waitId: name || reqWaitIdPrefix + (waitIdCounter++),
depCount: 0,
depMax: 0,
prefix: moduleMap.prefix,
name: name,
fullName: fullName,
deps: {},
depArray: depArray,
callback: callback,
onDep: function (depName, value) {
if (!(depName in manager.deps)) {
manager.deps[depName] = value;
manager.depCount += 1;
if (manager.depCount === manager.depMax) {
//All done, execute!
execManager(manager);
}
}
}
},
i, depArg, depName, cjsMod;
if (fullName) {
//If module already defined for context, or already loaded,
//then leave.
if (fullName in defined || loaded[fullName] === true) {
return;
}
//Set specified/loaded here for modules that are also loaded
//as part of a layer, where onScriptLoad is not fired
//for those cases. Do this after the inline define and
//dependency tracing is done.
//Also check if auto-registry of jQuery needs to be skipped.
specified[fullName] = true;
loaded[fullName] = true;
context.jQueryDef = (fullName === "jquery");
}
//Add the dependencies to the deps field, and register for callbacks
//on the dependencies.
for (i = 0; i < depArray.length; i++) {
depArg = depArray[i];
//There could be cases like in IE, where a trailing comma will
//introduce a null dependency, so only treat a real dependency
//value as a dependency.
if (depArg) {
//Split the dependency name into plugin and name parts
depArg = makeModuleMap(depArg, (name ? moduleMap : relModuleMap));
depName = depArg.fullName;
//Fix the name in depArray to be just the name, since
//that is how it will be called back later.
depArray[i] = depName;
//Fast path CommonJS standard dependencies.
if (depName === "require") {
manager.deps[depName] = makeRequire(moduleMap);
} else if (depName === "exports") {
//CommonJS module spec 1.1
manager.deps[depName] = defined[fullName] = {};
manager.usingExports = true;
} else if (depName === "module") {
//CommonJS module spec 1.1
manager.cjsModule = cjsMod = manager.deps[depName] = {
id: name,
uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined
};
cjsMod.setExports = makeSetExports(cjsMod);
} else if (depName in defined && !(depName in waiting)) {
//Module already defined, no need to wait for it.
manager.deps[depName] = defined[depName];
} else if (!uniques[depName]) {
//A dynamic dependency.
manager.depMax += 1;
queueDependency(depArg);
//Register to get notification when dependency loads.
(managerCallbacks[depName] ||
(managerCallbacks[depName] = [])).push(manager);
uniques[depName] = true;
}
}
}
//Do not bother tracking the manager if it is all done.
if (manager.depCount === manager.depMax) {
//All done, execute!
execManager(manager);
} else {
waiting[manager.waitId] = manager;
waitAry.push(manager);
context.waitCount += 1;
}
}
/**
* Convenience method to call main for a require.def call that was put on
* hold in the defQueue.
*/
function callDefMain(args) {
main.apply(null, args);
//Mark the module loaded. Must do it here in addition
//to doing it in require.def in case a script does
//not call require.def
loaded[args[0]] = true;
}
/**
* As of jQuery 1.4.3, it supports a readyWait property that will hold off
* calling jQuery ready callbacks until all scripts are loaded. Be sure
* to track it if readyWait is available. Also, since jQuery 1.4.3 does
* not register as a module, need to do some global inference checking.
* Even if it does register as a module, not guaranteed to be the precise
* name of the global. If a jQuery is tracked for this context, then go
* ahead and register it as a module too, if not already in process.
*/
function jQueryCheck(jqCandidate) {
if (!context.jQuery) {
var $ = jqCandidate || (typeof jQuery !== "undefined" ? jQuery : null);
if ($ && "readyWait" in $) {
context.jQuery = $;
//Manually create a "jquery" module entry if not one already
//or in process.
callDefMain(["jquery", [], function () {
return jQuery;
}]);
//Increment jQuery readyWait if ncecessary.
if (context.scriptCount) {
$.readyWait += 1;
context.jQueryIncremented = true;
}
}
}
}
function forceExec(manager, traced) {
if (manager.isDone) {
return undefined;
}
var fullName = manager.fullName,
depArray = manager.depArray,
depName, i;
if (fullName) {
if (traced[fullName]) {
return defined[fullName];
}
traced[fullName] = true;
}
//forceExec all of its dependencies.
for (i = 0; i < depArray.length; i++) {
//Some array members may be null, like if a trailing comma
//IE, so do the explicit [i] access and check if it has a value.
depName = depArray[i];
if (depName) {
if (!manager.deps[depName] && waiting[depName]) {
manager.onDep(depName, forceExec(waiting[depName], traced));
}
}
}
return fullName ? defined[fullName] : undefined;
}
/**
* Checks if all modules for a context are loaded, and if so, evaluates the
* new ones in right dependency order.
*
* @private
*/
function checkLoaded() {
var waitInterval = config.waitSeconds * 1000,
//It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
noLoads = "", hasLoadedProp = false, stillLoading = false, prop,
err, manager;
//If there are items still in the paused queue processing wait.
//This is particularly important in the sync case where each paused
//item is processed right away but there may be more waiting.
if (context.pausedCount > 0) {
return undefined;
}
//Determine if priority loading is done. If so clear the priority. If
//not, then do not check
if (config.priorityWait) {
if (isPriorityDone()) {
//Call resume, since it could have
//some waiting dependencies to trace.
resume();
} else {
return undefined;
}
}
//See if anything is still in flight.
for (prop in loaded) {
if (!(prop in empty)) {
hasLoadedProp = true;
if (!loaded[prop]) {
if (expired) {
noLoads += prop + " ";
} else {
stillLoading = true;
break;
}
}
}
}
//Check for exit conditions.
if (!hasLoadedProp && !context.waitCount) {
//If the loaded object had no items, then the rest of
//the work below does not need to be done.
return undefined;
}
if (expired && noLoads) {
//If wait time expired, throw error of unloaded modules.
err = new Error("require.js load timeout for modules: " + noLoads);
err.requireType = "timeout";
err.requireModules = noLoads;
return req.onError(err);
}
if (stillLoading || context.scriptCount) {
//Something is still waiting to load. Wait for it.
if (isBrowser || isWebWorker) {
setTimeout(checkLoaded, 50);
}
return undefined;
}
//If still have items in the waiting cue, but all modules have
//been loaded, then it means there are some circular dependencies
//that need to be broken.
//However, as a waiting thing is fired, then it can add items to
//the waiting cue, and those items should not be fired yet, so
//make sure to redo the checkLoaded call after breaking a single
//cycle, if nothing else loaded then this logic will pick it up
//again.
if (context.waitCount) {
//Cycle through the waitAry, and call items in sequence.
for (i = 0; (manager = waitAry[i]); i++) {
forceExec(manager, {});
}
checkLoaded();
return undefined;
}
//Check for DOM ready, and nothing is waiting across contexts.
req.checkReadyState();
return undefined;
}
function callPlugin(pluginName, dep) {
var name = dep.name,
fullName = dep.fullName,
load;
//Do not bother if plugin is already defined or being loaded.
if (fullName in defined || fullName in loaded) {
return;
}
if (!plugins[pluginName]) {
plugins[pluginName] = defined[pluginName];
}
//Only set loaded to false for tracking if it has not already been set.
if (!loaded[fullName]) {
loaded[fullName] = false;
}
load = function (ret) {
//Allow the build process to register plugin-loaded dependencies.
if (require.onPluginLoad) {
require.onPluginLoad(context, pluginName, name, ret);
}
execManager({
prefix: dep.prefix,
name: dep.name,
fullName: dep.fullName,
callback: function () {
return ret;
}
});
loaded[fullName] = true;
};
//Allow plugins to load other code without having to know the
//context or how to "complete" the load.
load.fromText = function (moduleName, text) {
/*jslint evil: true */
var hasInteractive = useInteractive;
//Indicate a the module is in process of loading.
context.loaded[moduleName] = false;
context.scriptCount += 1;
//Turn off interactive script matching for IE for any define
//calls in the text, then turn it back on at the end.
if (hasInteractive) {
useInteractive = false;
}
eval(text);
if (hasInteractive) {
useInteractive = true;
}
//Support anonymous modules.
context.completeLoad(moduleName);
};
//Use parentName here since the plugin's name is not reliable,
//could be some weird string with no path that actually wants to
//reference the parentName's path.
plugins[pluginName].load(name, makeRequire(dep.parentMap, true), load, config);
}
function loadPaused(dep) {
//Renormalize dependency if its name was waiting on a plugin
//to load, which as since loaded.
if (dep.prefix && dep.name.indexOf('__$p') === 0 && defined[dep.prefix]) {
dep = makeModuleMap(dep.originalName, dep.parentMap);
}
var pluginName = dep.prefix,
fullName = dep.fullName;
//Do not bother if the dependency has already been specified.
if (specified[fullName] || loaded[fullName]) {
return;
} else {
specified[fullName] = true;
}
if (pluginName) {
//If plugin not loaded, wait for it.
//set up callback list. if no list, then register
//managerCallback for that plugin.
if (defined[pluginName]) {
callPlugin(pluginName, dep);
} else {
if (!pluginsQueue[pluginName]) {
pluginsQueue[pluginName] = [];
(managerCallbacks[pluginName] ||
(managerCallbacks[pluginName] = [])).push({
onDep: function (name, value) {
if (name === pluginName) {
var i, oldModuleMap, ary = pluginsQueue[pluginName];
//Now update all queued plugin actions.
for (i = 0; i < ary.length; i++) {
oldModuleMap = ary[i];
//Update the moduleMap since the
//module name may be normalized
//differently now.
callPlugin(pluginName,
makeModuleMap(oldModuleMap.originalName, oldModuleMap.parentMap));
}
delete pluginsQueue[pluginName];
}
}
});
}
pluginsQueue[pluginName].push(dep);
}
} else {
req.load(context, fullName, dep.url);
}
}
/**
* Resumes tracing of dependencies and then checks if everything is loaded.
*/
resume = function () {
var args, i, p;
resumeDepth += 1;
if (context.scriptCount <= 0) {
//Synchronous envs will push the number below zero with the
//decrement above, be sure to set it back to zero for good measure.
//require() calls that also do not end up loading scripts could
//push the number negative too.
context.scriptCount = 0;
}
//Make sure any remaining defQueue items get properly processed.
while (defQueue.length) {
args = defQueue.shift();
if (args[0] === null) {
return req.onError(new Error('Mismatched anonymous require.def modules'));
} else {
callDefMain(args);
}
}
//Skip the resume of paused dependencies
//if current context is in priority wait.
if (!config.priorityWait || isPriorityDone()) {
while (context.paused.length) {
p = context.paused;
context.pausedCount += p.length;
//Reset paused list
context.paused = [];
for (i = 0; (args = p[i]); i++) {
loadPaused(args);
}
//Move the start time for timeout forward.
context.startTime = (new Date()).getTime();
context.pausedCount -= p.length;
}
}
//Only check if loaded when resume depth is 1. It is likely that
//it is only greater than 1 in sync environments where a factory
//function also then calls the callback-style require. In those
//cases, the checkLoaded should not occur until the resume
//depth is back at the top level.
if (resumeDepth === 1) {
checkLoaded();
}
resumeDepth -= 1;
return undefined;
};
//Define the context object. Many of these fields are on here