embient 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2052 +0,0 @@
1
- /** vim: et:ts=4:sw=4:sts=4
2
- * @license RequireJS 1.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
3
- * Available via the MIT or new BSD license.
4
- * see: http://github.com/jrburke/requirejs for details
5
- */
6
- /*jslint strict: false, plusplus: false, sub: true */
7
- /*global window, navigator, document, importScripts, jQuery, setTimeout, opera */
8
-
9
- var requirejs, require, define;
10
- (function () {
11
- //Change this version number for each release.
12
- var version = "1.0.5",
13
- commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
14
- cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g,
15
- currDirRegExp = /^\.\//,
16
- jsSuffixRegExp = /\.js$/,
17
- ostring = Object.prototype.toString,
18
- ap = Array.prototype,
19
- aps = ap.slice,
20
- apsp = ap.splice,
21
- isBrowser = !!(typeof window !== "undefined" && navigator && document),
22
- isWebWorker = !isBrowser && typeof importScripts !== "undefined",
23
- //PS3 indicates loaded and complete, but need to wait for complete
24
- //specifically. Sequence is "loading", "loaded", execution,
25
- // then "complete". The UA check is unfortunate, but not sure how
26
- //to feature test w/o causing perf issues.
27
- readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
28
- /^complete$/ : /^(complete|loaded)$/,
29
- defContextName = "_",
30
- //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
31
- isOpera = typeof opera !== "undefined" && opera.toString() === "[object Opera]",
32
- empty = {},
33
- contexts = {},
34
- globalDefQueue = [],
35
- interactiveScript = null,
36
- checkLoadedDepth = 0,
37
- useInteractive = false,
38
- reservedDependencies = {
39
- require: true,
40
- module: true,
41
- exports: true
42
- },
43
- req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script,
44
- src, subPath, mainScript, dataMain, globalI, ctx, jQueryCheck, checkLoadedTimeoutId;
45
-
46
- function isFunction(it) {
47
- return ostring.call(it) === "[object Function]";
48
- }
49
-
50
- function isArray(it) {
51
- return ostring.call(it) === "[object Array]";
52
- }
53
-
54
- /**
55
- * Simple function to mix in properties from source into target,
56
- * but only if target does not already have a property of the same name.
57
- * This is not robust in IE for transferring methods that match
58
- * Object.prototype names, but the uses of mixin here seem unlikely to
59
- * trigger a problem related to that.
60
- */
61
- function mixin(target, source, force) {
62
- for (var prop in source) {
63
- if (!(prop in empty) && (!(prop in target) || force)) {
64
- target[prop] = source[prop];
65
- }
66
- }
67
- return req;
68
- }
69
-
70
- /**
71
- * Constructs an error with a pointer to an URL with more information.
72
- * @param {String} id the error ID that maps to an ID on a web page.
73
- * @param {String} message human readable error.
74
- * @param {Error} [err] the original error, if there is one.
75
- *
76
- * @returns {Error}
77
- */
78
- function makeError(id, msg, err) {
79
- var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
80
- if (err) {
81
- e.originalError = err;
82
- }
83
- return e;
84
- }
85
-
86
- /**
87
- * Used to set up package paths from a packagePaths or packages config object.
88
- * @param {Object} pkgs the object to store the new package config
89
- * @param {Array} currentPackages an array of packages to configure
90
- * @param {String} [dir] a prefix dir to use.
91
- */
92
- function configurePackageDir(pkgs, currentPackages, dir) {
93
- var i, location, pkgObj;
94
-
95
- for (i = 0; (pkgObj = currentPackages[i]); i++) {
96
- pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
97
- location = pkgObj.location;
98
-
99
- //Add dir to the path, but avoid paths that start with a slash
100
- //or have a colon (indicates a protocol)
101
- if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
102
- location = dir + "/" + (location || pkgObj.name);
103
- }
104
-
105
- //Create a brand new object on pkgs, since currentPackages can
106
- //be passed in again, and config.pkgs is the internal transformed
107
- //state for all package configs.
108
- pkgs[pkgObj.name] = {
109
- name: pkgObj.name,
110
- location: location || pkgObj.name,
111
- //Remove leading dot in main, so main paths are normalized,
112
- //and remove any trailing .js, since different package
113
- //envs have different conventions: some use a module name,
114
- //some use a file name.
115
- main: (pkgObj.main || "main")
116
- .replace(currDirRegExp, '')
117
- .replace(jsSuffixRegExp, '')
118
- };
119
- }
120
- }
121
-
122
- /**
123
- * jQuery 1.4.3-1.5.x use a readyWait/ready() pairing to hold DOM
124
- * ready callbacks, but jQuery 1.6 supports a holdReady() API instead.
125
- * At some point remove the readyWait/ready() support and just stick
126
- * with using holdReady.
127
- */
128
- function jQueryHoldReady($, shouldHold) {
129
- if ($.holdReady) {
130
- $.holdReady(shouldHold);
131
- } else if (shouldHold) {
132
- $.readyWait += 1;
133
- } else {
134
- $.ready(true);
135
- }
136
- }
137
-
138
- if (typeof define !== "undefined") {
139
- //If a define is already in play via another AMD loader,
140
- //do not overwrite.
141
- return;
142
- }
143
-
144
- if (typeof requirejs !== "undefined") {
145
- if (isFunction(requirejs)) {
146
- //Do not overwrite and existing requirejs instance.
147
- return;
148
- } else {
149
- cfg = requirejs;
150
- requirejs = undefined;
151
- }
152
- }
153
-
154
- //Allow for a require config object
155
- if (typeof require !== "undefined" && !isFunction(require)) {
156
- //assume it is a config object.
157
- cfg = require;
158
- require = undefined;
159
- }
160
-
161
- /**
162
- * Creates a new context for use in require and define calls.
163
- * Handle most of the heavy lifting. Do not want to use an object
164
- * with prototype here to avoid using "this" in require, in case it
165
- * needs to be used in more super secure envs that do not want this.
166
- * Also there should not be that many contexts in the page. Usually just
167
- * one for the default context, but could be extra for multiversion cases
168
- * or if a package needs a special context for a dependency that conflicts
169
- * with the standard context.
170
- */
171
- function newContext(contextName) {
172
- var context, resume,
173
- config = {
174
- waitSeconds: 7,
175
- baseUrl: "./",
176
- paths: {},
177
- pkgs: {},
178
- catchError: {}
179
- },
180
- defQueue = [],
181
- specified = {
182
- "require": true,
183
- "exports": true,
184
- "module": true
185
- },
186
- urlMap = {},
187
- defined = {},
188
- loaded = {},
189
- waiting = {},
190
- waitAry = [],
191
- urlFetched = {},
192
- managerCounter = 0,
193
- managerCallbacks = {},
194
- plugins = {},
195
- //Used to indicate which modules in a build scenario
196
- //need to be full executed.
197
- needFullExec = {},
198
- fullExec = {},
199
- resumeDepth = 0;
200
-
201
- /**
202
- * Trims the . and .. from an array of path segments.
203
- * It will keep a leading path segment if a .. will become
204
- * the first path segment, to help with module name lookups,
205
- * which act like paths, but can be remapped. But the end result,
206
- * all paths that use this function should look normalized.
207
- * NOTE: this method MODIFIES the input array.
208
- * @param {Array} ary the array of path segments.
209
- */
210
- function trimDots(ary) {
211
- var i, part;
212
- for (i = 0; (part = ary[i]); i++) {
213
- if (part === ".") {
214
- ary.splice(i, 1);
215
- i -= 1;
216
- } else if (part === "..") {
217
- if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
218
- //End of the line. Keep at least one non-dot
219
- //path segment at the front so it can be mapped
220
- //correctly to disk. Otherwise, there is likely
221
- //no path mapping for a path starting with '..'.
222
- //This can still fail, but catches the most reasonable
223
- //uses of ..
224
- break;
225
- } else if (i > 0) {
226
- ary.splice(i - 1, 2);
227
- i -= 2;
228
- }
229
- }
230
- }
231
- }
232
-
233
- /**
234
- * Given a relative module name, like ./something, normalize it to
235
- * a real name that can be mapped to a path.
236
- * @param {String} name the relative name
237
- * @param {String} baseName a real name that the name arg is relative
238
- * to.
239
- * @returns {String} normalized name
240
- */
241
- function normalize(name, baseName) {
242
- var pkgName, pkgConfig;
243
-
244
- //Adjust any relative paths.
245
- if (name && name.charAt(0) === ".") {
246
- //If have a base name, try to normalize against it,
247
- //otherwise, assume it is a top-level require that will
248
- //be relative to baseUrl in the end.
249
- if (baseName) {
250
- if (config.pkgs[baseName]) {
251
- //If the baseName is a package name, then just treat it as one
252
- //name to concat the name with.
253
- baseName = [baseName];
254
- } else {
255
- //Convert baseName to array, and lop off the last part,
256
- //so that . matches that "directory" and not name of the baseName's
257
- //module. For instance, baseName of "one/two/three", maps to
258
- //"one/two/three.js", but we want the directory, "one/two" for
259
- //this normalization.
260
- baseName = baseName.split("/");
261
- baseName = baseName.slice(0, baseName.length - 1);
262
- }
263
-
264
- name = baseName.concat(name.split("/"));
265
- trimDots(name);
266
-
267
- //Some use of packages may use a . path to reference the
268
- //"main" module name, so normalize for that.
269
- pkgConfig = config.pkgs[(pkgName = name[0])];
270
- name = name.join("/");
271
- if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
272
- name = pkgName;
273
- }
274
- } else if (name.indexOf("./") === 0) {
275
- // No baseName, so this is ID is resolved relative
276
- // to baseUrl, pull off the leading dot.
277
- name = name.substring(2);
278
- }
279
- }
280
- return name;
281
- }
282
-
283
- /**
284
- * Creates a module mapping that includes plugin prefix, module
285
- * name, and path. If parentModuleMap is provided it will
286
- * also normalize the name via require.normalize()
287
- *
288
- * @param {String} name the module name
289
- * @param {String} [parentModuleMap] parent module map
290
- * for the module name, used to resolve relative names.
291
- *
292
- * @returns {Object}
293
- */
294
- function makeModuleMap(name, parentModuleMap) {
295
- var index = name ? name.indexOf("!") : -1,
296
- prefix = null,
297
- parentName = parentModuleMap ? parentModuleMap.name : null,
298
- originalName = name,
299
- normalizedName, url, pluginModule;
300
-
301
- if (index !== -1) {
302
- prefix = name.substring(0, index);
303
- name = name.substring(index + 1, name.length);
304
- }
305
-
306
- if (prefix) {
307
- prefix = normalize(prefix, parentName);
308
- }
309
-
310
- //Account for relative paths if there is a base name.
311
- if (name) {
312
- if (prefix) {
313
- pluginModule = defined[prefix];
314
- if (pluginModule && pluginModule.normalize) {
315
- //Plugin is loaded, use its normalize method.
316
- normalizedName = pluginModule.normalize(name, function (name) {
317
- return normalize(name, parentName);
318
- });
319
- } else {
320
- normalizedName = normalize(name, parentName);
321
- }
322
- } else {
323
- //A regular module.
324
- normalizedName = normalize(name, parentName);
325
-
326
- url = urlMap[normalizedName];
327
- if (!url) {
328
- //Calculate url for the module, if it has a name.
329
- //Use name here since nameToUrl also calls normalize,
330
- //and for relative names that are outside the baseUrl
331
- //this causes havoc. Was thinking of just removing
332
- //parentModuleMap to avoid extra normalization, but
333
- //normalize() still does a dot removal because of
334
- //issue #142, so just pass in name here and redo
335
- //the normalization. Paths outside baseUrl are just
336
- //messy to support.
337
- url = context.nameToUrl(name, null, parentModuleMap);
338
-
339
- //Store the URL mapping for later.
340
- urlMap[normalizedName] = url;
341
- }
342
- }
343
- }
344
-
345
- return {
346
- prefix: prefix,
347
- name: normalizedName,
348
- parentMap: parentModuleMap,
349
- url: url,
350
- originalName: originalName,
351
- fullName: prefix ? prefix + "!" + (normalizedName || '') : normalizedName
352
- };
353
- }
354
-
355
- /**
356
- * Determine if priority loading is done. If so clear the priorityWait
357
- */
358
- function isPriorityDone() {
359
- var priorityDone = true,
360
- priorityWait = config.priorityWait,
361
- priorityName, i;
362
- if (priorityWait) {
363
- for (i = 0; (priorityName = priorityWait[i]); i++) {
364
- if (!loaded[priorityName]) {
365
- priorityDone = false;
366
- break;
367
- }
368
- }
369
- if (priorityDone) {
370
- delete config.priorityWait;
371
- }
372
- }
373
- return priorityDone;
374
- }
375
-
376
- function makeContextModuleFunc(func, relModuleMap, enableBuildCallback) {
377
- return function () {
378
- //A version of a require function that passes a moduleName
379
- //value for items that may need to
380
- //look up paths relative to the moduleName
381
- var args = aps.call(arguments, 0), lastArg;
382
- if (enableBuildCallback &&
383
- isFunction((lastArg = args[args.length - 1]))) {
384
- lastArg.__requireJsBuild = true;
385
- }
386
- args.push(relModuleMap);
387
- return func.apply(null, args);
388
- };
389
- }
390
-
391
- /**
392
- * Helper function that creates a require function object to give to
393
- * modules that ask for it as a dependency. It needs to be specific
394
- * per module because of the implication of path mappings that may
395
- * need to be relative to the module name.
396
- */
397
- function makeRequire(relModuleMap, enableBuildCallback, altRequire) {
398
- var modRequire = makeContextModuleFunc(altRequire || context.require, relModuleMap, enableBuildCallback);
399
-
400
- mixin(modRequire, {
401
- nameToUrl: makeContextModuleFunc(context.nameToUrl, relModuleMap),
402
- toUrl: makeContextModuleFunc(context.toUrl, relModuleMap),
403
- defined: makeContextModuleFunc(context.requireDefined, relModuleMap),
404
- specified: makeContextModuleFunc(context.requireSpecified, relModuleMap),
405
- isBrowser: req.isBrowser
406
- });
407
- return modRequire;
408
- }
409
-
410
- /*
411
- * Queues a dependency for checking after the loader is out of a
412
- * "paused" state, for example while a script file is being loaded
413
- * in the browser, where it may have many modules defined in it.
414
- */
415
- function queueDependency(manager) {
416
- context.paused.push(manager);
417
- }
418
-
419
- function execManager(manager) {
420
- var i, ret, err, errFile, errModuleTree,
421
- cb = manager.callback,
422
- map = manager.map,
423
- fullName = map.fullName,
424
- args = manager.deps,
425
- listeners = manager.listeners,
426
- cjsModule;
427
-
428
- //Call the callback to define the module, if necessary.
429
- if (cb && isFunction(cb)) {
430
- if (config.catchError.define) {
431
- try {
432
- ret = req.execCb(fullName, manager.callback, args, defined[fullName]);
433
- } catch (e) {
434
- err = e;
435
- }
436
- } else {
437
- ret = req.execCb(fullName, manager.callback, args, defined[fullName]);
438
- }
439
-
440
- if (fullName) {
441
- //If setting exports via "module" is in play,
442
- //favor that over return value and exports. After that,
443
- //favor a non-undefined return value over exports use.
444
- cjsModule = manager.cjsModule;
445
- if (cjsModule &&
446
- cjsModule.exports !== undefined &&
447
- //Make sure it is not already the exports value
448
- cjsModule.exports !== defined[fullName]) {
449
- ret = defined[fullName] = manager.cjsModule.exports;
450
- } else if (ret === undefined && manager.usingExports) {
451
- //exports already set the defined value.
452
- ret = defined[fullName];
453
- } else {
454
- //Use the return value from the function.
455
- defined[fullName] = ret;
456
- //If this module needed full execution in a build
457
- //environment, mark that now.
458
- if (needFullExec[fullName]) {
459
- fullExec[fullName] = true;
460
- }
461
- }
462
- }
463
- } else if (fullName) {
464
- //May just be an object definition for the module. Only
465
- //worry about defining if have a module name.
466
- ret = defined[fullName] = cb;
467
-
468
- //If this module needed full execution in a build
469
- //environment, mark that now.
470
- if (needFullExec[fullName]) {
471
- fullExec[fullName] = true;
472
- }
473
- }
474
-
475
- //Clean up waiting. Do this before error calls, and before
476
- //calling back listeners, so that bookkeeping is correct
477
- //in the event of an error and error is reported in correct order,
478
- //since the listeners will likely have errors if the
479
- //onError function does not throw.
480
- if (waiting[manager.id]) {
481
- delete waiting[manager.id];
482
- manager.isDone = true;
483
- context.waitCount -= 1;
484
- if (context.waitCount === 0) {
485
- //Clear the wait array used for cycles.
486
- waitAry = [];
487
- }
488
- }
489
-
490
- //Do not need to track manager callback now that it is defined.
491
- delete managerCallbacks[fullName];
492
-
493
- //Allow instrumentation like the optimizer to know the order
494
- //of modules executed and their dependencies.
495
- if (req.onResourceLoad && !manager.placeholder) {
496
- req.onResourceLoad(context, map, manager.depArray);
497
- }
498
-
499
- if (err) {
500
- errFile = (fullName ? makeModuleMap(fullName).url : '') ||
501
- err.fileName || err.sourceURL;
502
- errModuleTree = err.moduleTree;
503
- err = makeError('defineerror', 'Error evaluating ' +
504
- 'module "' + fullName + '" at location "' +
505
- errFile + '":\n' +
506
- err + '\nfileName:' + errFile +
507
- '\nlineNumber: ' + (err.lineNumber || err.line), err);
508
- err.moduleName = fullName;
509
- err.moduleTree = errModuleTree;
510
- return req.onError(err);
511
- }
512
-
513
- //Let listeners know of this manager's value.
514
- for (i = 0; (cb = listeners[i]); i++) {
515
- cb(ret);
516
- }
517
-
518
- return undefined;
519
- }
520
-
521
- /**
522
- * Helper that creates a callack function that is called when a dependency
523
- * is ready, and sets the i-th dependency for the manager as the
524
- * value passed to the callback generated by this function.
525
- */
526
- function makeArgCallback(manager, i) {
527
- return function (value) {
528
- //Only do the work if it has not been done
529
- //already for a dependency. Cycle breaking
530
- //logic in forceExec could mean this function
531
- //is called more than once for a given dependency.
532
- if (!manager.depDone[i]) {
533
- manager.depDone[i] = true;
534
- manager.deps[i] = value;
535
- manager.depCount -= 1;
536
- if (!manager.depCount) {
537
- //All done, execute!
538
- execManager(manager);
539
- }
540
- }
541
- };
542
- }
543
-
544
- function callPlugin(pluginName, depManager) {
545
- var map = depManager.map,
546
- fullName = map.fullName,
547
- name = map.name,
548
- plugin = plugins[pluginName] ||
549
- (plugins[pluginName] = defined[pluginName]),
550
- load;
551
-
552
- //No need to continue if the manager is already
553
- //in the process of loading.
554
- if (depManager.loading) {
555
- return;
556
- }
557
- depManager.loading = true;
558
-
559
- load = function (ret) {
560
- depManager.callback = function () {
561
- return ret;
562
- };
563
- execManager(depManager);
564
-
565
- loaded[depManager.id] = true;
566
-
567
- //The loading of this plugin
568
- //might have placed other things
569
- //in the paused queue. In particular,
570
- //a loader plugin that depends on
571
- //a different plugin loaded resource.
572
- resume();
573
- };
574
-
575
- //Allow plugins to load other code without having to know the
576
- //context or how to "complete" the load.
577
- load.fromText = function (moduleName, text) {
578
- /*jslint evil: true */
579
- var hasInteractive = useInteractive;
580
-
581
- //Indicate a the module is in process of loading.
582
- loaded[moduleName] = false;
583
- context.scriptCount += 1;
584
-
585
- //Indicate this is not a "real" module, so do not track it
586
- //for builds, it does not map to a real file.
587
- context.fake[moduleName] = true;
588
-
589
- //Turn off interactive script matching for IE for any define
590
- //calls in the text, then turn it back on at the end.
591
- if (hasInteractive) {
592
- useInteractive = false;
593
- }
594
-
595
- req.exec(text);
596
-
597
- if (hasInteractive) {
598
- useInteractive = true;
599
- }
600
-
601
- //Support anonymous modules.
602
- context.completeLoad(moduleName);
603
- };
604
-
605
- //No need to continue if the plugin value has already been
606
- //defined by a build.
607
- if (fullName in defined) {
608
- load(defined[fullName]);
609
- } else {
610
- //Use parentName here since the plugin's name is not reliable,
611
- //could be some weird string with no path that actually wants to
612
- //reference the parentName's path.
613
- plugin.load(name, makeRequire(map.parentMap, true, function (deps, cb) {
614
- var moduleDeps = [],
615
- i, dep, depMap;
616
- //Convert deps to full names and hold on to them
617
- //for reference later, when figuring out if they
618
- //are blocked by a circular dependency.
619
- for (i = 0; (dep = deps[i]); i++) {
620
- depMap = makeModuleMap(dep, map.parentMap);
621
- deps[i] = depMap.fullName;
622
- if (!depMap.prefix) {
623
- moduleDeps.push(deps[i]);
624
- }
625
- }
626
- depManager.moduleDeps = (depManager.moduleDeps || []).concat(moduleDeps);
627
- return context.require(deps, cb);
628
- }), load, config);
629
- }
630
- }
631
-
632
- /**
633
- * Adds the manager to the waiting queue. Only fully
634
- * resolved items should be in the waiting queue.
635
- */
636
- function addWait(manager) {
637
- if (!waiting[manager.id]) {
638
- waiting[manager.id] = manager;
639
- waitAry.push(manager);
640
- context.waitCount += 1;
641
- }
642
- }
643
-
644
- /**
645
- * Function added to every manager object. Created out here
646
- * to avoid new function creation for each manager instance.
647
- */
648
- function managerAdd(cb) {
649
- this.listeners.push(cb);
650
- }
651
-
652
- function getManager(map, shouldQueue) {
653
- var fullName = map.fullName,
654
- prefix = map.prefix,
655
- plugin = prefix ? plugins[prefix] ||
656
- (plugins[prefix] = defined[prefix]) : null,
657
- manager, created, pluginManager, prefixMap;
658
-
659
- if (fullName) {
660
- manager = managerCallbacks[fullName];
661
- }
662
-
663
- if (!manager) {
664
- created = true;
665
- manager = {
666
- //ID is just the full name, but if it is a plugin resource
667
- //for a plugin that has not been loaded,
668
- //then add an ID counter to it.
669
- id: (prefix && !plugin ?
670
- (managerCounter++) + '__p@:' : '') +
671
- (fullName || '__r@' + (managerCounter++)),
672
- map: map,
673
- depCount: 0,
674
- depDone: [],
675
- depCallbacks: [],
676
- deps: [],
677
- listeners: [],
678
- add: managerAdd
679
- };
680
-
681
- specified[manager.id] = true;
682
-
683
- //Only track the manager/reuse it if this is a non-plugin
684
- //resource. Also only track plugin resources once
685
- //the plugin has been loaded, and so the fullName is the
686
- //true normalized value.
687
- if (fullName && (!prefix || plugins[prefix])) {
688
- managerCallbacks[fullName] = manager;
689
- }
690
- }
691
-
692
- //If there is a plugin needed, but it is not loaded,
693
- //first load the plugin, then continue on.
694
- if (prefix && !plugin) {
695
- prefixMap = makeModuleMap(prefix);
696
-
697
- //Clear out defined and urlFetched if the plugin was previously
698
- //loaded/defined, but not as full module (as in a build
699
- //situation). However, only do this work if the plugin is in
700
- //defined but does not have a module export value.
701
- if (prefix in defined && !defined[prefix]) {
702
- delete defined[prefix];
703
- delete urlFetched[prefixMap.url];
704
- }
705
-
706
- pluginManager = getManager(prefixMap, true);
707
- pluginManager.add(function (plugin) {
708
- //Create a new manager for the normalized
709
- //resource ID and have it call this manager when
710
- //done.
711
- var newMap = makeModuleMap(map.originalName, map.parentMap),
712
- normalizedManager = getManager(newMap, true);
713
-
714
- //Indicate this manager is a placeholder for the real,
715
- //normalized thing. Important for when trying to map
716
- //modules and dependencies, for instance, in a build.
717
- manager.placeholder = true;
718
-
719
- normalizedManager.add(function (resource) {
720
- manager.callback = function () {
721
- return resource;
722
- };
723
- execManager(manager);
724
- });
725
- });
726
- } else if (created && shouldQueue) {
727
- //Indicate the resource is not loaded yet if it is to be
728
- //queued.
729
- loaded[manager.id] = false;
730
- queueDependency(manager);
731
- addWait(manager);
732
- }
733
-
734
- return manager;
735
- }
736
-
737
- function main(inName, depArray, callback, relModuleMap) {
738
- var moduleMap = makeModuleMap(inName, relModuleMap),
739
- name = moduleMap.name,
740
- fullName = moduleMap.fullName,
741
- manager = getManager(moduleMap),
742
- id = manager.id,
743
- deps = manager.deps,
744
- i, depArg, depName, depPrefix, cjsMod;
745
-
746
- if (fullName) {
747
- //If module already defined for context, or already loaded,
748
- //then leave. Also leave if jQuery is registering but it does
749
- //not match the desired version number in the config.
750
- if (fullName in defined || loaded[id] === true ||
751
- (fullName === "jquery" && config.jQuery &&
752
- config.jQuery !== callback().fn.jquery)) {
753
- return;
754
- }
755
-
756
- //Set specified/loaded here for modules that are also loaded
757
- //as part of a layer, where onScriptLoad is not fired
758
- //for those cases. Do this after the inline define and
759
- //dependency tracing is done.
760
- specified[id] = true;
761
- loaded[id] = true;
762
-
763
- //If module is jQuery set up delaying its dom ready listeners.
764
- if (fullName === "jquery" && callback) {
765
- jQueryCheck(callback());
766
- }
767
- }
768
-
769
- //Attach real depArray and callback to the manager. Do this
770
- //only if the module has not been defined already, so do this after
771
- //the fullName checks above. IE can call main() more than once
772
- //for a module.
773
- manager.depArray = depArray;
774
- manager.callback = callback;
775
-
776
- //Add the dependencies to the deps field, and register for callbacks
777
- //on the dependencies.
778
- for (i = 0; i < depArray.length; i++) {
779
- depArg = depArray[i];
780
- //There could be cases like in IE, where a trailing comma will
781
- //introduce a null dependency, so only treat a real dependency
782
- //value as a dependency.
783
- if (depArg) {
784
- //Split the dependency name into plugin and name parts
785
- depArg = makeModuleMap(depArg, (name ? moduleMap : relModuleMap));
786
- depName = depArg.fullName;
787
- depPrefix = depArg.prefix;
788
-
789
- //Fix the name in depArray to be just the name, since
790
- //that is how it will be called back later.
791
- depArray[i] = depName;
792
-
793
- //Fast path CommonJS standard dependencies.
794
- if (depName === "require") {
795
- deps[i] = makeRequire(moduleMap);
796
- } else if (depName === "exports") {
797
- //CommonJS module spec 1.1
798
- deps[i] = defined[fullName] = {};
799
- manager.usingExports = true;
800
- } else if (depName === "module") {
801
- //CommonJS module spec 1.1
802
- manager.cjsModule = cjsMod = deps[i] = {
803
- id: name,
804
- uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined,
805
- exports: defined[fullName]
806
- };
807
- } else if (depName in defined && !(depName in waiting) &&
808
- (!(fullName in needFullExec) ||
809
- (fullName in needFullExec && fullExec[depName]))) {
810
- //Module already defined, and not in a build situation
811
- //where the module is a something that needs full
812
- //execution and this dependency has not been fully
813
- //executed. See r.js's requirePatch.js for more info
814
- //on fullExec.
815
- deps[i] = defined[depName];
816
- } else {
817
- //Mark this dependency as needing full exec if
818
- //the current module needs full exec.
819
- if (fullName in needFullExec) {
820
- needFullExec[depName] = true;
821
- //Reset state so fully executed code will get
822
- //picked up correctly.
823
- delete defined[depName];
824
- urlFetched[depArg.url] = false;
825
- }
826
-
827
- //Either a resource that is not loaded yet, or a plugin
828
- //resource for either a plugin that has not
829
- //loaded yet.
830
- manager.depCount += 1;
831
- manager.depCallbacks[i] = makeArgCallback(manager, i);
832
- getManager(depArg, true).add(manager.depCallbacks[i]);
833
- }
834
- }
835
- }
836
-
837
- //Do not bother tracking the manager if it is all done.
838
- if (!manager.depCount) {
839
- //All done, execute!
840
- execManager(manager);
841
- } else {
842
- addWait(manager);
843
- }
844
- }
845
-
846
- /**
847
- * Convenience method to call main for a define call that was put on
848
- * hold in the defQueue.
849
- */
850
- function callDefMain(args) {
851
- main.apply(null, args);
852
- }
853
-
854
- /**
855
- * jQuery 1.4.3+ supports ways to hold off calling
856
- * calling jQuery ready callbacks until all scripts are loaded. Be sure
857
- * to track it if the capability exists.. Also, since jQuery 1.4.3 does
858
- * not register as a module, need to do some global inference checking.
859
- * Even if it does register as a module, not guaranteed to be the precise
860
- * name of the global. If a jQuery is tracked for this context, then go
861
- * ahead and register it as a module too, if not already in process.
862
- */
863
- jQueryCheck = function (jqCandidate) {
864
- if (!context.jQuery) {
865
- var $ = jqCandidate || (typeof jQuery !== "undefined" ? jQuery : null);
866
-
867
- if ($) {
868
- //If a specific version of jQuery is wanted, make sure to only
869
- //use this jQuery if it matches.
870
- if (config.jQuery && $.fn.jquery !== config.jQuery) {
871
- return;
872
- }
873
-
874
- if ("holdReady" in $ || "readyWait" in $) {
875
- context.jQuery = $;
876
-
877
- //Manually create a "jquery" module entry if not one already
878
- //or in process. Note this could trigger an attempt at
879
- //a second jQuery registration, but does no harm since
880
- //the first one wins, and it is the same value anyway.
881
- callDefMain(["jquery", [], function () {
882
- return jQuery;
883
- }]);
884
-
885
- //Ask jQuery to hold DOM ready callbacks.
886
- if (context.scriptCount) {
887
- jQueryHoldReady($, true);
888
- context.jQueryIncremented = true;
889
- }
890
- }
891
- }
892
- }
893
- };
894
-
895
- function findCycle(manager, traced) {
896
- var fullName = manager.map.fullName,
897
- depArray = manager.depArray,
898
- fullyLoaded = true,
899
- i, depName, depManager, result;
900
-
901
- if (manager.isDone || !fullName || !loaded[fullName]) {
902
- return result;
903
- }
904
-
905
- //Found the cycle.
906
- if (traced[fullName]) {
907
- return manager;
908
- }
909
-
910
- traced[fullName] = true;
911
-
912
- //Trace through the dependencies.
913
- if (depArray) {
914
- for (i = 0; i < depArray.length; i++) {
915
- //Some array members may be null, like if a trailing comma
916
- //IE, so do the explicit [i] access and check if it has a value.
917
- depName = depArray[i];
918
- if (!loaded[depName] && !reservedDependencies[depName]) {
919
- fullyLoaded = false;
920
- break;
921
- }
922
- depManager = waiting[depName];
923
- if (depManager && !depManager.isDone && loaded[depName]) {
924
- result = findCycle(depManager, traced);
925
- if (result) {
926
- break;
927
- }
928
- }
929
- }
930
- if (!fullyLoaded) {
931
- //Discard the cycle that was found, since it cannot
932
- //be forced yet. Also clear this module from traced.
933
- result = undefined;
934
- delete traced[fullName];
935
- }
936
- }
937
-
938
- return result;
939
- }
940
-
941
- function forceExec(manager, traced) {
942
- var fullName = manager.map.fullName,
943
- depArray = manager.depArray,
944
- i, depName, depManager, prefix, prefixManager, value;
945
-
946
-
947
- if (manager.isDone || !fullName || !loaded[fullName]) {
948
- return undefined;
949
- }
950
-
951
- if (fullName) {
952
- if (traced[fullName]) {
953
- return defined[fullName];
954
- }
955
-
956
- traced[fullName] = true;
957
- }
958
-
959
- //Trace through the dependencies.
960
- if (depArray) {
961
- for (i = 0; i < depArray.length; i++) {
962
- //Some array members may be null, like if a trailing comma
963
- //IE, so do the explicit [i] access and check if it has a value.
964
- depName = depArray[i];
965
- if (depName) {
966
- //First, make sure if it is a plugin resource that the
967
- //plugin is not blocked.
968
- prefix = makeModuleMap(depName).prefix;
969
- if (prefix && (prefixManager = waiting[prefix])) {
970
- forceExec(prefixManager, traced);
971
- }
972
- depManager = waiting[depName];
973
- if (depManager && !depManager.isDone && loaded[depName]) {
974
- value = forceExec(depManager, traced);
975
- manager.depCallbacks[i](value);
976
- }
977
- }
978
- }
979
- }
980
-
981
- return defined[fullName];
982
- }
983
-
984
- /**
985
- * Checks if all modules for a context are loaded, and if so, evaluates the
986
- * new ones in right dependency order.
987
- *
988
- * @private
989
- */
990
- function checkLoaded() {
991
- var waitInterval = config.waitSeconds * 1000,
992
- //It is possible to disable the wait interval by using waitSeconds of 0.
993
- expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
994
- noLoads = "", hasLoadedProp = false, stillLoading = false,
995
- cycleDeps = [],
996
- i, prop, err, manager, cycleManager, moduleDeps;
997
-
998
- //If there are items still in the paused queue processing wait.
999
- //This is particularly important in the sync case where each paused
1000
- //item is processed right away but there may be more waiting.
1001
- if (context.pausedCount > 0) {
1002
- return undefined;
1003
- }
1004
-
1005
- //Determine if priority loading is done. If so clear the priority. If
1006
- //not, then do not check
1007
- if (config.priorityWait) {
1008
- if (isPriorityDone()) {
1009
- //Call resume, since it could have
1010
- //some waiting dependencies to trace.
1011
- resume();
1012
- } else {
1013
- return undefined;
1014
- }
1015
- }
1016
-
1017
- //See if anything is still in flight.
1018
- for (prop in loaded) {
1019
- if (!(prop in empty)) {
1020
- hasLoadedProp = true;
1021
- if (!loaded[prop]) {
1022
- if (expired) {
1023
- noLoads += prop + " ";
1024
- } else {
1025
- stillLoading = true;
1026
- if (prop.indexOf('!') === -1) {
1027
- //No reason to keep looking for unfinished
1028
- //loading. If the only stillLoading is a
1029
- //plugin resource though, keep going,
1030
- //because it may be that a plugin resource
1031
- //is waiting on a non-plugin cycle.
1032
- cycleDeps = [];
1033
- break;
1034
- } else {
1035
- moduleDeps = managerCallbacks[prop] && managerCallbacks[prop].moduleDeps;
1036
- if (moduleDeps) {
1037
- cycleDeps.push.apply(cycleDeps, moduleDeps);
1038
- }
1039
- }
1040
- }
1041
- }
1042
- }
1043
- }
1044
-
1045
- //Check for exit conditions.
1046
- if (!hasLoadedProp && !context.waitCount) {
1047
- //If the loaded object had no items, then the rest of
1048
- //the work below does not need to be done.
1049
- return undefined;
1050
- }
1051
- if (expired && noLoads) {
1052
- //If wait time expired, throw error of unloaded modules.
1053
- err = makeError("timeout", "Load timeout for modules: " + noLoads);
1054
- err.requireType = "timeout";
1055
- err.requireModules = noLoads;
1056
- return req.onError(err);
1057
- }
1058
-
1059
- //If still loading but a plugin is waiting on a regular module cycle
1060
- //break the cycle.
1061
- if (stillLoading && cycleDeps.length) {
1062
- for (i = 0; (manager = waiting[cycleDeps[i]]); i++) {
1063
- if ((cycleManager = findCycle(manager, {}))) {
1064
- forceExec(cycleManager, {});
1065
- break;
1066
- }
1067
- }
1068
-
1069
- }
1070
-
1071
- //If still waiting on loads, and the waiting load is something
1072
- //other than a plugin resource, or there are still outstanding
1073
- //scripts, then just try back later.
1074
- if (!expired && (stillLoading || context.scriptCount)) {
1075
- //Something is still waiting to load. Wait for it, but only
1076
- //if a timeout is not already in effect.
1077
- if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
1078
- checkLoadedTimeoutId = setTimeout(function () {
1079
- checkLoadedTimeoutId = 0;
1080
- checkLoaded();
1081
- }, 50);
1082
- }
1083
- return undefined;
1084
- }
1085
-
1086
- //If still have items in the waiting cue, but all modules have
1087
- //been loaded, then it means there are some circular dependencies
1088
- //that need to be broken.
1089
- //However, as a waiting thing is fired, then it can add items to
1090
- //the waiting cue, and those items should not be fired yet, so
1091
- //make sure to redo the checkLoaded call after breaking a single
1092
- //cycle, if nothing else loaded then this logic will pick it up
1093
- //again.
1094
- if (context.waitCount) {
1095
- //Cycle through the waitAry, and call items in sequence.
1096
- for (i = 0; (manager = waitAry[i]); i++) {
1097
- forceExec(manager, {});
1098
- }
1099
-
1100
- //If anything got placed in the paused queue, run it down.
1101
- if (context.paused.length) {
1102
- resume();
1103
- }
1104
-
1105
- //Only allow this recursion to a certain depth. Only
1106
- //triggered by errors in calling a module in which its
1107
- //modules waiting on it cannot finish loading, or some circular
1108
- //dependencies that then may add more dependencies.
1109
- //The value of 5 is a bit arbitrary. Hopefully just one extra
1110
- //pass, or two for the case of circular dependencies generating
1111
- //more work that gets resolved in the sync node case.
1112
- if (checkLoadedDepth < 5) {
1113
- checkLoadedDepth += 1;
1114
- checkLoaded();
1115
- }
1116
- }
1117
-
1118
- checkLoadedDepth = 0;
1119
-
1120
- //Check for DOM ready, and nothing is waiting across contexts.
1121
- req.checkReadyState();
1122
-
1123
- return undefined;
1124
- }
1125
-
1126
- /**
1127
- * Resumes tracing of dependencies and then checks if everything is loaded.
1128
- */
1129
- resume = function () {
1130
- var manager, map, url, i, p, args, fullName;
1131
-
1132
- //Any defined modules in the global queue, intake them now.
1133
- context.takeGlobalQueue();
1134
-
1135
- resumeDepth += 1;
1136
-
1137
- if (context.scriptCount <= 0) {
1138
- //Synchronous envs will push the number below zero with the
1139
- //decrement above, be sure to set it back to zero for good measure.
1140
- //require() calls that also do not end up loading scripts could
1141
- //push the number negative too.
1142
- context.scriptCount = 0;
1143
- }
1144
-
1145
- //Make sure any remaining defQueue items get properly processed.
1146
- while (defQueue.length) {
1147
- args = defQueue.shift();
1148
- if (args[0] === null) {
1149
- return req.onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
1150
- } else {
1151
- callDefMain(args);
1152
- }
1153
- }
1154
-
1155
- //Skip the resume of paused dependencies
1156
- //if current context is in priority wait.
1157
- if (!config.priorityWait || isPriorityDone()) {
1158
- while (context.paused.length) {
1159
- p = context.paused;
1160
- context.pausedCount += p.length;
1161
- //Reset paused list
1162
- context.paused = [];
1163
-
1164
- for (i = 0; (manager = p[i]); i++) {
1165
- map = manager.map;
1166
- url = map.url;
1167
- fullName = map.fullName;
1168
-
1169
- //If the manager is for a plugin managed resource,
1170
- //ask the plugin to load it now.
1171
- if (map.prefix) {
1172
- callPlugin(map.prefix, manager);
1173
- } else {
1174
- //Regular dependency.
1175
- if (!urlFetched[url] && !loaded[fullName]) {
1176
- req.load(context, fullName, url);
1177
-
1178
- //Mark the URL as fetched, but only if it is
1179
- //not an empty: URL, used by the optimizer.
1180
- //In that case we need to be sure to call
1181
- //load() for each module that is mapped to
1182
- //empty: so that dependencies are satisfied
1183
- //correctly.
1184
- if (url.indexOf('empty:') !== 0) {
1185
- urlFetched[url] = true;
1186
- }
1187
- }
1188
- }
1189
- }
1190
-
1191
- //Move the start time for timeout forward.
1192
- context.startTime = (new Date()).getTime();
1193
- context.pausedCount -= p.length;
1194
- }
1195
- }
1196
-
1197
- //Only check if loaded when resume depth is 1. It is likely that
1198
- //it is only greater than 1 in sync environments where a factory
1199
- //function also then calls the callback-style require. In those
1200
- //cases, the checkLoaded should not occur until the resume
1201
- //depth is back at the top level.
1202
- if (resumeDepth === 1) {
1203
- checkLoaded();
1204
- }
1205
-
1206
- resumeDepth -= 1;
1207
-
1208
- return undefined;
1209
- };
1210
-
1211
- //Define the context object. Many of these fields are on here
1212
- //just to make debugging easier.
1213
- context = {
1214
- contextName: contextName,
1215
- config: config,
1216
- defQueue: defQueue,
1217
- waiting: waiting,
1218
- waitCount: 0,
1219
- specified: specified,
1220
- loaded: loaded,
1221
- urlMap: urlMap,
1222
- urlFetched: urlFetched,
1223
- scriptCount: 0,
1224
- defined: defined,
1225
- paused: [],
1226
- pausedCount: 0,
1227
- plugins: plugins,
1228
- needFullExec: needFullExec,
1229
- fake: {},
1230
- fullExec: fullExec,
1231
- managerCallbacks: managerCallbacks,
1232
- makeModuleMap: makeModuleMap,
1233
- normalize: normalize,
1234
- /**
1235
- * Set a configuration for the context.
1236
- * @param {Object} cfg config object to integrate.
1237
- */
1238
- configure: function (cfg) {
1239
- var paths, prop, packages, pkgs, packagePaths, requireWait;
1240
-
1241
- //Make sure the baseUrl ends in a slash.
1242
- if (cfg.baseUrl) {
1243
- if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== "/") {
1244
- cfg.baseUrl += "/";
1245
- }
1246
- }
1247
-
1248
- //Save off the paths and packages since they require special processing,
1249
- //they are additive.
1250
- paths = config.paths;
1251
- packages = config.packages;
1252
- pkgs = config.pkgs;
1253
-
1254
- //Mix in the config values, favoring the new values over
1255
- //existing ones in context.config.
1256
- mixin(config, cfg, true);
1257
-
1258
- //Adjust paths if necessary.
1259
- if (cfg.paths) {
1260
- for (prop in cfg.paths) {
1261
- if (!(prop in empty)) {
1262
- paths[prop] = cfg.paths[prop];
1263
- }
1264
- }
1265
- config.paths = paths;
1266
- }
1267
-
1268
- packagePaths = cfg.packagePaths;
1269
- if (packagePaths || cfg.packages) {
1270
- //Convert packagePaths into a packages config.
1271
- if (packagePaths) {
1272
- for (prop in packagePaths) {
1273
- if (!(prop in empty)) {
1274
- configurePackageDir(pkgs, packagePaths[prop], prop);
1275
- }
1276
- }
1277
- }
1278
-
1279
- //Adjust packages if necessary.
1280
- if (cfg.packages) {
1281
- configurePackageDir(pkgs, cfg.packages);
1282
- }
1283
-
1284
- //Done with modifications, assing packages back to context config
1285
- config.pkgs = pkgs;
1286
- }
1287
-
1288
- //If priority loading is in effect, trigger the loads now
1289
- if (cfg.priority) {
1290
- //Hold on to requireWait value, and reset it after done
1291
- requireWait = context.requireWait;
1292
-
1293
- //Allow tracing some require calls to allow the fetching
1294
- //of the priority config.
1295
- context.requireWait = false;
1296
- //But first, call resume to register any defined modules that may
1297
- //be in a data-main built file before the priority config
1298
- //call.
1299
- resume();
1300
-
1301
- context.require(cfg.priority);
1302
-
1303
- //Trigger a resume right away, for the case when
1304
- //the script with the priority load is done as part
1305
- //of a data-main call. In that case the normal resume
1306
- //call will not happen because the scriptCount will be
1307
- //at 1, since the script for data-main is being processed.
1308
- resume();
1309
-
1310
- //Restore previous state.
1311
- context.requireWait = requireWait;
1312
- config.priorityWait = cfg.priority;
1313
- }
1314
-
1315
- //If a deps array or a config callback is specified, then call
1316
- //require with those args. This is useful when require is defined as a
1317
- //config object before require.js is loaded.
1318
- if (cfg.deps || cfg.callback) {
1319
- context.require(cfg.deps || [], cfg.callback);
1320
- }
1321
- },
1322
-
1323
- requireDefined: function (moduleName, relModuleMap) {
1324
- return makeModuleMap(moduleName, relModuleMap).fullName in defined;
1325
- },
1326
-
1327
- requireSpecified: function (moduleName, relModuleMap) {
1328
- return makeModuleMap(moduleName, relModuleMap).fullName in specified;
1329
- },
1330
-
1331
- require: function (deps, callback, relModuleMap) {
1332
- var moduleName, fullName, moduleMap;
1333
- if (typeof deps === "string") {
1334
- if (isFunction(callback)) {
1335
- //Invalid call
1336
- return req.onError(makeError("requireargs", "Invalid require call"));
1337
- }
1338
-
1339
- //Synchronous access to one module. If require.get is
1340
- //available (as in the Node adapter), prefer that.
1341
- //In this case deps is the moduleName and callback is
1342
- //the relModuleMap
1343
- if (req.get) {
1344
- return req.get(context, deps, callback);
1345
- }
1346
-
1347
- //Just return the module wanted. In this scenario, the
1348
- //second arg (if passed) is just the relModuleMap.
1349
- moduleName = deps;
1350
- relModuleMap = callback;
1351
-
1352
- //Normalize module name, if it contains . or ..
1353
- moduleMap = makeModuleMap(moduleName, relModuleMap);
1354
- fullName = moduleMap.fullName;
1355
-
1356
- if (!(fullName in defined)) {
1357
- return req.onError(makeError("notloaded", "Module name '" +
1358
- moduleMap.fullName +
1359
- "' has not been loaded yet for context: " +
1360
- contextName));
1361
- }
1362
- return defined[fullName];
1363
- }
1364
-
1365
- //Call main but only if there are dependencies or
1366
- //a callback to call.
1367
- if (deps && deps.length || callback) {
1368
- main(null, deps, callback, relModuleMap);
1369
- }
1370
-
1371
- //If the require call does not trigger anything new to load,
1372
- //then resume the dependency processing.
1373
- if (!context.requireWait) {
1374
- while (!context.scriptCount && context.paused.length) {
1375
- resume();
1376
- }
1377
- }
1378
- return context.require;
1379
- },
1380
-
1381
- /**
1382
- * Internal method to transfer globalQueue items to this context's
1383
- * defQueue.
1384
- */
1385
- takeGlobalQueue: function () {
1386
- //Push all the globalDefQueue items into the context's defQueue
1387
- if (globalDefQueue.length) {
1388
- //Array splice in the values since the context code has a
1389
- //local var ref to defQueue, so cannot just reassign the one
1390
- //on context.
1391
- apsp.apply(context.defQueue,
1392
- [context.defQueue.length - 1, 0].concat(globalDefQueue));
1393
- globalDefQueue = [];
1394
- }
1395
- },
1396
-
1397
- /**
1398
- * Internal method used by environment adapters to complete a load event.
1399
- * A load event could be a script load or just a load pass from a synchronous
1400
- * load call.
1401
- * @param {String} moduleName the name of the module to potentially complete.
1402
- */
1403
- completeLoad: function (moduleName) {
1404
- var args;
1405
-
1406
- context.takeGlobalQueue();
1407
-
1408
- while (defQueue.length) {
1409
- args = defQueue.shift();
1410
-
1411
- if (args[0] === null) {
1412
- args[0] = moduleName;
1413
- break;
1414
- } else if (args[0] === moduleName) {
1415
- //Found matching define call for this script!
1416
- break;
1417
- } else {
1418
- //Some other named define call, most likely the result
1419
- //of a build layer that included many define calls.
1420
- callDefMain(args);
1421
- args = null;
1422
- }
1423
- }
1424
- if (args) {
1425
- callDefMain(args);
1426
- } else {
1427
- //A script that does not call define(), so just simulate
1428
- //the call for it. Special exception for jQuery dynamic load.
1429
- callDefMain([moduleName, [],
1430
- moduleName === "jquery" && typeof jQuery !== "undefined" ?
1431
- function () {
1432
- return jQuery;
1433
- } : null]);
1434
- }
1435
-
1436
- //Doing this scriptCount decrement branching because sync envs
1437
- //need to decrement after resume, otherwise it looks like
1438
- //loading is complete after the first dependency is fetched.
1439
- //For browsers, it works fine to decrement after, but it means
1440
- //the checkLoaded setTimeout 50 ms cost is taken. To avoid
1441
- //that cost, decrement beforehand.
1442
- if (req.isAsync) {
1443
- context.scriptCount -= 1;
1444
- }
1445
- resume();
1446
- if (!req.isAsync) {
1447
- context.scriptCount -= 1;
1448
- }
1449
- },
1450
-
1451
- /**
1452
- * Converts a module name + .extension into an URL path.
1453
- * *Requires* the use of a module name. It does not support using
1454
- * plain URLs like nameToUrl.
1455
- */
1456
- toUrl: function (moduleNamePlusExt, relModuleMap) {
1457
- var index = moduleNamePlusExt.lastIndexOf("."),
1458
- ext = null;
1459
-
1460
- if (index !== -1) {
1461
- ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
1462
- moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
1463
- }
1464
-
1465
- return context.nameToUrl(moduleNamePlusExt, ext, relModuleMap);
1466
- },
1467
-
1468
- /**
1469
- * Converts a module name to a file path. Supports cases where
1470
- * moduleName may actually be just an URL.
1471
- */
1472
- nameToUrl: function (moduleName, ext, relModuleMap) {
1473
- var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
1474
- config = context.config;
1475
-
1476
- //Normalize module name if have a base relative module name to work from.
1477
- moduleName = normalize(moduleName, relModuleMap && relModuleMap.fullName);
1478
-
1479
- //If a colon is in the URL, it indicates a protocol is used and it is just
1480
- //an URL to a file, or if it starts with a slash or ends with .js, it is just a plain file.
1481
- //The slash is important for protocol-less URLs as well as full paths.
1482
- if (req.jsExtRegExp.test(moduleName)) {
1483
- //Just a plain path, not module name lookup, so just return it.
1484
- //Add extension if it is included. This is a bit wonky, only non-.js things pass
1485
- //an extension, this method probably needs to be reworked.
1486
- url = moduleName + (ext ? ext : "");
1487
- } else {
1488
- //A module that needs to be converted to a path.
1489
- paths = config.paths;
1490
- pkgs = config.pkgs;
1491
-
1492
- syms = moduleName.split("/");
1493
- //For each module name segment, see if there is a path
1494
- //registered for it. Start with most specific name
1495
- //and work up from it.
1496
- for (i = syms.length; i > 0; i--) {
1497
- parentModule = syms.slice(0, i).join("/");
1498
- if (paths[parentModule]) {
1499
- syms.splice(0, i, paths[parentModule]);
1500
- break;
1501
- } else if ((pkg = pkgs[parentModule])) {
1502
- //If module name is just the package name, then looking
1503
- //for the main module.
1504
- if (moduleName === pkg.name) {
1505
- pkgPath = pkg.location + '/' + pkg.main;
1506
- } else {
1507
- pkgPath = pkg.location;
1508
- }
1509
- syms.splice(0, i, pkgPath);
1510
- break;
1511
- }
1512
- }
1513
-
1514
- //Join the path parts together, then figure out if baseUrl is needed.
1515
- url = syms.join("/") + (ext || ".js");
1516
- url = (url.charAt(0) === '/' || url.match(/^\w+:/) ? "" : config.baseUrl) + url;
1517
- }
1518
-
1519
- return config.urlArgs ? url +
1520
- ((url.indexOf('?') === -1 ? '?' : '&') +
1521
- config.urlArgs) : url;
1522
- }
1523
- };
1524
-
1525
- //Make these visible on the context so can be called at the very
1526
- //end of the file to bootstrap
1527
- context.jQueryCheck = jQueryCheck;
1528
- context.resume = resume;
1529
-
1530
- return context;
1531
- }
1532
-
1533
- /**
1534
- * Main entry point.
1535
- *
1536
- * If the only argument to require is a string, then the module that
1537
- * is represented by that string is fetched for the appropriate context.
1538
- *
1539
- * If the first argument is an array, then it will be treated as an array
1540
- * of dependency string names to fetch. An optional function callback can
1541
- * be specified to execute when all of those dependencies are available.
1542
- *
1543
- * Make a local req variable to help Caja compliance (it assumes things
1544
- * on a require that are not standardized), and to give a short
1545
- * name for minification/local scope use.
1546
- */
1547
- req = requirejs = function (deps, callback) {
1548
-
1549
- //Find the right context, use default
1550
- var contextName = defContextName,
1551
- context, config;
1552
-
1553
- // Determine if have config object in the call.
1554
- if (!isArray(deps) && typeof deps !== "string") {
1555
- // deps is a config object
1556
- config = deps;
1557
- if (isArray(callback)) {
1558
- // Adjust args if there are dependencies
1559
- deps = callback;
1560
- callback = arguments[2];
1561
- } else {
1562
- deps = [];
1563
- }
1564
- }
1565
-
1566
- if (config && config.context) {
1567
- contextName = config.context;
1568
- }
1569
-
1570
- context = contexts[contextName] ||
1571
- (contexts[contextName] = newContext(contextName));
1572
-
1573
- if (config) {
1574
- context.configure(config);
1575
- }
1576
-
1577
- return context.require(deps, callback);
1578
- };
1579
-
1580
- /**
1581
- * Support require.config() to make it easier to cooperate with other
1582
- * AMD loaders on globally agreed names.
1583
- */
1584
- req.config = function (config) {
1585
- return req(config);
1586
- };
1587
-
1588
- /**
1589
- * Export require as a global, but only if it does not already exist.
1590
- */
1591
- if (!require) {
1592
- require = req;
1593
- }
1594
-
1595
- /**
1596
- * Global require.toUrl(), to match global require, mostly useful
1597
- * for debugging/work in the global space.
1598
- */
1599
- req.toUrl = function (moduleNamePlusExt) {
1600
- return contexts[defContextName].toUrl(moduleNamePlusExt);
1601
- };
1602
-
1603
- req.version = version;
1604
-
1605
- //Used to filter out dependencies that are already paths.
1606
- req.jsExtRegExp = /^\/|:|\?|\.js$/;
1607
- s = req.s = {
1608
- contexts: contexts,
1609
- //Stores a list of URLs that should not get async script tag treatment.
1610
- skipAsync: {}
1611
- };
1612
-
1613
- req.isAsync = req.isBrowser = isBrowser;
1614
- if (isBrowser) {
1615
- head = s.head = document.getElementsByTagName("head")[0];
1616
- //If BASE tag is in play, using appendChild is a problem for IE6.
1617
- //When that browser dies, this can be removed. Details in this jQuery bug:
1618
- //http://dev.jquery.com/ticket/2709
1619
- baseElement = document.getElementsByTagName("base")[0];
1620
- if (baseElement) {
1621
- head = s.head = baseElement.parentNode;
1622
- }
1623
- }
1624
-
1625
- /**
1626
- * Any errors that require explicitly generates will be passed to this
1627
- * function. Intercept/override it if you want custom error handling.
1628
- * @param {Error} err the error object.
1629
- */
1630
- req.onError = function (err) {
1631
- throw err;
1632
- };
1633
-
1634
- /**
1635
- * Does the request to load a module for the browser case.
1636
- * Make this a separate function to allow other environments
1637
- * to override it.
1638
- *
1639
- * @param {Object} context the require context to find state.
1640
- * @param {String} moduleName the name of the module.
1641
- * @param {Object} url the URL to the module.
1642
- */
1643
- req.load = function (context, moduleName, url) {
1644
- req.resourcesReady(false);
1645
-
1646
- context.scriptCount += 1;
1647
- req.attach(url, context, moduleName);
1648
-
1649
- //If tracking a jQuery, then make sure its ready callbacks
1650
- //are put on hold to prevent its ready callbacks from
1651
- //triggering too soon.
1652
- if (context.jQuery && !context.jQueryIncremented) {
1653
- jQueryHoldReady(context.jQuery, true);
1654
- context.jQueryIncremented = true;
1655
- }
1656
- };
1657
-
1658
- function getInteractiveScript() {
1659
- var scripts, i, script;
1660
- if (interactiveScript && interactiveScript.readyState === 'interactive') {
1661
- return interactiveScript;
1662
- }
1663
-
1664
- scripts = document.getElementsByTagName('script');
1665
- for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) {
1666
- if (script.readyState === 'interactive') {
1667
- return (interactiveScript = script);
1668
- }
1669
- }
1670
-
1671
- return null;
1672
- }
1673
-
1674
- /**
1675
- * The function that handles definitions of modules. Differs from
1676
- * require() in that a string for the module should be the first argument,
1677
- * and the function to execute after dependencies are loaded should
1678
- * return a value to define the module corresponding to the first argument's
1679
- * name.
1680
- */
1681
- define = function (name, deps, callback) {
1682
- var node, context;
1683
-
1684
- //Allow for anonymous functions
1685
- if (typeof name !== 'string') {
1686
- //Adjust args appropriately
1687
- callback = deps;
1688
- deps = name;
1689
- name = null;
1690
- }
1691
-
1692
- //This module may not have dependencies
1693
- if (!isArray(deps)) {
1694
- callback = deps;
1695
- deps = [];
1696
- }
1697
-
1698
- //If no name, and callback is a function, then figure out if it a
1699
- //CommonJS thing with dependencies.
1700
- if (!deps.length && isFunction(callback)) {
1701
- //Remove comments from the callback string,
1702
- //look for require calls, and pull them into the dependencies,
1703
- //but only if there are function args.
1704
- if (callback.length) {
1705
- callback
1706
- .toString()
1707
- .replace(commentRegExp, "")
1708
- .replace(cjsRequireRegExp, function (match, dep) {
1709
- deps.push(dep);
1710
- });
1711
-
1712
- //May be a CommonJS thing even without require calls, but still
1713
- //could use exports, and module. Avoid doing exports and module
1714
- //work though if it just needs require.
1715
- //REQUIRES the function to expect the CommonJS variables in the
1716
- //order listed below.
1717
- deps = (callback.length === 1 ? ["require"] : ["require", "exports", "module"]).concat(deps);
1718
- }
1719
- }
1720
-
1721
- //If in IE 6-8 and hit an anonymous define() call, do the interactive
1722
- //work.
1723
- if (useInteractive) {
1724
- node = currentlyAddingScript || getInteractiveScript();
1725
- if (node) {
1726
- if (!name) {
1727
- name = node.getAttribute("data-requiremodule");
1728
- }
1729
- context = contexts[node.getAttribute("data-requirecontext")];
1730
- }
1731
- }
1732
-
1733
- //Always save off evaluating the def call until the script onload handler.
1734
- //This allows multiple modules to be in a file without prematurely
1735
- //tracing dependencies, and allows for anonymous module support,
1736
- //where the module name is not known until the script onload event
1737
- //occurs. If no context, use the global queue, and get it processed
1738
- //in the onscript load callback.
1739
- (context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
1740
-
1741
- return undefined;
1742
- };
1743
-
1744
- define.amd = {
1745
- multiversion: true,
1746
- plugins: true,
1747
- jQuery: true
1748
- };
1749
-
1750
- /**
1751
- * Executes the text. Normally just uses eval, but can be modified
1752
- * to use a more environment specific call.
1753
- * @param {String} text the text to execute/evaluate.
1754
- */
1755
- req.exec = function (text) {
1756
- return eval(text);
1757
- };
1758
-
1759
- /**
1760
- * Executes a module callack function. Broken out as a separate function
1761
- * solely to allow the build system to sequence the files in the built
1762
- * layer in the right sequence.
1763
- *
1764
- * @private
1765
- */
1766
- req.execCb = function (name, callback, args, exports) {
1767
- return callback.apply(exports, args);
1768
- };
1769
-
1770
-
1771
- /**
1772
- * Adds a node to the DOM. Public function since used by the order plugin.
1773
- * This method should not normally be called by outside code.
1774
- */
1775
- req.addScriptToDom = function (node) {
1776
- //For some cache cases in IE 6-8, the script executes before the end
1777
- //of the appendChild execution, so to tie an anonymous define
1778
- //call to the module name (which is stored on the node), hold on
1779
- //to a reference to this node, but clear after the DOM insertion.
1780
- currentlyAddingScript = node;
1781
- if (baseElement) {
1782
- head.insertBefore(node, baseElement);
1783
- } else {
1784
- head.appendChild(node);
1785
- }
1786
- currentlyAddingScript = null;
1787
- };
1788
-
1789
- /**
1790
- * callback for script loads, used to check status of loading.
1791
- *
1792
- * @param {Event} evt the event from the browser for the script
1793
- * that was loaded.
1794
- *
1795
- * @private
1796
- */
1797
- req.onScriptLoad = function (evt) {
1798
- //Using currentTarget instead of target for Firefox 2.0's sake. Not
1799
- //all old browsers will be supported, but this one was easy enough
1800
- //to support and still makes sense.
1801
- var node = evt.currentTarget || evt.srcElement, contextName, moduleName,
1802
- context;
1803
-
1804
- if (evt.type === "load" || (node && readyRegExp.test(node.readyState))) {
1805
- //Reset interactive script so a script node is not held onto for
1806
- //to long.
1807
- interactiveScript = null;
1808
-
1809
- //Pull out the name of the module and the context.
1810
- contextName = node.getAttribute("data-requirecontext");
1811
- moduleName = node.getAttribute("data-requiremodule");
1812
- context = contexts[contextName];
1813
-
1814
- contexts[contextName].completeLoad(moduleName);
1815
-
1816
- //Clean up script binding. Favor detachEvent because of IE9
1817
- //issue, see attachEvent/addEventListener comment elsewhere
1818
- //in this file.
1819
- if (node.detachEvent && !isOpera) {
1820
- //Probably IE. If not it will throw an error, which will be
1821
- //useful to know.
1822
- node.detachEvent("onreadystatechange", req.onScriptLoad);
1823
- } else {
1824
- node.removeEventListener("load", req.onScriptLoad, false);
1825
- }
1826
- }
1827
- };
1828
-
1829
- /**
1830
- * Attaches the script represented by the URL to the current
1831
- * environment. Right now only supports browser loading,
1832
- * but can be redefined in other environments to do the right thing.
1833
- * @param {String} url the url of the script to attach.
1834
- * @param {Object} context the context that wants the script.
1835
- * @param {moduleName} the name of the module that is associated with the script.
1836
- * @param {Function} [callback] optional callback, defaults to require.onScriptLoad
1837
- * @param {String} [type] optional type, defaults to text/javascript
1838
- * @param {Function} [fetchOnlyFunction] optional function to indicate the script node
1839
- * should be set up to fetch the script but do not attach it to the DOM
1840
- * so that it can later be attached to execute it. This is a way for the
1841
- * order plugin to support ordered loading in IE. Once the script is fetched,
1842
- * but not executed, the fetchOnlyFunction will be called.
1843
- */
1844
- req.attach = function (url, context, moduleName, callback, type, fetchOnlyFunction) {
1845
- var node;
1846
- if (isBrowser) {
1847
- //In the browser so use a script tag
1848
- callback = callback || req.onScriptLoad;
1849
- node = context && context.config && context.config.xhtml ?
1850
- document.createElementNS("http://www.w3.org/1999/xhtml", "html:script") :
1851
- document.createElement("script");
1852
- node.type = type || (context && context.config.scriptType) ||
1853
- "text/javascript";
1854
- node.charset = "utf-8";
1855
- //Use async so Gecko does not block on executing the script if something
1856
- //like a long-polling comet tag is being run first. Gecko likes
1857
- //to evaluate scripts in DOM order, even for dynamic scripts.
1858
- //It will fetch them async, but only evaluate the contents in DOM
1859
- //order, so a long-polling script tag can delay execution of scripts
1860
- //after it. But telling Gecko we expect async gets us the behavior
1861
- //we want -- execute it whenever it is finished downloading. Only
1862
- //Helps Firefox 3.6+
1863
- //Allow some URLs to not be fetched async. Mostly helps the order!
1864
- //plugin
1865
- node.async = !s.skipAsync[url];
1866
-
1867
- if (context) {
1868
- node.setAttribute("data-requirecontext", context.contextName);
1869
- }
1870
- node.setAttribute("data-requiremodule", moduleName);
1871
-
1872
- //Set up load listener. Test attachEvent first because IE9 has
1873
- //a subtle issue in its addEventListener and script onload firings
1874
- //that do not match the behavior of all other browsers with
1875
- //addEventListener support, which fire the onload event for a
1876
- //script right after the script execution. See:
1877
- //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
1878
- //UNFORTUNATELY Opera implements attachEvent but does not follow the script
1879
- //script execution mode.
1880
- if (node.attachEvent && !isOpera) {
1881
- //Probably IE. IE (at least 6-8) do not fire
1882
- //script onload right after executing the script, so
1883
- //we cannot tie the anonymous define call to a name.
1884
- //However, IE reports the script as being in "interactive"
1885
- //readyState at the time of the define call.
1886
- useInteractive = true;
1887
-
1888
-
1889
- if (fetchOnlyFunction) {
1890
- //Need to use old school onreadystate here since
1891
- //when the event fires and the node is not attached
1892
- //to the DOM, the evt.srcElement is null, so use
1893
- //a closure to remember the node.
1894
- node.onreadystatechange = function (evt) {
1895
- //Script loaded but not executed.
1896
- //Clear loaded handler, set the real one that
1897
- //waits for script execution.
1898
- if (node.readyState === 'loaded') {
1899
- node.onreadystatechange = null;
1900
- node.attachEvent("onreadystatechange", callback);
1901
- fetchOnlyFunction(node);
1902
- }
1903
- };
1904
- } else {
1905
- node.attachEvent("onreadystatechange", callback);
1906
- }
1907
- } else {
1908
- node.addEventListener("load", callback, false);
1909
- }
1910
- node.src = url;
1911
-
1912
- //Fetch only means waiting to attach to DOM after loaded.
1913
- if (!fetchOnlyFunction) {
1914
- req.addScriptToDom(node);
1915
- }
1916
-
1917
- return node;
1918
- } else if (isWebWorker) {
1919
- //In a web worker, use importScripts. This is not a very
1920
- //efficient use of importScripts, importScripts will block until
1921
- //its script is downloaded and evaluated. However, if web workers
1922
- //are in play, the expectation that a build has been done so that
1923
- //only one script needs to be loaded anyway. This may need to be
1924
- //reevaluated if other use cases become common.
1925
- importScripts(url);
1926
-
1927
- //Account for anonymous modules
1928
- context.completeLoad(moduleName);
1929
- }
1930
- return null;
1931
- };
1932
-
1933
- //Look for a data-main script attribute, which could also adjust the baseUrl.
1934
- if (isBrowser) {
1935
- //Figure out baseUrl. Get it from the script tag with require.js in it.
1936
- scripts = document.getElementsByTagName("script");
1937
-
1938
- for (globalI = scripts.length - 1; globalI > -1 && (script = scripts[globalI]); globalI--) {
1939
- //Set the "head" where we can append children by
1940
- //using the script's parent.
1941
- if (!head) {
1942
- head = script.parentNode;
1943
- }
1944
-
1945
- //Look for a data-main attribute to set main script for the page
1946
- //to load. If it is there, the path to data main becomes the
1947
- //baseUrl, if it is not already set.
1948
- if ((dataMain = script.getAttribute('data-main'))) {
1949
- if (!cfg.baseUrl) {
1950
- //Pull off the directory of data-main for use as the
1951
- //baseUrl.
1952
- src = dataMain.split('/');
1953
- mainScript = src.pop();
1954
- subPath = src.length ? src.join('/') + '/' : './';
1955
-
1956
- //Set final config.
1957
- cfg.baseUrl = subPath;
1958
- //Strip off any trailing .js since dataMain is now
1959
- //like a module name.
1960
- dataMain = mainScript.replace(jsSuffixRegExp, '');
1961
- }
1962
-
1963
- //Put the data-main script in the files to load.
1964
- cfg.deps = cfg.deps ? cfg.deps.concat(dataMain) : [dataMain];
1965
-
1966
- break;
1967
- }
1968
- }
1969
- }
1970
-
1971
- //See if there is nothing waiting across contexts, and if not, trigger
1972
- //resourcesReady.
1973
- req.checkReadyState = function () {
1974
- var contexts = s.contexts, prop;
1975
- for (prop in contexts) {
1976
- if (!(prop in empty)) {
1977
- if (contexts[prop].waitCount) {
1978
- return;
1979
- }
1980
- }
1981
- }
1982
- req.resourcesReady(true);
1983
- };
1984
-
1985
- /**
1986
- * Internal function that is triggered whenever all scripts/resources
1987
- * have been loaded by the loader. Can be overridden by other, for
1988
- * instance the domReady plugin, which wants to know when all resources
1989
- * are loaded.
1990
- */
1991
- req.resourcesReady = function (isReady) {
1992
- var contexts, context, prop;
1993
-
1994
- //First, set the public variable indicating that resources are loading.
1995
- req.resourcesDone = isReady;
1996
-
1997
- if (req.resourcesDone) {
1998
- //If jQuery with DOM ready delayed, release it now.
1999
- contexts = s.contexts;
2000
- for (prop in contexts) {
2001
- if (!(prop in empty)) {
2002
- context = contexts[prop];
2003
- if (context.jQueryIncremented) {
2004
- jQueryHoldReady(context.jQuery, false);
2005
- context.jQueryIncremented = false;
2006
- }
2007
- }
2008
- }
2009
- }
2010
- };
2011
-
2012
- //FF < 3.6 readyState fix. Needed so that domReady plugin
2013
- //works well in that environment, since require.js is normally
2014
- //loaded via an HTML script tag so it will be there before window load,
2015
- //where the domReady plugin is more likely to be loaded after window load.
2016
- req.pageLoaded = function () {
2017
- if (document.readyState !== "complete") {
2018
- document.readyState = "complete";
2019
- }
2020
- };
2021
- if (isBrowser) {
2022
- if (document.addEventListener) {
2023
- if (!document.readyState) {
2024
- document.readyState = "loading";
2025
- window.addEventListener("load", req.pageLoaded, false);
2026
- }
2027
- }
2028
- }
2029
-
2030
- //Set up default context. If require was a configuration object, use that as base config.
2031
- req(cfg);
2032
-
2033
- //If modules are built into require.js, then need to make sure dependencies are
2034
- //traced. Use a setTimeout in the browser world, to allow all the modules to register
2035
- //themselves. In a non-browser env, assume that modules are not built into require.js,
2036
- //which seems odd to do on the server.
2037
- if (req.isAsync && typeof setTimeout !== "undefined") {
2038
- ctx = s.contexts[(cfg.context || defContextName)];
2039
- //Indicate that the script that includes require() is still loading,
2040
- //so that require()'d dependencies are not traced until the end of the
2041
- //file is parsed (approximated via the setTimeout call).
2042
- ctx.requireWait = true;
2043
- setTimeout(function () {
2044
- ctx.requireWait = false;
2045
-
2046
- if (!ctx.scriptCount) {
2047
- ctx.resume();
2048
- }
2049
- req.checkReadyState();
2050
- }, 0);
2051
- }
2052
- }());