forked from requirejs/requirejs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
require.js
1155 lines (1042 loc) · 43.1 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
/**
* @license RequireJS Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
* Available via the MIT, GPL or new BSD license.
* see: http://github.com/jrburke/requirejs for details
*/
//laxbreak is true to allow build pragmas to change some statements.
/*jslint plusplus: false, laxbreak: true */
/*global window: false, document: false, navigator: false,
setTimeout: false, traceDeps: true, clearInterval: false, self: false,
setInterval: false */
//>>excludeStart("dojoConvert", pragmas.dojoConvert);
"use strict";
//>>excludeEnd("dojoConvert");
var require;
(function () {
//Change this version number for each release.
var version = "0.8.0",
empty = {}, s,
i, defContextName = "_", contextLoads = [],
scripts, script, rePkg, src, m, cfg,
readyRegExp = /^(complete|loaded)$/,
isBrowser = !!(typeof window !== "undefined" && navigator && document),
ostring = Object.prototype.toString, scrollIntervalId;
function isFunction(it) {
return ostring.call(it) === "[object Function]";
}
//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;
}
}
//>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext);
function makeContextFunc(name, contextName, force) {
return function () {
//A version of a require function that uses the current context.
//If last arg is a string, then it is a context.
//If last arg is not a string, then add context to it.
var args = [].concat(Array.prototype.slice.call(arguments, 0));
if (force || typeof arguments[arguments.length - 1] !== "string") {
args.push(contextName);
}
return (name ? require[name] : require).apply(null, args);
};
}
//>>excludeEnd("requireExcludeContext");
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
/**
* Calls a method on a plugin. The obj object should have two property,
* name: the name of the method to call on the plugin
* args: the arguments to pass to the plugin method.
*/
function callPlugin(prefix, context, obj) {
//Call the plugin, or load it.
var plugin = s.plugins.defined[prefix], waiting;
if (plugin) {
plugin[obj.name].apply(null, obj.args);
} else {
//Load the module and add the call to waitin queue.
context.defined.require(["require/" + prefix]);
waiting = s.plugins.waiting[prefix] || (s.plugins.waiting[prefix] = []);
waiting.push(obj);
}
}
//>>excludeEnd("requireExcludePlugin");
/**
* Main entry point.
*
* If the only argument to require is a string, then the module that
* is represented by that string is fetched for the appropriate context.
*
* If the first argument is an array, then it will be treated as an array
* of dependency string names to fetch. An optional function callback can
* be specified to execute when all of those dependencies are available.
*/
require = function (deps, callback, contextName) {
if (typeof deps === "string" && !isFunction(callback)) {
//Just return the module wanted. In this scenario, the
//second arg (if passed) is just the contextName.
return require.get(deps, callback);
}
//Do more work, either
return require.def.apply(require, arguments);
};
/**
* The function that handles definitions of modules. Differs from
* require() in that a string for the module should be the first argument,
* and the function to execute after dependencies are loaded should
* return a value to define the module corresponding to the first argument's
* name.
*/
require.def = function (name, deps, callback, contextName) {
var config = null, context, newContext, contextRequire, loaded,
canSetContext, prop, newLength,
mods, pluginPrefix, paths, index;
//Normalize the arguments.
if (typeof name === "string") {
//Defining a module. First, pull off any plugin prefix.
index = name.indexOf("!");
if (index !== -1) {
pluginPrefix = name.substring(0, index);
name = name.substring(index + 1, name.length);
}
//Check if there are no dependencies, and adjust args.
if (!require.isArray(deps)) {
contextName = callback;
callback = deps;
deps = [];
}
contextName = contextName || s.ctxName;
//If module already defined for context, or already waiting to be
//evaluated, leave.
context = s.contexts[contextName];
if (context && (context.defined[name] || context.waiting[name])) {
return require;
}
} else if (require.isArray(name)) {
//Just some code that has dependencies. Adjust args accordingly.
contextName = callback;
callback = deps;
deps = name;
name = null;
} else if (require.isFunction(name)) {
//Just a function that does not define a module and
//does not have dependencies. Useful if just want to wait
//for whatever modules are in flight and execute some code after
//those modules load.
callback = name;
contextName = deps;
name = null;
deps = [];
} else {
//name is a config object.
config = name;
name = null;
//Adjust args if no dependencies.
if (require.isFunction(deps)) {
contextName = callback;
callback = deps;
deps = [];
}
contextName = contextName || config.context;
}
contextName = contextName || s.ctxName;
//>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext);
if (contextName !== s.ctxName) {
//If nothing is waiting on being loaded in the current context,
//then switch s.ctxName to current contextName.
loaded = (s.contexts[s.ctxName] && s.contexts[s.ctxName].loaded);
canSetContext = true;
if (loaded) {
for (prop in loaded) {
if (!(prop in empty)) {
if (!loaded[prop]) {
canSetContext = false;
break;
}
}
}
}
if (canSetContext) {
s.ctxName = contextName;
}
}
//>>excludeEnd("requireExcludeContext");
//Grab the context, or create a new one for the given context name.
context = s.contexts[contextName];
if (!context) {
newContext = {
contextName: contextName,
config: {
waitSeconds: 7,
baseUrl: s.baseUrl || "./",
paths: {}
},
waiting: [],
specified: {
"require": true,
"exports": true,
"module": true
},
loaded: {
"require": true
},
defined: {},
modifiers: {}
};
//Define require for this context.
//>>includeStart("requireExcludeContext", pragmas.requireExcludeContext);
//A placeholder for build pragmas.
newContext.defined.require = require;
//>>includeEnd("requireExcludeContext");
//>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext);
newContext.defined.require = contextRequire = makeContextFunc(null, contextName);
require.mixin(contextRequire, {
//>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
modify: makeContextFunc("modify", contextName),
def: makeContextFunc("def", contextName),
//>>excludeEnd("requireExcludeModify");
get: makeContextFunc("get", contextName, true),
nameToUrl: makeContextFunc("nameToUrl", contextName, true),
ready: require.ready,
context: newContext,
config: newContext.config,
isBrowser: s.isBrowser
});
//>>excludeEnd("requireExcludeContext");
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
if (s.plugins.newContext) {
s.plugins.newContext(newContext);
}
//>>excludeEnd("requireExcludePlugin");
context = s.contexts[contextName] = newContext;
}
//If have a config object, update the context's config object with
//the config values.
if (config) {
//Make sure the baseUrl ends in a slash.
if (config.baseUrl) {
if (config.baseUrl.charAt(config.baseUrl.length - 1) !== "/") {
config.baseUrl += "/";
}
}
//Save off the paths since they require special processing,
//they are additive.
paths = context.config.paths;
//Mix in the config values, favoring the new values over
//existing ones in context.config.
require.mixin(context.config, config, true);
//Adjust paths if necessary.
if (config.paths) {
for (prop in config.paths) {
if (!(prop in empty)) {
paths[prop] = config.paths[prop];
}
}
context.config.paths = paths;
}
//If a deps array or a config callback is specified, then call
//require with those args. This is useful when require is defined as a
//config object before require.js is loaded.
if (config.deps || config.callback) {
require(config.deps || [], config.callback);
}
//>>excludeStart("requireExcludePageLoad", pragmas.requireExcludePageLoad);
//Set up ready callback, if asked. Useful when require is defined as a
//config object before require.js is loaded.
if (config.ready) {
require.ready(config.ready);
}
//>>excludeEnd("requireExcludePageLoad");
//If it is just a config block, nothing else,
//then return.
if (!deps) {
return require;
}
}
//Store the module for later evaluation
newLength = context.waiting.push({
name: name,
deps: deps,
callback: callback
});
if (name) {
//Store index of insertion for quick lookup
context.waiting[name] = newLength - 1;
//Mark the module as specified: not loaded yet, but in the process,
//so no need to fetch it again. Important to do it here for the
//pause/resume case where there are multiple modules in a file.
context.specified[name] = true;
//>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
//Load any modifiers for the module.
mods = context.modifiers[name];
if (mods) {
require(mods, contextName);
}
//>>excludeEnd("requireExcludeModify");
}
//If the callback is not an actual function, it means it already
//has the definition of the module as a literal value.
if (name && callback && !require.isFunction(callback)) {
context.defined[name] = callback;
}
//If a pluginPrefix is available, call the plugin, or load it.
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
if (pluginPrefix) {
callPlugin(pluginPrefix, context, {
name: "require",
args: [name, deps, callback, context]
});
}
//>>excludeEnd("requireExcludePlugin");
//See if all is loaded. If paused, then do not check the dependencies
//of the module yet.
if (s.paused) {
s.paused.push([pluginPrefix, name, deps, context]);
} else {
require.checkDeps(pluginPrefix, name, deps, context);
require.checkLoaded(contextName);
}
return require;
};
/**
* Simple function to mix in properties from source into target,
* but only if target does not already have a property of the same name.
*/
require.mixin = function (target, source, override) {
for (var prop in source) {
if (!(prop in empty) && (!(prop in target) || override)) {
target[prop] = source[prop];
}
}
return require;
};
require.version = version;
//Set up page state.
s = require.s = {
ctxName: defContextName,
contexts: {},
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
plugins: {
defined: {},
callbacks: {},
waiting: {}
},
//>>excludeEnd("requireExcludePlugin");
isBrowser: isBrowser,
isPageLoaded: !isBrowser,
readyCalls: [],
doc: isBrowser ? document : null
};
require.isBrowser = s.isBrowser;
s.head = isBrowser ? document.getElementsByTagName("head")[0] : null;
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
/**
* Sets up a plugin callback name. Want to make it easy to test if a plugin
* needs to be called for a certain lifecycle event by testing for
* if (s.plugins.onLifeCyleEvent) so only define the lifecycle event
* if there is a real plugin that registers for it.
*/
function makePluginCallback(name, returnOnTrue) {
var cbs = s.plugins.callbacks[name] = [];
s.plugins[name] = function () {
for (var i = 0, cb; (cb = cbs[i]); i++) {
if (cb.apply(null, arguments) === true && returnOnTrue) {
return true;
}
}
return false;
};
}
/**
* Registers a new plugin for require.
*/
require.plugin = function (obj) {
var i, prop, call, prefix = obj.prefix, cbs = s.plugins.callbacks,
waiting = s.plugins.waiting[prefix], generics,
defined = s.plugins.defined, contexts = s.contexts, context;
//Do not allow redefinition of a plugin, there may be internal
//state in the plugin that could be lost.
if (defined[prefix]) {
return require;
}
//Save the plugin.
defined[prefix] = obj;
//Set up plugin callbacks for methods that need to be generic to
//require, for lifecycle cases where it does not care about a particular
//plugin, but just that some plugin work needs to be done.
generics = ["newContext", "isWaiting", "orderDeps"];
for (i = 0; (prop = generics[i]); i++) {
if (!s.plugins[prop]) {
makePluginCallback(prop, prop === "isWaiting");
}
cbs[prop].push(obj[prop]);
}
//Call newContext for any contexts that were already created.
if (obj.newContext) {
for (prop in contexts) {
if (!(prop in empty)) {
context = contexts[prop];
obj.newContext(context);
}
}
}
//If there are waiting requests for a plugin, execute them now.
if (waiting) {
for (i = 0; (call = waiting[i]); i++) {
if (obj[call.name]) {
obj[call.name].apply(null, call.args);
}
}
delete s.plugins.waiting[prefix];
}
return require;
};
//>>excludeEnd("requireExcludePlugin");
/**
* Pauses the tracing of dependencies. Useful in a build scenario when
* multiple modules are bundled into one file, and they all need to be
* require before figuring out what is left still to load.
*/
require.pause = function () {
if (!s.paused) {
s.paused = [];
}
};
/**
* Resumes the tracing of dependencies. Useful in a build scenario when
* multiple modules are bundled into one file. This method is related
* to require.pause() and should only be called if require.pause() was called first.
*/
require.resume = function () {
var i, args, paused;
if (s.paused) {
paused = s.paused;
delete s.paused;
for (i = 0; (args = paused[i]); i++) {
require.checkDeps.apply(require, args);
}
}
require.checkLoaded(s.ctxName);
};
/**
* Trace down the dependencies to see if they are loaded. If not, trigger
* the load.
* @param {String} pluginPrefix the plugin prefix, if any associated with the name.
*
* @param {String} name: the name of the module that has the dependencies.
*
* @param {Array} deps array of dependencies.
*
* @param {Object} context: the loading context.
*
* @private
*/
require.checkDeps = function (pluginPrefix, name, deps, context) {
//Figure out if all the modules are loaded. If the module is not
//being loaded or already loaded, add it to the "to load" list,
//and request it to be loaded.
var i, dep, index, depPrefix;
if (pluginPrefix) {
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
callPlugin(pluginPrefix, context, {
name: "checkDeps",
args: [name, deps, context]
});
//>>excludeEnd("requireExcludePlugin");
} else {
for (i = 0; (dep = deps[i]); i++) {
//If it is a string, then a plain dependency
if (typeof dep === "string") {
if (!context.specified[dep]) {
context.specified[dep] = true;
//If a plugin, call its load method.
index = dep.indexOf("!");
if (index !== -1) {
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
depPrefix = dep.substring(0, index);
dep = dep.substring(index + 1, dep.length);
callPlugin(depPrefix, context, {
name: "load",
args: [dep, context.contextName]
});
//>>excludeEnd("requireExcludePlugin");
} else {
require.load(dep, context.contextName);
}
}
} else {
throw new Error("Unsupported non-string dependency: " + dep);
}
}
}
};
//>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
/**
* Register a module that modifies another module. The modifier will
* only be called once the target module has been loaded.
*
* First syntax:
*
* require.modify({
* "some/target1": "my/modifier1",
* "some/target2": "my/modifier2",
* });
*
* With this syntax, the my/modifier1 will only be loaded when
* "some/target1" is loaded.
*
* Second syntax, defining a modifier.
*
* require.modify("some/target1", "my/modifier",
* ["some/target1", "some/other"],
* function (target, other) {
* //Modify properties of target here.
* Only properties of target can be modified, but
* target cannot be replaced.
* }
* );
*/
require.modify = function (target, name, deps, callback, contextName) {
var prop, modifier, list,
cName = (typeof target === "string" ? contextName : name) || s.ctxName,
context = s.contexts[cName],
mods = context.modifiers;
if (typeof target === "string") {
//A modifier module.
//First store that it is a modifier.
list = mods[target] || (mods[target] = []);
if (!list[name]) {
list.push(name);
list[name] = true;
}
//Trigger the normal module definition logic.
require.def(name, deps, callback, contextName);
} else {
//A list of modifiers. Save them for future reference.
for (prop in target) {
if (!(prop in empty)) {
//Store the modifier for future use.
modifier = target[prop];
list = context.modifiers[prop] || (context.modifiers[prop] = []);
if (!list[modifier]) {
list.push(modifier);
list[modifier] = true;
if (context.specified[prop]) {
//Load the modifier right away.
require([modifier], cName);
}
}
}
}
}
};
//>>excludeEnd("requireExcludeModify");
require.isArray = function (it) {
return ostring.call(it) === "[object Array]";
};
require.isFunction = isFunction;
/**
* Gets one module's exported value. This method is used by require().
* It is broken out as a separate function to allow a host environment
* shim to overwrite this function with something appropriate for that
* environment.
*
* @param {String} moduleName the name of the module.
* @param {String} [contextName] the name of the context to use. Uses
* default context if no contextName is provided.
*
* @returns {Object} the exported module value.
*/
require.get = function (moduleName, contextName) {
if (moduleName === "exports" || moduleName === "module") {
throw new Error("require of " + moduleName + " is not allowed.");
}
contextName = contextName || s.ctxName;
var ret = s.contexts[contextName].defined[moduleName];
if (ret === undefined) {
throw new Error("require: module name '" +
moduleName +
"' has not been loaded yet for context: " +
contextName);
}
return ret;
};
/**
* Makes the request to load a module. May be an async load depending on
* the environment and the circumstance of the load call. Override this
* method in a host environment shim to do something specific for that
* environment.
*
* @param {String} moduleName the name of the module.
* @param {String} contextName the name of the context to use.
*/
require.load = function (moduleName, contextName) {
var context = s.contexts[contextName], url;
s.isDone = false;
context.loaded[moduleName] = false;
//>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext);
if (contextName !== s.ctxName) {
//Not in the right context now, hold on to it until
//the current context finishes all its loading.
contextLoads.push(arguments);
} else {
//>>excludeEnd("requireExcludeContext");
//First derive the path name for the module.
url = require.nameToUrl(moduleName, null, contextName);
require.attach(url, contextName, moduleName);
context.startTime = (new Date()).getTime();
//>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext);
}
//>>excludeEnd("requireExcludeContext");
};
require.jsExtRegExp = /\.js$/;
/**
* Converts a module name to a file path.
*/
require.nameToUrl = function (moduleName, ext, contextName) {
var paths, syms, i, parentModule, url,
config = s.contexts[contextName].config;
//If a colon is in the URL, it indicates a protocol is used and it is just
//an URL to a file, or if it starts with a slash or ends with .js, it is just a plain file.
//The slash is important for protocol-less URLs as well as full paths.
if (moduleName.indexOf(":") !== -1 || moduleName.charAt(0) === '/' || require.jsExtRegExp.test(moduleName)) {
//Just a plain path, not module name lookup, so just return it.
return moduleName;
} else {
//A module that needs to be converted to a path.
paths = config.paths;
syms = moduleName.split("/");
//For each module name segment, see if there is a path
//registered for it. Start with most specific name
//and work up from it.
for (i = syms.length; i > 0; i--) {
parentModule = syms.slice(0, i).join("/");
if (paths[parentModule]) {
syms.splice(0, i, paths[parentModule]);
break;
}
}
//Join the path parts together, then figure out if baseUrl is needed.
url = syms.join("/") + (ext || ".js");
return ((url.charAt(0) === '/' || url.match(/^\w+:/)) ? "" : config.baseUrl) + url;
}
};
/**
* Checks if all modules for a context are loaded, and if so, evaluates the
* new ones in right dependency order.
*
* @private
*/
require.checkLoaded = function (contextName) {
var context = s.contexts[contextName || s.ctxName],
waitInterval = context.config.waitSeconds * 1000,
//It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
loaded = context.loaded, defined = context.defined,
modifiers = context.modifiers, waiting = context.waiting, noLoads = "",
hasLoadedProp = false, stillLoading = false, prop,
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
pIsWaiting = s.plugins.isWaiting, pOrderDeps = s.plugins.orderDeps,
//>>excludeEnd("requireExcludePlugin");
i, module, allDone, loads, loadArgs,
traced = {};
//If already doing a checkLoaded call,
//then do not bother checking loaded state.
if (context.isCheckLoaded) {
return;
}
//Signal that checkLoaded is being require, so other calls that could be triggered
//by calling a waiting callback that then calls require and then this function
//should not proceed. At the end of this function, if there are still things
//waiting, then checkLoaded will be called again.
context.isCheckLoaded = true;
//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 && !waiting.length
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
&& (!pIsWaiting || !pIsWaiting(context))
//>>excludeEnd("requireExcludePlugin");
) {
//If the loaded object had no items, then the rest of
//the work below does not need to be done.
context.isCheckLoaded = false;
return;
}
if (expired && noLoads) {
//If wait time expired, throw error of unloaded modules.
throw new Error("require.js load timeout for modules: " + noLoads);
}
if (stillLoading) {
//Something is still waiting to load. Wait for it.
context.isCheckLoaded = false;
if (require.isBrowser) {
setTimeout(function () {
require.checkLoaded(contextName);
}, 50);
}
return;
}
//Order the dependencies. Also clean up state because the evaluation
//of modules might create new loading tasks, so need to reset.
//Be sure to call plugins too.
context.waiting = [];
context.loaded = {};
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
//Call plugins to order their dependencies, do their
//module definitions.
if (pOrderDeps) {
pOrderDeps(context);
}
//>>excludeEnd("requireExcludePlugin");
//>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
//Before defining the modules, give priority treatment to any modifiers
//for modules that are already defined.
for (prop in modifiers) {
if (!(prop in empty)) {
if (defined[prop]) {
require.execModifiers(prop, traced, waiting, context);
}
}
}
//>>excludeEnd("requireExcludeModify");
//Define the modules, doing a depth first search.
for (i = 0; (module = waiting[i]); i++) {
require.exec(module, traced, waiting, context);
}
//Indicate checkLoaded is now done.
context.isCheckLoaded = false;
if (context.waiting.length
//>>excludeStart("requireExcludePlugin", pragmas.requireExcludePlugin);
|| (pIsWaiting && pIsWaiting(context))
//>>excludeEnd("requireExcludePlugin");
) {
//More things in this context are waiting to load. They were probably
//added while doing the work above in checkLoaded, calling module
//callbacks that triggered other require calls.
require.checkLoaded(contextName);
} else if (contextLoads.length) {
//>>excludeStart("requireExcludeContext", pragmas.requireExcludeContext);
//Check for other contexts that need to load things.
//First, make sure current context has no more things to
//load. After defining the modules above, new require calls
//could have been made.
loaded = context.loaded;
allDone = true;
for (prop in loaded) {
if (!(prop in empty)) {
if (!loaded[prop]) {
allDone = false;
break;
}
}
}
if (allDone) {
s.ctxName = contextLoads[0][1];
loads = contextLoads;
//Reset contextLoads in case some of the waiting loads
//are for yet another context.
contextLoads = [];
for (i = 0; (loadArgs = loads[i]); i++) {
require.load.apply(require, loadArgs);
}
}
//>>excludeEnd("requireExcludeContext");
} else {
//Make sure we reset to default context.
s.ctxName = defContextName;
s.isDone = true;
if (require.callReady) {
require.callReady();
}
}
};
/**
* Executes the modules in the correct order.
*
* @private
*/
require.exec = function (module, traced, waiting, context) {
//Some modules are just plain script files, abddo not have a formal
//module definition,
if (!module) {
return undefined;
}
var name = module.name, cb = module.callback, deps = module.deps, j, dep,
defined = context.defined, ret, args = [], prefix, depModule,
usingExports = false;
//If already traced or defined, do not bother a second time.
if (name) {
if (traced[name] || defined[name]) {
return defined[name];
}
//Mark this module as being traced, so that it is not retraced (as in a circular
//dependency)
traced[name] = true;
}
if (deps) {
for (j = 0; (dep = deps[j]); j++) {
//Adjust dependency for plugins.
prefix = dep.indexOf("!");
if (prefix !== -1) {
dep = dep.substring(prefix + 1, dep.length);
}
if (dep === "exports") {
//CommonJS module spec 1.1
depModule = defined[name] = {};
usingExports = true;
} else if (dep === "module") {
//CommonJS module spec 1.1
depModule = {
id: name,
uri: name ? require.nameToUrl(name, null, context.contextName) : undefined
};
} else {
//Get dependent module. It could not exist, for a circular
//dependency or if the loaded dependency does not actually call
//require. Favor not throwing an error here if undefined because
//we want to allow code that does not use require as a module
//definition framework to still work -- allow a web site to
//gradually update to contained modules. That is seen as more
//important than forcing a throw for the circular dependency case.
depModule = dep in defined ? defined[dep] : (traced[dep] ? undefined : require.exec(waiting[waiting[dep]], traced, waiting, context));
}
args.push(depModule);
}
}
//Call the callback to define the module, if necessary.
cb = module.callback;
if (cb && require.isFunction(cb)) {
ret = require.execCb(name, cb, args);
if (name) {
if (usingExports) {
ret = defined[name];
} else {
if (name in defined) {
throw new Error(name + " has already been defined");
} else {
defined[name] = ret;
}
}
}
}
//>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
//Execute modifiers, if they exist.
require.execModifiers(name, traced, waiting, context);
//>>excludeEnd("requireExcludeModify");
return ret;
};
/**
* Executes a module callack function. Broken out as a separate function
* solely to allow the build system to sequence the files in the built
* layer in the right sequence.
* @param {String} name the module name.
* @param {Function} cb the module callback/definition function.
* @param {Array} args The arguments (dependent modules) to pass to callback.
*
* @private
*/
require.execCb = function (name, cb, args) {
return cb.apply(null, args);
};
//>>excludeStart("requireExcludeModify", pragmas.requireExcludeModify);
/**
* Executes modifiers for the given module name.
* @param {String} target
* @param {Object} traced
* @param {Object} context
*
* @private
*/
require.execModifiers = function (target, traced, waiting, context) {
var modifiers = context.modifiers, mods = modifiers[target], mod, i;
if (mods) {
for (i = 0; i < mods.length; i++) {
mod = mods[i];
//Not all modifiers define a module, they might collect other modules.
//If it is just a collection it will not be in waiting.
if (mod in waiting) {
require.exec(waiting[waiting[mod]], traced, waiting, context);
}
}
delete modifiers[target];
}
};
//>>excludeEnd("requireExcludeModify");
/**
* callback for script loads, used to check status of loading.
*
* @param {Event} evt the event from the browser for the script
* that was loaded.
*
* @private
*/
require.onScriptLoad = function (evt) {
var node = evt.target || evt.srcElement, contextName, moduleName;
if (evt.type === "load" || readyRegExp.test(node.readyState)) {
//Pull out the name of the module and the context.
contextName = node.getAttribute("data-requirecontext");
moduleName = node.getAttribute("data-requiremodule");
//Mark the module loaded.
s.contexts[contextName].loaded[moduleName] = true;
require.checkLoaded(contextName);
//Clean up script binding.
if (node.removeEventListener) {
node.removeEventListener("load", require.onScriptLoad, false);