ruby-requirejs 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +25 -0
  3. data/Gemfile +6 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +85 -0
  6. data/Rakefile +1 -0
  7. data/lib/requirejs/action_view/tag_helper.rb +15 -0
  8. data/lib/requirejs/builds/build.js.erb +8 -0
  9. data/lib/requirejs/builds/build.rb +18 -0
  10. data/lib/requirejs/builds/build_config.rb +59 -0
  11. data/lib/requirejs/builds/optimized_build.rb +57 -0
  12. data/lib/requirejs/compiler.rb +21 -0
  13. data/lib/requirejs/config.rb +72 -0
  14. data/lib/requirejs/engine.rb +40 -0
  15. data/lib/requirejs/manifest.rb +56 -0
  16. data/lib/requirejs/runtime/node_runner.js +21 -0
  17. data/lib/requirejs/runtime/r.js +27617 -0
  18. data/lib/requirejs/runtime/runtime.rb +59 -0
  19. data/lib/requirejs/tilt/directive_processor.rb +52 -0
  20. data/lib/requirejs/tilt/template.rb +37 -0
  21. data/lib/requirejs/version.rb +5 -0
  22. data/lib/ruby-requirejs.rb +26 -0
  23. data/ruby-requirejs.gemspec +24 -0
  24. data/spec/cases/basic/in/app.js +10 -0
  25. data/spec/cases/basic/in/application.js +7 -0
  26. data/spec/cases/basic/out/application.js +6 -0
  27. data/spec/cases/basic_almond/in/app.js +10 -0
  28. data/spec/cases/basic_almond/in/application.js +7 -0
  29. data/spec/cases/basic_almond/out/application.js +447 -0
  30. data/spec/cases/basic_digested/in/app.js +10 -0
  31. data/spec/cases/basic_digested/in/application.js +7 -0
  32. data/spec/cases/basic_digested/out/application.js +14 -0
  33. data/spec/cases/basic_minimized_almond/in/app.js +10 -0
  34. data/spec/cases/basic_minimized_almond/in/application.js +7 -0
  35. data/spec/cases/basic_minimized_almond/out/application.js +7 -0
  36. data/spec/cases/basic_optimized/in/app.js +10 -0
  37. data/spec/cases/basic_optimized/in/application.js +7 -0
  38. data/spec/cases/basic_optimized/out/application.js +21 -0
  39. data/spec/cases/simple/in/app.js +10 -0
  40. data/spec/cases/simple/in/application.js +35 -0
  41. data/spec/rails_spec.rb +80 -0
  42. data/spec/spec_helper.rb +22 -0
  43. data/spec/support/helpers.rb +40 -0
  44. data/vendor/assets/javascripts/almond.js +422 -0
  45. data/vendor/assets/javascripts/require.js +2072 -0
  46. metadata +136 -0
@@ -0,0 +1,2072 @@
1
+ /** vim: et:ts=4:sw=4:sts=4
2
+ * @license RequireJS 2.1.10 Copyright (c) 2010-2014, 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
+ //Not using strict: uneven strict support in browsers, #392, and causes
7
+ //problems with requirejs.exec()/transpiler plugins that may not be strict.
8
+ /*jslint regexp: true, nomen: true, sloppy: true */
9
+ /*global window, navigator, document, importScripts, setTimeout, opera */
10
+
11
+ var requirejs, require, define;
12
+ (function (global) {
13
+ var req, s, head, baseElement, dataMain, src,
14
+ interactiveScript, currentlyAddingScript, mainScript, subPath,
15
+ version = '2.1.10',
16
+ commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
17
+ cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
18
+ jsSuffixRegExp = /\.js$/,
19
+ currDirRegExp = /^\.\//,
20
+ op = Object.prototype,
21
+ ostring = op.toString,
22
+ hasOwn = op.hasOwnProperty,
23
+ ap = Array.prototype,
24
+ apsp = ap.splice,
25
+ isBrowser = !!(typeof window !== 'undefined' && typeof navigator !== 'undefined' && window.document),
26
+ isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
27
+ //PS3 indicates loaded and complete, but need to wait for complete
28
+ //specifically. Sequence is 'loading', 'loaded', execution,
29
+ // then 'complete'. The UA check is unfortunate, but not sure how
30
+ //to feature test w/o causing perf issues.
31
+ readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
32
+ /^complete$/ : /^(complete|loaded)$/,
33
+ defContextName = '_',
34
+ //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
35
+ isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]',
36
+ contexts = {},
37
+ cfg = {},
38
+ globalDefQueue = [],
39
+ useInteractive = false;
40
+
41
+ function isFunction(it) {
42
+ return ostring.call(it) === '[object Function]';
43
+ }
44
+
45
+ function isArray(it) {
46
+ return ostring.call(it) === '[object Array]';
47
+ }
48
+
49
+ /**
50
+ * Helper function for iterating over an array. If the func returns
51
+ * a true value, it will break out of the loop.
52
+ */
53
+ function each(ary, func) {
54
+ if (ary) {
55
+ var i;
56
+ for (i = 0; i < ary.length; i += 1) {
57
+ if (ary[i] && func(ary[i], i, ary)) {
58
+ break;
59
+ }
60
+ }
61
+ }
62
+ }
63
+
64
+ /**
65
+ * Helper function for iterating over an array backwards. If the func
66
+ * returns a true value, it will break out of the loop.
67
+ */
68
+ function eachReverse(ary, func) {
69
+ if (ary) {
70
+ var i;
71
+ for (i = ary.length - 1; i > -1; i -= 1) {
72
+ if (ary[i] && func(ary[i], i, ary)) {
73
+ break;
74
+ }
75
+ }
76
+ }
77
+ }
78
+
79
+ function hasProp(obj, prop) {
80
+ return hasOwn.call(obj, prop);
81
+ }
82
+
83
+ function getOwn(obj, prop) {
84
+ return hasProp(obj, prop) && obj[prop];
85
+ }
86
+
87
+ /**
88
+ * Cycles over properties in an object and calls a function for each
89
+ * property value. If the function returns a truthy value, then the
90
+ * iteration is stopped.
91
+ */
92
+ function eachProp(obj, func) {
93
+ var prop;
94
+ for (prop in obj) {
95
+ if (hasProp(obj, prop)) {
96
+ if (func(obj[prop], prop)) {
97
+ break;
98
+ }
99
+ }
100
+ }
101
+ }
102
+
103
+ /**
104
+ * Simple function to mix in properties from source into target,
105
+ * but only if target does not already have a property of the same name.
106
+ */
107
+ function mixin(target, source, force, deepStringMixin) {
108
+ if (source) {
109
+ eachProp(source, function (value, prop) {
110
+ if (force || !hasProp(target, prop)) {
111
+ if (deepStringMixin && typeof value === 'object' && value && !isArray(value) && !isFunction(value) && !(value instanceof RegExp)) {
112
+
113
+ if (!target[prop]) {
114
+ target[prop] = {};
115
+ }
116
+ mixin(target[prop], value, force, deepStringMixin);
117
+ } else {
118
+ target[prop] = value;
119
+ }
120
+ }
121
+ });
122
+ }
123
+ return target;
124
+ }
125
+
126
+ //Similar to Function.prototype.bind, but the 'this' object is specified
127
+ //first, since it is easier to read/figure out what 'this' will be.
128
+ function bind(obj, fn) {
129
+ return function () {
130
+ return fn.apply(obj, arguments);
131
+ };
132
+ }
133
+
134
+ function scripts() {
135
+ return document.getElementsByTagName('script');
136
+ }
137
+
138
+ function defaultOnError(err) {
139
+ throw err;
140
+ }
141
+
142
+ //Allow getting a global that expressed in
143
+ //dot notation, like 'a.b.c'.
144
+ function getGlobal(value) {
145
+ if (!value) {
146
+ return value;
147
+ }
148
+ var g = global;
149
+ each(value.split('.'), function (part) {
150
+ g = g[part];
151
+ });
152
+ return g;
153
+ }
154
+
155
+ /**
156
+ * Constructs an error with a pointer to an URL with more information.
157
+ * @param {String} id the error ID that maps to an ID on a web page.
158
+ * @param {String} message human readable error.
159
+ * @param {Error} [err] the original error, if there is one.
160
+ *
161
+ * @returns {Error}
162
+ */
163
+ function makeError(id, msg, err, requireModules) {
164
+ var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
165
+ e.requireType = id;
166
+ e.requireModules = requireModules;
167
+ if (err) {
168
+ e.originalError = err;
169
+ }
170
+ return e;
171
+ }
172
+
173
+ if (typeof define !== 'undefined') {
174
+ //If a define is already in play via another AMD loader,
175
+ //do not overwrite.
176
+ return;
177
+ }
178
+
179
+ if (typeof requirejs !== 'undefined') {
180
+ if (isFunction(requirejs)) {
181
+ //Do not overwrite and existing requirejs instance.
182
+ return;
183
+ }
184
+ cfg = requirejs;
185
+ requirejs = undefined;
186
+ }
187
+
188
+ //Allow for a require config object
189
+ if (typeof require !== 'undefined' && !isFunction(require)) {
190
+ //assume it is a config object.
191
+ cfg = require;
192
+ require = undefined;
193
+ }
194
+
195
+ function newContext(contextName) {
196
+ var inCheckLoaded, Module, context, handlers,
197
+ checkLoadedTimeoutId,
198
+ config = {
199
+ //Defaults. Do not set a default for map
200
+ //config to speed up normalize(), which
201
+ //will run faster if there is no default.
202
+ waitSeconds: 7,
203
+ baseUrl: './',
204
+ paths: {},
205
+ bundles: {},
206
+ pkgs: {},
207
+ shim: {},
208
+ config: {}
209
+ },
210
+ registry = {},
211
+ //registry of just enabled modules, to speed
212
+ //cycle breaking code when lots of modules
213
+ //are registered, but not activated.
214
+ enabledRegistry = {},
215
+ undefEvents = {},
216
+ defQueue = [],
217
+ defined = {},
218
+ urlFetched = {},
219
+ bundlesMap = {},
220
+ requireCounter = 1,
221
+ unnormalizedCounter = 1;
222
+
223
+ /**
224
+ * Trims the . and .. from an array of path segments.
225
+ * It will keep a leading path segment if a .. will become
226
+ * the first path segment, to help with module name lookups,
227
+ * which act like paths, but can be remapped. But the end result,
228
+ * all paths that use this function should look normalized.
229
+ * NOTE: this method MODIFIES the input array.
230
+ * @param {Array} ary the array of path segments.
231
+ */
232
+ function trimDots(ary) {
233
+ var i, part, length = ary.length;
234
+ for (i = 0; i < length; i++) {
235
+ part = ary[i];
236
+ if (part === '.') {
237
+ ary.splice(i, 1);
238
+ i -= 1;
239
+ } else if (part === '..') {
240
+ if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
241
+ //End of the line. Keep at least one non-dot
242
+ //path segment at the front so it can be mapped
243
+ //correctly to disk. Otherwise, there is likely
244
+ //no path mapping for a path starting with '..'.
245
+ //This can still fail, but catches the most reasonable
246
+ //uses of ..
247
+ break;
248
+ } else if (i > 0) {
249
+ ary.splice(i - 1, 2);
250
+ i -= 2;
251
+ }
252
+ }
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Given a relative module name, like ./something, normalize it to
258
+ * a real name that can be mapped to a path.
259
+ * @param {String} name the relative name
260
+ * @param {String} baseName a real name that the name arg is relative
261
+ * to.
262
+ * @param {Boolean} applyMap apply the map config to the value. Should
263
+ * only be done if this normalization is for a dependency ID.
264
+ * @returns {String} normalized name
265
+ */
266
+ function normalize(name, baseName, applyMap) {
267
+ var pkgMain, mapValue, nameParts, i, j, nameSegment, lastIndex,
268
+ foundMap, foundI, foundStarMap, starI,
269
+ baseParts = baseName && baseName.split('/'),
270
+ normalizedBaseParts = baseParts,
271
+ map = config.map,
272
+ starMap = map && map['*'];
273
+
274
+ //Adjust any relative paths.
275
+ if (name && name.charAt(0) === '.') {
276
+ //If have a base name, try to normalize against it,
277
+ //otherwise, assume it is a top-level require that will
278
+ //be relative to baseUrl in the end.
279
+ if (baseName) {
280
+ //Convert baseName to array, and lop off the last part,
281
+ //so that . matches that 'directory' and not name of the baseName's
282
+ //module. For instance, baseName of 'one/two/three', maps to
283
+ //'one/two/three.js', but we want the directory, 'one/two' for
284
+ //this normalization.
285
+ normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
286
+ name = name.split('/');
287
+ lastIndex = name.length - 1;
288
+
289
+ // If wanting node ID compatibility, strip .js from end
290
+ // of IDs. Have to do this here, and not in nameToUrl
291
+ // because node allows either .js or non .js to map
292
+ // to same file.
293
+ if (config.nodeIdCompat && jsSuffixRegExp.test(name[lastIndex])) {
294
+ name[lastIndex] = name[lastIndex].replace(jsSuffixRegExp, '');
295
+ }
296
+
297
+ name = normalizedBaseParts.concat(name);
298
+ trimDots(name);
299
+ name = name.join('/');
300
+ } else if (name.indexOf('./') === 0) {
301
+ // No baseName, so this is ID is resolved relative
302
+ // to baseUrl, pull off the leading dot.
303
+ name = name.substring(2);
304
+ }
305
+ }
306
+
307
+ //Apply map config if available.
308
+ if (applyMap && map && (baseParts || starMap)) {
309
+ nameParts = name.split('/');
310
+
311
+ outerLoop: for (i = nameParts.length; i > 0; i -= 1) {
312
+ nameSegment = nameParts.slice(0, i).join('/');
313
+
314
+ if (baseParts) {
315
+ //Find the longest baseName segment match in the config.
316
+ //So, do joins on the biggest to smallest lengths of baseParts.
317
+ for (j = baseParts.length; j > 0; j -= 1) {
318
+ mapValue = getOwn(map, baseParts.slice(0, j).join('/'));
319
+
320
+ //baseName segment has config, find if it has one for
321
+ //this name.
322
+ if (mapValue) {
323
+ mapValue = getOwn(mapValue, nameSegment);
324
+ if (mapValue) {
325
+ //Match, update name to the new value.
326
+ foundMap = mapValue;
327
+ foundI = i;
328
+ break outerLoop;
329
+ }
330
+ }
331
+ }
332
+ }
333
+
334
+ //Check for a star map match, but just hold on to it,
335
+ //if there is a shorter segment match later in a matching
336
+ //config, then favor over this star map.
337
+ if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) {
338
+ foundStarMap = getOwn(starMap, nameSegment);
339
+ starI = i;
340
+ }
341
+ }
342
+
343
+ if (!foundMap && foundStarMap) {
344
+ foundMap = foundStarMap;
345
+ foundI = starI;
346
+ }
347
+
348
+ if (foundMap) {
349
+ nameParts.splice(0, foundI, foundMap);
350
+ name = nameParts.join('/');
351
+ }
352
+ }
353
+
354
+ // If the name points to a package's name, use
355
+ // the package main instead.
356
+ pkgMain = getOwn(config.pkgs, name);
357
+
358
+ return pkgMain ? pkgMain : name;
359
+ }
360
+
361
+ function removeScript(name) {
362
+ if (isBrowser) {
363
+ each(scripts(), function (scriptNode) {
364
+ if (scriptNode.getAttribute('data-requiremodule') === name &&
365
+ scriptNode.getAttribute('data-requirecontext') === context.contextName) {
366
+ scriptNode.parentNode.removeChild(scriptNode);
367
+ return true;
368
+ }
369
+ });
370
+ }
371
+ }
372
+
373
+ function hasPathFallback(id) {
374
+ var pathConfig = getOwn(config.paths, id);
375
+ if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
376
+ //Pop off the first array value, since it failed, and
377
+ //retry
378
+ pathConfig.shift();
379
+ context.require.undef(id);
380
+ context.require([id]);
381
+ return true;
382
+ }
383
+ }
384
+
385
+ //Turns a plugin!resource to [plugin, resource]
386
+ //with the plugin being undefined if the name
387
+ //did not have a plugin prefix.
388
+ function splitPrefix(name) {
389
+ var prefix,
390
+ index = name ? name.indexOf('!') : -1;
391
+ if (index > -1) {
392
+ prefix = name.substring(0, index);
393
+ name = name.substring(index + 1, name.length);
394
+ }
395
+ return [prefix, name];
396
+ }
397
+
398
+ /**
399
+ * Creates a module mapping that includes plugin prefix, module
400
+ * name, and path. If parentModuleMap is provided it will
401
+ * also normalize the name via require.normalize()
402
+ *
403
+ * @param {String} name the module name
404
+ * @param {String} [parentModuleMap] parent module map
405
+ * for the module name, used to resolve relative names.
406
+ * @param {Boolean} isNormalized: is the ID already normalized.
407
+ * This is true if this call is done for a define() module ID.
408
+ * @param {Boolean} applyMap: apply the map config to the ID.
409
+ * Should only be true if this map is for a dependency.
410
+ *
411
+ * @returns {Object}
412
+ */
413
+ function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
414
+ var url, pluginModule, suffix, nameParts,
415
+ prefix = null,
416
+ parentName = parentModuleMap ? parentModuleMap.name : null,
417
+ originalName = name,
418
+ isDefine = true,
419
+ normalizedName = '';
420
+
421
+ //If no name, then it means it is a require call, generate an
422
+ //internal name.
423
+ if (!name) {
424
+ isDefine = false;
425
+ name = '_@r' + (requireCounter += 1);
426
+ }
427
+
428
+ nameParts = splitPrefix(name);
429
+ prefix = nameParts[0];
430
+ name = nameParts[1];
431
+
432
+ if (prefix) {
433
+ prefix = normalize(prefix, parentName, applyMap);
434
+ pluginModule = getOwn(defined, prefix);
435
+ }
436
+
437
+ //Account for relative paths if there is a base name.
438
+ if (name) {
439
+ if (prefix) {
440
+ if (pluginModule && pluginModule.normalize) {
441
+ //Plugin is loaded, use its normalize method.
442
+ normalizedName = pluginModule.normalize(name, function (name) {
443
+ return normalize(name, parentName, applyMap);
444
+ });
445
+ } else {
446
+ normalizedName = normalize(name, parentName, applyMap);
447
+ }
448
+ } else {
449
+ //A regular module.
450
+ normalizedName = normalize(name, parentName, applyMap);
451
+
452
+ //Normalized name may be a plugin ID due to map config
453
+ //application in normalize. The map config values must
454
+ //already be normalized, so do not need to redo that part.
455
+ nameParts = splitPrefix(normalizedName);
456
+ prefix = nameParts[0];
457
+ normalizedName = nameParts[1];
458
+ isNormalized = true;
459
+
460
+ url = context.nameToUrl(normalizedName);
461
+ }
462
+ }
463
+
464
+ //If the id is a plugin id that cannot be determined if it needs
465
+ //normalization, stamp it with a unique ID so two matching relative
466
+ //ids that may conflict can be separate.
467
+ suffix = prefix && !pluginModule && !isNormalized ?
468
+ '_unnormalized' + (unnormalizedCounter += 1) :
469
+ '';
470
+
471
+ return {
472
+ prefix: prefix,
473
+ name: normalizedName,
474
+ parentMap: parentModuleMap,
475
+ unnormalized: !!suffix,
476
+ url: url,
477
+ originalName: originalName,
478
+ isDefine: isDefine,
479
+ id: (prefix ?
480
+ prefix + '!' + normalizedName :
481
+ normalizedName) + suffix
482
+ };
483
+ }
484
+
485
+ function getModule(depMap) {
486
+ var id = depMap.id,
487
+ mod = getOwn(registry, id);
488
+
489
+ if (!mod) {
490
+ mod = registry[id] = new context.Module(depMap);
491
+ }
492
+
493
+ return mod;
494
+ }
495
+
496
+ function on(depMap, name, fn) {
497
+ var id = depMap.id,
498
+ mod = getOwn(registry, id);
499
+
500
+ if (hasProp(defined, id) &&
501
+ (!mod || mod.defineEmitComplete)) {
502
+ if (name === 'defined') {
503
+ fn(defined[id]);
504
+ }
505
+ } else {
506
+ mod = getModule(depMap);
507
+ if (mod.error && name === 'error') {
508
+ fn(mod.error);
509
+ } else {
510
+ mod.on(name, fn);
511
+ }
512
+ }
513
+ }
514
+
515
+ function onError(err, errback) {
516
+ var ids = err.requireModules,
517
+ notified = false;
518
+
519
+ if (errback) {
520
+ errback(err);
521
+ } else {
522
+ each(ids, function (id) {
523
+ var mod = getOwn(registry, id);
524
+ if (mod) {
525
+ //Set error on module, so it skips timeout checks.
526
+ mod.error = err;
527
+ if (mod.events.error) {
528
+ notified = true;
529
+ mod.emit('error', err);
530
+ }
531
+ }
532
+ });
533
+
534
+ if (!notified) {
535
+ req.onError(err);
536
+ }
537
+ }
538
+ }
539
+
540
+ /**
541
+ * Internal method to transfer globalQueue items to this context's
542
+ * defQueue.
543
+ */
544
+ function takeGlobalQueue() {
545
+ //Push all the globalDefQueue items into the context's defQueue
546
+ if (globalDefQueue.length) {
547
+ //Array splice in the values since the context code has a
548
+ //local var ref to defQueue, so cannot just reassign the one
549
+ //on context.
550
+ apsp.apply(defQueue,
551
+ [defQueue.length, 0].concat(globalDefQueue));
552
+ globalDefQueue = [];
553
+ }
554
+ }
555
+
556
+ handlers = {
557
+ 'require': function (mod) {
558
+ if (mod.require) {
559
+ return mod.require;
560
+ } else {
561
+ return (mod.require = context.makeRequire(mod.map));
562
+ }
563
+ },
564
+ 'exports': function (mod) {
565
+ mod.usingExports = true;
566
+ if (mod.map.isDefine) {
567
+ if (mod.exports) {
568
+ return mod.exports;
569
+ } else {
570
+ return (mod.exports = defined[mod.map.id] = {});
571
+ }
572
+ }
573
+ },
574
+ 'module': function (mod) {
575
+ if (mod.module) {
576
+ return mod.module;
577
+ } else {
578
+ return (mod.module = {
579
+ id: mod.map.id,
580
+ uri: mod.map.url,
581
+ config: function () {
582
+ return getOwn(config.config, mod.map.id) || {};
583
+ },
584
+ exports: handlers.exports(mod)
585
+ });
586
+ }
587
+ }
588
+ };
589
+
590
+ function cleanRegistry(id) {
591
+ //Clean up machinery used for waiting modules.
592
+ delete registry[id];
593
+ delete enabledRegistry[id];
594
+ }
595
+
596
+ function breakCycle(mod, traced, processed) {
597
+ var id = mod.map.id;
598
+
599
+ if (mod.error) {
600
+ mod.emit('error', mod.error);
601
+ } else {
602
+ traced[id] = true;
603
+ each(mod.depMaps, function (depMap, i) {
604
+ var depId = depMap.id,
605
+ dep = getOwn(registry, depId);
606
+
607
+ //Only force things that have not completed
608
+ //being defined, so still in the registry,
609
+ //and only if it has not been matched up
610
+ //in the module already.
611
+ if (dep && !mod.depMatched[i] && !processed[depId]) {
612
+ if (getOwn(traced, depId)) {
613
+ mod.defineDep(i, defined[depId]);
614
+ mod.check(); //pass false?
615
+ } else {
616
+ breakCycle(dep, traced, processed);
617
+ }
618
+ }
619
+ });
620
+ processed[id] = true;
621
+ }
622
+ }
623
+
624
+ function checkLoaded() {
625
+ var err, usingPathFallback,
626
+ waitInterval = config.waitSeconds * 1000,
627
+ //It is possible to disable the wait interval by using waitSeconds of 0.
628
+ expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
629
+ noLoads = [],
630
+ reqCalls = [],
631
+ stillLoading = false,
632
+ needCycleCheck = true;
633
+
634
+ //Do not bother if this call was a result of a cycle break.
635
+ if (inCheckLoaded) {
636
+ return;
637
+ }
638
+
639
+ inCheckLoaded = true;
640
+
641
+ //Figure out the state of all the modules.
642
+ eachProp(enabledRegistry, function (mod) {
643
+ var map = mod.map,
644
+ modId = map.id;
645
+
646
+ //Skip things that are not enabled or in error state.
647
+ if (!mod.enabled) {
648
+ return;
649
+ }
650
+
651
+ if (!map.isDefine) {
652
+ reqCalls.push(mod);
653
+ }
654
+
655
+ if (!mod.error) {
656
+ //If the module should be executed, and it has not
657
+ //been inited and time is up, remember it.
658
+ if (!mod.inited && expired) {
659
+ if (hasPathFallback(modId)) {
660
+ usingPathFallback = true;
661
+ stillLoading = true;
662
+ } else {
663
+ noLoads.push(modId);
664
+ removeScript(modId);
665
+ }
666
+ } else if (!mod.inited && mod.fetched && map.isDefine) {
667
+ stillLoading = true;
668
+ if (!map.prefix) {
669
+ //No reason to keep looking for unfinished
670
+ //loading. If the only stillLoading is a
671
+ //plugin resource though, keep going,
672
+ //because it may be that a plugin resource
673
+ //is waiting on a non-plugin cycle.
674
+ return (needCycleCheck = false);
675
+ }
676
+ }
677
+ }
678
+ });
679
+
680
+ if (expired && noLoads.length) {
681
+ //If wait time expired, throw error of unloaded modules.
682
+ err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads);
683
+ err.contextName = context.contextName;
684
+ return onError(err);
685
+ }
686
+
687
+ //Not expired, check for a cycle.
688
+ if (needCycleCheck) {
689
+ each(reqCalls, function (mod) {
690
+ breakCycle(mod, {}, {});
691
+ });
692
+ }
693
+
694
+ //If still waiting on loads, and the waiting load is something
695
+ //other than a plugin resource, or there are still outstanding
696
+ //scripts, then just try back later.
697
+ if ((!expired || usingPathFallback) && stillLoading) {
698
+ //Something is still waiting to load. Wait for it, but only
699
+ //if a timeout is not already in effect.
700
+ if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
701
+ checkLoadedTimeoutId = setTimeout(function () {
702
+ checkLoadedTimeoutId = 0;
703
+ checkLoaded();
704
+ }, 50);
705
+ }
706
+ }
707
+
708
+ inCheckLoaded = false;
709
+ }
710
+
711
+ Module = function (map) {
712
+ this.events = getOwn(undefEvents, map.id) || {};
713
+ this.map = map;
714
+ this.shim = getOwn(config.shim, map.id);
715
+ this.depExports = [];
716
+ this.depMaps = [];
717
+ this.depMatched = [];
718
+ this.pluginMaps = {};
719
+ this.depCount = 0;
720
+
721
+ /* this.exports this.factory
722
+ this.depMaps = [],
723
+ this.enabled, this.fetched
724
+ */
725
+ };
726
+
727
+ Module.prototype = {
728
+ init: function (depMaps, factory, errback, options) {
729
+ options = options || {};
730
+
731
+ //Do not do more inits if already done. Can happen if there
732
+ //are multiple define calls for the same module. That is not
733
+ //a normal, common case, but it is also not unexpected.
734
+ if (this.inited) {
735
+ return;
736
+ }
737
+
738
+ this.factory = factory;
739
+
740
+ if (errback) {
741
+ //Register for errors on this module.
742
+ this.on('error', errback);
743
+ } else if (this.events.error) {
744
+ //If no errback already, but there are error listeners
745
+ //on this module, set up an errback to pass to the deps.
746
+ errback = bind(this, function (err) {
747
+ this.emit('error', err);
748
+ });
749
+ }
750
+
751
+ //Do a copy of the dependency array, so that
752
+ //source inputs are not modified. For example
753
+ //"shim" deps are passed in here directly, and
754
+ //doing a direct modification of the depMaps array
755
+ //would affect that config.
756
+ this.depMaps = depMaps && depMaps.slice(0);
757
+
758
+ this.errback = errback;
759
+
760
+ //Indicate this module has be initialized
761
+ this.inited = true;
762
+
763
+ this.ignore = options.ignore;
764
+
765
+ //Could have option to init this module in enabled mode,
766
+ //or could have been previously marked as enabled. However,
767
+ //the dependencies are not known until init is called. So
768
+ //if enabled previously, now trigger dependencies as enabled.
769
+ if (options.enabled || this.enabled) {
770
+ //Enable this module and dependencies.
771
+ //Will call this.check()
772
+ this.enable();
773
+ } else {
774
+ this.check();
775
+ }
776
+ },
777
+
778
+ defineDep: function (i, depExports) {
779
+ //Because of cycles, defined callback for a given
780
+ //export can be called more than once.
781
+ if (!this.depMatched[i]) {
782
+ this.depMatched[i] = true;
783
+ this.depCount -= 1;
784
+ this.depExports[i] = depExports;
785
+ }
786
+ },
787
+
788
+ fetch: function () {
789
+ if (this.fetched) {
790
+ return;
791
+ }
792
+ this.fetched = true;
793
+
794
+ context.startTime = (new Date()).getTime();
795
+
796
+ var map = this.map;
797
+
798
+ //If the manager is for a plugin managed resource,
799
+ //ask the plugin to load it now.
800
+ if (this.shim) {
801
+ context.makeRequire(this.map, {
802
+ enableBuildCallback: true
803
+ })(this.shim.deps || [], bind(this, function () {
804
+ return map.prefix ? this.callPlugin() : this.load();
805
+ }));
806
+ } else {
807
+ //Regular dependency.
808
+ return map.prefix ? this.callPlugin() : this.load();
809
+ }
810
+ },
811
+
812
+ load: function () {
813
+ var url = this.map.url;
814
+
815
+ //Regular dependency.
816
+ if (!urlFetched[url]) {
817
+ urlFetched[url] = true;
818
+ context.load(this.map.id, url);
819
+ }
820
+ },
821
+
822
+ /**
823
+ * Checks if the module is ready to define itself, and if so,
824
+ * define it.
825
+ */
826
+ check: function () {
827
+ if (!this.enabled || this.enabling) {
828
+ return;
829
+ }
830
+
831
+ var err, cjsModule,
832
+ id = this.map.id,
833
+ depExports = this.depExports,
834
+ exports = this.exports,
835
+ factory = this.factory;
836
+
837
+ if (!this.inited) {
838
+ this.fetch();
839
+ } else if (this.error) {
840
+ this.emit('error', this.error);
841
+ } else if (!this.defining) {
842
+ //The factory could trigger another require call
843
+ //that would result in checking this module to
844
+ //define itself again. If already in the process
845
+ //of doing that, skip this work.
846
+ this.defining = true;
847
+
848
+ if (this.depCount < 1 && !this.defined) {
849
+ if (isFunction(factory)) {
850
+ //If there is an error listener, favor passing
851
+ //to that instead of throwing an error. However,
852
+ //only do it for define()'d modules. require
853
+ //errbacks should not be called for failures in
854
+ //their callbacks (#699). However if a global
855
+ //onError is set, use that.
856
+ if ((this.events.error && this.map.isDefine) ||
857
+ req.onError !== defaultOnError) {
858
+ try {
859
+ exports = context.execCb(id, factory, depExports, exports);
860
+ } catch (e) {
861
+ err = e;
862
+ }
863
+ } else {
864
+ exports = context.execCb(id, factory, depExports, exports);
865
+ }
866
+
867
+ // Favor return value over exports. If node/cjs in play,
868
+ // then will not have a return value anyway. Favor
869
+ // module.exports assignment over exports object.
870
+ if (this.map.isDefine && exports === undefined) {
871
+ cjsModule = this.module;
872
+ if (cjsModule) {
873
+ exports = cjsModule.exports;
874
+ } else if (this.usingExports) {
875
+ //exports already set the defined value.
876
+ exports = this.exports;
877
+ }
878
+ }
879
+
880
+ if (err) {
881
+ err.requireMap = this.map;
882
+ err.requireModules = this.map.isDefine ? [this.map.id] : null;
883
+ err.requireType = this.map.isDefine ? 'define' : 'require';
884
+ return onError((this.error = err));
885
+ }
886
+
887
+ } else {
888
+ //Just a literal value
889
+ exports = factory;
890
+ }
891
+
892
+ this.exports = exports;
893
+
894
+ if (this.map.isDefine && !this.ignore) {
895
+ defined[id] = exports;
896
+
897
+ if (req.onResourceLoad) {
898
+ req.onResourceLoad(context, this.map, this.depMaps);
899
+ }
900
+ }
901
+
902
+ //Clean up
903
+ cleanRegistry(id);
904
+
905
+ this.defined = true;
906
+ }
907
+
908
+ //Finished the define stage. Allow calling check again
909
+ //to allow define notifications below in the case of a
910
+ //cycle.
911
+ this.defining = false;
912
+
913
+ if (this.defined && !this.defineEmitted) {
914
+ this.defineEmitted = true;
915
+ this.emit('defined', this.exports);
916
+ this.defineEmitComplete = true;
917
+ }
918
+
919
+ }
920
+ },
921
+
922
+ callPlugin: function () {
923
+ var map = this.map,
924
+ id = map.id,
925
+ //Map already normalized the prefix.
926
+ pluginMap = makeModuleMap(map.prefix);
927
+
928
+ //Mark this as a dependency for this plugin, so it
929
+ //can be traced for cycles.
930
+ this.depMaps.push(pluginMap);
931
+
932
+ on(pluginMap, 'defined', bind(this, function (plugin) {
933
+ var load, normalizedMap, normalizedMod,
934
+ bundleId = getOwn(bundlesMap, this.map.id),
935
+ name = this.map.name,
936
+ parentName = this.map.parentMap ? this.map.parentMap.name : null,
937
+ localRequire = context.makeRequire(map.parentMap, {
938
+ enableBuildCallback: true
939
+ });
940
+
941
+ //If current map is not normalized, wait for that
942
+ //normalized name to load instead of continuing.
943
+ if (this.map.unnormalized) {
944
+ //Normalize the ID if the plugin allows it.
945
+ if (plugin.normalize) {
946
+ name = plugin.normalize(name, function (name) {
947
+ return normalize(name, parentName, true);
948
+ }) || '';
949
+ }
950
+
951
+ //prefix and name should already be normalized, no need
952
+ //for applying map config again either.
953
+ normalizedMap = makeModuleMap(map.prefix + '!' + name,
954
+ this.map.parentMap);
955
+ on(normalizedMap,
956
+ 'defined', bind(this, function (value) {
957
+ this.init([], function () {
958
+ return value;
959
+ }, null, {
960
+ enabled: true,
961
+ ignore: true
962
+ });
963
+ }));
964
+
965
+ normalizedMod = getOwn(registry, normalizedMap.id);
966
+ if (normalizedMod) {
967
+ //Mark this as a dependency for this plugin, so it
968
+ //can be traced for cycles.
969
+ this.depMaps.push(normalizedMap);
970
+
971
+ if (this.events.error) {
972
+ normalizedMod.on('error', bind(this, function (err) {
973
+ this.emit('error', err);
974
+ }));
975
+ }
976
+ normalizedMod.enable();
977
+ }
978
+
979
+ return;
980
+ }
981
+
982
+ //If a paths config, then just load that file instead to
983
+ //resolve the plugin, as it is built into that paths layer.
984
+ if (bundleId) {
985
+ this.map.url = context.nameToUrl(bundleId);
986
+ this.load();
987
+ return;
988
+ }
989
+
990
+ load = bind(this, function (value) {
991
+ this.init([], function () {
992
+ return value;
993
+ }, null, {
994
+ enabled: true
995
+ });
996
+ });
997
+
998
+ load.error = bind(this, function (err) {
999
+ this.inited = true;
1000
+ this.error = err;
1001
+ err.requireModules = [id];
1002
+
1003
+ //Remove temp unnormalized modules for this module,
1004
+ //since they will never be resolved otherwise now.
1005
+ eachProp(registry, function (mod) {
1006
+ if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
1007
+ cleanRegistry(mod.map.id);
1008
+ }
1009
+ });
1010
+
1011
+ onError(err);
1012
+ });
1013
+
1014
+ //Allow plugins to load other code without having to know the
1015
+ //context or how to 'complete' the load.
1016
+ load.fromText = bind(this, function (text, textAlt) {
1017
+ /*jslint evil: true */
1018
+ var moduleName = map.name,
1019
+ moduleMap = makeModuleMap(moduleName),
1020
+ hasInteractive = useInteractive;
1021
+
1022
+ //As of 2.1.0, support just passing the text, to reinforce
1023
+ //fromText only being called once per resource. Still
1024
+ //support old style of passing moduleName but discard
1025
+ //that moduleName in favor of the internal ref.
1026
+ if (textAlt) {
1027
+ text = textAlt;
1028
+ }
1029
+
1030
+ //Turn off interactive script matching for IE for any define
1031
+ //calls in the text, then turn it back on at the end.
1032
+ if (hasInteractive) {
1033
+ useInteractive = false;
1034
+ }
1035
+
1036
+ //Prime the system by creating a module instance for
1037
+ //it.
1038
+ getModule(moduleMap);
1039
+
1040
+ //Transfer any config to this other module.
1041
+ if (hasProp(config.config, id)) {
1042
+ config.config[moduleName] = config.config[id];
1043
+ }
1044
+
1045
+ try {
1046
+ req.exec(text);
1047
+ } catch (e) {
1048
+ return onError(makeError('fromtexteval',
1049
+ 'fromText eval for ' + id +
1050
+ ' failed: ' + e,
1051
+ e,
1052
+ [id]));
1053
+ }
1054
+
1055
+ if (hasInteractive) {
1056
+ useInteractive = true;
1057
+ }
1058
+
1059
+ //Mark this as a dependency for the plugin
1060
+ //resource
1061
+ this.depMaps.push(moduleMap);
1062
+
1063
+ //Support anonymous modules.
1064
+ context.completeLoad(moduleName);
1065
+
1066
+ //Bind the value of that module to the value for this
1067
+ //resource ID.
1068
+ localRequire([moduleName], load);
1069
+ });
1070
+
1071
+ //Use parentName here since the plugin's name is not reliable,
1072
+ //could be some weird string with no path that actually wants to
1073
+ //reference the parentName's path.
1074
+ plugin.load(map.name, localRequire, load, config);
1075
+ }));
1076
+
1077
+ context.enable(pluginMap, this);
1078
+ this.pluginMaps[pluginMap.id] = pluginMap;
1079
+ },
1080
+
1081
+ enable: function () {
1082
+ enabledRegistry[this.map.id] = this;
1083
+ this.enabled = true;
1084
+
1085
+ //Set flag mentioning that the module is enabling,
1086
+ //so that immediate calls to the defined callbacks
1087
+ //for dependencies do not trigger inadvertent load
1088
+ //with the depCount still being zero.
1089
+ this.enabling = true;
1090
+
1091
+ //Enable each dependency
1092
+ each(this.depMaps, bind(this, function (depMap, i) {
1093
+ var id, mod, handler;
1094
+
1095
+ if (typeof depMap === 'string') {
1096
+ //Dependency needs to be converted to a depMap
1097
+ //and wired up to this module.
1098
+ depMap = makeModuleMap(depMap,
1099
+ (this.map.isDefine ? this.map : this.map.parentMap),
1100
+ false,
1101
+ !this.skipMap);
1102
+ this.depMaps[i] = depMap;
1103
+
1104
+ handler = getOwn(handlers, depMap.id);
1105
+
1106
+ if (handler) {
1107
+ this.depExports[i] = handler(this);
1108
+ return;
1109
+ }
1110
+
1111
+ this.depCount += 1;
1112
+
1113
+ on(depMap, 'defined', bind(this, function (depExports) {
1114
+ this.defineDep(i, depExports);
1115
+ this.check();
1116
+ }));
1117
+
1118
+ if (this.errback) {
1119
+ on(depMap, 'error', bind(this, this.errback));
1120
+ }
1121
+ }
1122
+
1123
+ id = depMap.id;
1124
+ mod = registry[id];
1125
+
1126
+ //Skip special modules like 'require', 'exports', 'module'
1127
+ //Also, don't call enable if it is already enabled,
1128
+ //important in circular dependency cases.
1129
+ if (!hasProp(handlers, id) && mod && !mod.enabled) {
1130
+ context.enable(depMap, this);
1131
+ }
1132
+ }));
1133
+
1134
+ //Enable each plugin that is used in
1135
+ //a dependency
1136
+ eachProp(this.pluginMaps, bind(this, function (pluginMap) {
1137
+ var mod = getOwn(registry, pluginMap.id);
1138
+ if (mod && !mod.enabled) {
1139
+ context.enable(pluginMap, this);
1140
+ }
1141
+ }));
1142
+
1143
+ this.enabling = false;
1144
+
1145
+ this.check();
1146
+ },
1147
+
1148
+ on: function (name, cb) {
1149
+ var cbs = this.events[name];
1150
+ if (!cbs) {
1151
+ cbs = this.events[name] = [];
1152
+ }
1153
+ cbs.push(cb);
1154
+ },
1155
+
1156
+ emit: function (name, evt) {
1157
+ each(this.events[name], function (cb) {
1158
+ cb(evt);
1159
+ });
1160
+ if (name === 'error') {
1161
+ //Now that the error handler was triggered, remove
1162
+ //the listeners, since this broken Module instance
1163
+ //can stay around for a while in the registry.
1164
+ delete this.events[name];
1165
+ }
1166
+ }
1167
+ };
1168
+
1169
+ function callGetModule(args) {
1170
+ //Skip modules already defined.
1171
+ if (!hasProp(defined, args[0])) {
1172
+ getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]);
1173
+ }
1174
+ }
1175
+
1176
+ function removeListener(node, func, name, ieName) {
1177
+ //Favor detachEvent because of IE9
1178
+ //issue, see attachEvent/addEventListener comment elsewhere
1179
+ //in this file.
1180
+ if (node.detachEvent && !isOpera) {
1181
+ //Probably IE. If not it will throw an error, which will be
1182
+ //useful to know.
1183
+ if (ieName) {
1184
+ node.detachEvent(ieName, func);
1185
+ }
1186
+ } else {
1187
+ node.removeEventListener(name, func, false);
1188
+ }
1189
+ }
1190
+
1191
+ /**
1192
+ * Given an event from a script node, get the requirejs info from it,
1193
+ * and then removes the event listeners on the node.
1194
+ * @param {Event} evt
1195
+ * @returns {Object}
1196
+ */
1197
+ function getScriptData(evt) {
1198
+ //Using currentTarget instead of target for Firefox 2.0's sake. Not
1199
+ //all old browsers will be supported, but this one was easy enough
1200
+ //to support and still makes sense.
1201
+ var node = evt.currentTarget || evt.srcElement;
1202
+
1203
+ //Remove the listeners once here.
1204
+ removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
1205
+ removeListener(node, context.onScriptError, 'error');
1206
+
1207
+ return {
1208
+ node: node,
1209
+ id: node && node.getAttribute('data-requiremodule')
1210
+ };
1211
+ }
1212
+
1213
+ function intakeDefines() {
1214
+ var args;
1215
+
1216
+ //Any defined modules in the global queue, intake them now.
1217
+ takeGlobalQueue();
1218
+
1219
+ //Make sure any remaining defQueue items get properly processed.
1220
+ while (defQueue.length) {
1221
+ args = defQueue.shift();
1222
+ if (args[0] === null) {
1223
+ return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
1224
+ } else {
1225
+ //args are id, deps, factory. Should be normalized by the
1226
+ //define() function.
1227
+ callGetModule(args);
1228
+ }
1229
+ }
1230
+ }
1231
+
1232
+ context = {
1233
+ config: config,
1234
+ contextName: contextName,
1235
+ registry: registry,
1236
+ defined: defined,
1237
+ urlFetched: urlFetched,
1238
+ defQueue: defQueue,
1239
+ Module: Module,
1240
+ makeModuleMap: makeModuleMap,
1241
+ nextTick: req.nextTick,
1242
+ onError: onError,
1243
+
1244
+ /**
1245
+ * Set a configuration for the context.
1246
+ * @param {Object} cfg config object to integrate.
1247
+ */
1248
+ configure: function (cfg) {
1249
+ //Make sure the baseUrl ends in a slash.
1250
+ if (cfg.baseUrl) {
1251
+ if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
1252
+ cfg.baseUrl += '/';
1253
+ }
1254
+ }
1255
+
1256
+ //Save off the paths since they require special processing,
1257
+ //they are additive.
1258
+ var shim = config.shim,
1259
+ objs = {
1260
+ paths: true,
1261
+ bundles: true,
1262
+ config: true,
1263
+ map: true
1264
+ };
1265
+
1266
+ eachProp(cfg, function (value, prop) {
1267
+ if (objs[prop]) {
1268
+ if (!config[prop]) {
1269
+ config[prop] = {};
1270
+ }
1271
+ mixin(config[prop], value, true, true);
1272
+ } else {
1273
+ config[prop] = value;
1274
+ }
1275
+ });
1276
+
1277
+ //Reverse map the bundles
1278
+ if (cfg.bundles) {
1279
+ eachProp(cfg.bundles, function (value, prop) {
1280
+ each(value, function (v) {
1281
+ if (v !== prop) {
1282
+ bundlesMap[v] = prop;
1283
+ }
1284
+ });
1285
+ });
1286
+ }
1287
+
1288
+ //Merge shim
1289
+ if (cfg.shim) {
1290
+ eachProp(cfg.shim, function (value, id) {
1291
+ //Normalize the structure
1292
+ if (isArray(value)) {
1293
+ value = {
1294
+ deps: value
1295
+ };
1296
+ }
1297
+ if ((value.exports || value.init) && !value.exportsFn) {
1298
+ value.exportsFn = context.makeShimExports(value);
1299
+ }
1300
+ shim[id] = value;
1301
+ });
1302
+ config.shim = shim;
1303
+ }
1304
+
1305
+ //Adjust packages if necessary.
1306
+ if (cfg.packages) {
1307
+ each(cfg.packages, function (pkgObj) {
1308
+ var location, name;
1309
+
1310
+ pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj;
1311
+
1312
+ name = pkgObj.name;
1313
+ location = pkgObj.location;
1314
+ if (location) {
1315
+ config.paths[name] = pkgObj.location;
1316
+ }
1317
+
1318
+ //Save pointer to main module ID for pkg name.
1319
+ //Remove leading dot in main, so main paths are normalized,
1320
+ //and remove any trailing .js, since different package
1321
+ //envs have different conventions: some use a module name,
1322
+ //some use a file name.
1323
+ config.pkgs[name] = pkgObj.name + '/' + (pkgObj.main || 'main')
1324
+ .replace(currDirRegExp, '')
1325
+ .replace(jsSuffixRegExp, '');
1326
+ });
1327
+ }
1328
+
1329
+ //If there are any "waiting to execute" modules in the registry,
1330
+ //update the maps for them, since their info, like URLs to load,
1331
+ //may have changed.
1332
+ eachProp(registry, function (mod, id) {
1333
+ //If module already has init called, since it is too
1334
+ //late to modify them, and ignore unnormalized ones
1335
+ //since they are transient.
1336
+ if (!mod.inited && !mod.map.unnormalized) {
1337
+ mod.map = makeModuleMap(id);
1338
+ }
1339
+ });
1340
+
1341
+ //If a deps array or a config callback is specified, then call
1342
+ //require with those args. This is useful when require is defined as a
1343
+ //config object before require.js is loaded.
1344
+ if (cfg.deps || cfg.callback) {
1345
+ context.require(cfg.deps || [], cfg.callback);
1346
+ }
1347
+ },
1348
+
1349
+ makeShimExports: function (value) {
1350
+ function fn() {
1351
+ var ret;
1352
+ if (value.init) {
1353
+ ret = value.init.apply(global, arguments);
1354
+ }
1355
+ return ret || (value.exports && getGlobal(value.exports));
1356
+ }
1357
+
1358
+ return fn;
1359
+ },
1360
+
1361
+ makeRequire: function (relMap, options) {
1362
+ options = options || {};
1363
+
1364
+ function localRequire(deps, callback, errback) {
1365
+ var id, map, requireMod;
1366
+
1367
+ if (options.enableBuildCallback && callback && isFunction(callback)) {
1368
+ callback.__requireJsBuild = true;
1369
+ }
1370
+
1371
+ if (typeof deps === 'string') {
1372
+ if (isFunction(callback)) {
1373
+ //Invalid call
1374
+ return onError(makeError('requireargs', 'Invalid require call'), errback);
1375
+ }
1376
+
1377
+ //If require|exports|module are requested, get the
1378
+ //value for them from the special handlers. Caveat:
1379
+ //this only works while module is being defined.
1380
+ if (relMap && hasProp(handlers, deps)) {
1381
+ return handlers[deps](registry[relMap.id]);
1382
+ }
1383
+
1384
+ //Synchronous access to one module. If require.get is
1385
+ //available (as in the Node adapter), prefer that.
1386
+ if (req.get) {
1387
+ return req.get(context, deps, relMap, localRequire);
1388
+ }
1389
+
1390
+ //Normalize module name, if it contains . or ..
1391
+ map = makeModuleMap(deps, relMap, false, true);
1392
+ id = map.id;
1393
+
1394
+ if (!hasProp(defined, id)) {
1395
+ return onError(makeError('notloaded', 'Module name "' +
1396
+ id +
1397
+ '" has not been loaded yet for context: ' +
1398
+ contextName +
1399
+ (relMap ? '' : '. Use require([])')));
1400
+ }
1401
+ return defined[id];
1402
+ }
1403
+
1404
+ //Grab defines waiting in the global queue.
1405
+ intakeDefines();
1406
+
1407
+ //Mark all the dependencies as needing to be loaded.
1408
+ context.nextTick(function () {
1409
+ //Some defines could have been added since the
1410
+ //require call, collect them.
1411
+ intakeDefines();
1412
+
1413
+ requireMod = getModule(makeModuleMap(null, relMap));
1414
+
1415
+ //Store if map config should be applied to this require
1416
+ //call for dependencies.
1417
+ requireMod.skipMap = options.skipMap;
1418
+
1419
+ requireMod.init(deps, callback, errback, {
1420
+ enabled: true
1421
+ });
1422
+
1423
+ checkLoaded();
1424
+ });
1425
+
1426
+ return localRequire;
1427
+ }
1428
+
1429
+ mixin(localRequire, {
1430
+ isBrowser: isBrowser,
1431
+
1432
+ /**
1433
+ * Converts a module name + .extension into an URL path.
1434
+ * *Requires* the use of a module name. It does not support using
1435
+ * plain URLs like nameToUrl.
1436
+ */
1437
+ toUrl: function (moduleNamePlusExt) {
1438
+ var ext,
1439
+ index = moduleNamePlusExt.lastIndexOf('.'),
1440
+ segment = moduleNamePlusExt.split('/')[0],
1441
+ isRelative = segment === '.' || segment === '..';
1442
+
1443
+ //Have a file extension alias, and it is not the
1444
+ //dots from a relative path.
1445
+ if (index !== -1 && (!isRelative || index > 1)) {
1446
+ ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
1447
+ moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
1448
+ }
1449
+
1450
+ return context.nameToUrl(normalize(moduleNamePlusExt,
1451
+ relMap && relMap.id, true), ext, true);
1452
+ },
1453
+
1454
+ defined: function (id) {
1455
+ return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
1456
+ },
1457
+
1458
+ specified: function (id) {
1459
+ id = makeModuleMap(id, relMap, false, true).id;
1460
+ return hasProp(defined, id) || hasProp(registry, id);
1461
+ }
1462
+ });
1463
+
1464
+ //Only allow undef on top level require calls
1465
+ if (!relMap) {
1466
+ localRequire.undef = function (id) {
1467
+ //Bind any waiting define() calls to this context,
1468
+ //fix for #408
1469
+ takeGlobalQueue();
1470
+
1471
+ var map = makeModuleMap(id, relMap, true),
1472
+ mod = getOwn(registry, id);
1473
+
1474
+ removeScript(id);
1475
+
1476
+ delete defined[id];
1477
+ delete urlFetched[map.url];
1478
+ delete undefEvents[id];
1479
+
1480
+ //Clean queued defines too. Go backwards
1481
+ //in array so that the splices do not
1482
+ //mess up the iteration.
1483
+ eachReverse(defQueue, function (args, i) {
1484
+ if (args[0] === id) {
1485
+ defQueue.splice(i, 1);
1486
+ }
1487
+ });
1488
+
1489
+ if (mod) {
1490
+ //Hold on to listeners in case the
1491
+ //module will be attempted to be reloaded
1492
+ //using a different config.
1493
+ if (mod.events.defined) {
1494
+ undefEvents[id] = mod.events;
1495
+ }
1496
+
1497
+ cleanRegistry(id);
1498
+ }
1499
+ };
1500
+ }
1501
+
1502
+ return localRequire;
1503
+ },
1504
+
1505
+ /**
1506
+ * Called to enable a module if it is still in the registry
1507
+ * awaiting enablement. A second arg, parent, the parent module,
1508
+ * is passed in for context, when this method is overriden by
1509
+ * the optimizer. Not shown here to keep code compact.
1510
+ */
1511
+ enable: function (depMap) {
1512
+ var mod = getOwn(registry, depMap.id);
1513
+ if (mod) {
1514
+ getModule(depMap).enable();
1515
+ }
1516
+ },
1517
+
1518
+ /**
1519
+ * Internal method used by environment adapters to complete a load event.
1520
+ * A load event could be a script load or just a load pass from a synchronous
1521
+ * load call.
1522
+ * @param {String} moduleName the name of the module to potentially complete.
1523
+ */
1524
+ completeLoad: function (moduleName) {
1525
+ var found, args, mod,
1526
+ shim = getOwn(config.shim, moduleName) || {},
1527
+ shExports = shim.exports;
1528
+
1529
+ takeGlobalQueue();
1530
+
1531
+ while (defQueue.length) {
1532
+ args = defQueue.shift();
1533
+ if (args[0] === null) {
1534
+ args[0] = moduleName;
1535
+ //If already found an anonymous module and bound it
1536
+ //to this name, then this is some other anon module
1537
+ //waiting for its completeLoad to fire.
1538
+ if (found) {
1539
+ break;
1540
+ }
1541
+ found = true;
1542
+ } else if (args[0] === moduleName) {
1543
+ //Found matching define call for this script!
1544
+ found = true;
1545
+ }
1546
+
1547
+ callGetModule(args);
1548
+ }
1549
+
1550
+ //Do this after the cycle of callGetModule in case the result
1551
+ //of those calls/init calls changes the registry.
1552
+ mod = getOwn(registry, moduleName);
1553
+
1554
+ if (!found && !hasProp(defined, moduleName) && mod && !mod.inited) {
1555
+ if (config.enforceDefine && (!shExports || !getGlobal(shExports))) {
1556
+ if (hasPathFallback(moduleName)) {
1557
+ return;
1558
+ } else {
1559
+ return onError(makeError('nodefine',
1560
+ 'No define call for ' + moduleName,
1561
+ null,
1562
+ [moduleName]));
1563
+ }
1564
+ } else {
1565
+ //A script that does not call define(), so just simulate
1566
+ //the call for it.
1567
+ callGetModule([moduleName, (shim.deps || []), shim.exportsFn]);
1568
+ }
1569
+ }
1570
+
1571
+ checkLoaded();
1572
+ },
1573
+
1574
+ /**
1575
+ * Converts a module name to a file path. Supports cases where
1576
+ * moduleName may actually be just an URL.
1577
+ * Note that it **does not** call normalize on the moduleName,
1578
+ * it is assumed to have already been normalized. This is an
1579
+ * internal API, not a public one. Use toUrl for the public API.
1580
+ */
1581
+ nameToUrl: function (moduleName, ext, skipExt) {
1582
+ var paths, syms, i, parentModule, url,
1583
+ parentPath, bundleId,
1584
+ pkgMain = getOwn(config.pkgs, moduleName);
1585
+
1586
+ if (pkgMain) {
1587
+ moduleName = pkgMain;
1588
+ }
1589
+
1590
+ bundleId = getOwn(bundlesMap, moduleName);
1591
+
1592
+ if (bundleId) {
1593
+ return context.nameToUrl(bundleId, ext, skipExt);
1594
+ }
1595
+
1596
+ //If a colon is in the URL, it indicates a protocol is used and it is just
1597
+ //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
1598
+ //or ends with .js, then assume the user meant to use an url and not a module id.
1599
+ //The slash is important for protocol-less URLs as well as full paths.
1600
+ if (req.jsExtRegExp.test(moduleName)) {
1601
+ //Just a plain path, not module name lookup, so just return it.
1602
+ //Add extension if it is included. This is a bit wonky, only non-.js things pass
1603
+ //an extension, this method probably needs to be reworked.
1604
+ url = moduleName + (ext || '');
1605
+ } else {
1606
+ //A module that needs to be converted to a path.
1607
+ paths = config.paths;
1608
+
1609
+ syms = moduleName.split('/');
1610
+ //For each module name segment, see if there is a path
1611
+ //registered for it. Start with most specific name
1612
+ //and work up from it.
1613
+ for (i = syms.length; i > 0; i -= 1) {
1614
+ parentModule = syms.slice(0, i).join('/');
1615
+
1616
+ parentPath = getOwn(paths, parentModule);
1617
+ if (parentPath) {
1618
+ //If an array, it means there are a few choices,
1619
+ //Choose the one that is desired
1620
+ if (isArray(parentPath)) {
1621
+ parentPath = parentPath[0];
1622
+ }
1623
+ syms.splice(0, i, parentPath);
1624
+ break;
1625
+ }
1626
+ }
1627
+
1628
+ //Join the path parts together, then figure out if baseUrl is needed.
1629
+ url = syms.join('/');
1630
+ url += (ext || (/^data\:|\?/.test(url) || skipExt ? '' : '.js'));
1631
+ url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
1632
+ }
1633
+
1634
+ return config.urlArgs ? url +
1635
+ ((url.indexOf('?') === -1 ? '?' : '&') +
1636
+ config.urlArgs) : url;
1637
+ },
1638
+
1639
+ //Delegates to req.load. Broken out as a separate function to
1640
+ //allow overriding in the optimizer.
1641
+ load: function (id, url) {
1642
+ req.load(context, id, url);
1643
+ },
1644
+
1645
+ /**
1646
+ * Executes a module callback function. Broken out as a separate function
1647
+ * solely to allow the build system to sequence the files in the built
1648
+ * layer in the right sequence.
1649
+ *
1650
+ * @private
1651
+ */
1652
+ execCb: function (name, callback, args, exports) {
1653
+ return callback.apply(exports, args);
1654
+ },
1655
+
1656
+ /**
1657
+ * callback for script loads, used to check status of loading.
1658
+ *
1659
+ * @param {Event} evt the event from the browser for the script
1660
+ * that was loaded.
1661
+ */
1662
+ onScriptLoad: function (evt) {
1663
+ //Using currentTarget instead of target for Firefox 2.0's sake. Not
1664
+ //all old browsers will be supported, but this one was easy enough
1665
+ //to support and still makes sense.
1666
+ if (evt.type === 'load' ||
1667
+ (readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
1668
+ //Reset interactive script so a script node is not held onto for
1669
+ //to long.
1670
+ interactiveScript = null;
1671
+
1672
+ //Pull out the name of the module and the context.
1673
+ var data = getScriptData(evt);
1674
+ context.completeLoad(data.id);
1675
+ }
1676
+ },
1677
+
1678
+ /**
1679
+ * Callback for script errors.
1680
+ */
1681
+ onScriptError: function (evt) {
1682
+ var data = getScriptData(evt);
1683
+ if (!hasPathFallback(data.id)) {
1684
+ return onError(makeError('scripterror', 'Script error for: ' + data.id, evt, [data.id]));
1685
+ }
1686
+ }
1687
+ };
1688
+
1689
+ context.require = context.makeRequire();
1690
+ return context;
1691
+ }
1692
+
1693
+ /**
1694
+ * Main entry point.
1695
+ *
1696
+ * If the only argument to require is a string, then the module that
1697
+ * is represented by that string is fetched for the appropriate context.
1698
+ *
1699
+ * If the first argument is an array, then it will be treated as an array
1700
+ * of dependency string names to fetch. An optional function callback can
1701
+ * be specified to execute when all of those dependencies are available.
1702
+ *
1703
+ * Make a local req variable to help Caja compliance (it assumes things
1704
+ * on a require that are not standardized), and to give a short
1705
+ * name for minification/local scope use.
1706
+ */
1707
+ req = requirejs = function (deps, callback, errback, optional) {
1708
+
1709
+ //Find the right context, use default
1710
+ var context, config,
1711
+ contextName = defContextName;
1712
+
1713
+ // Determine if have config object in the call.
1714
+ if (!isArray(deps) && typeof deps !== 'string') {
1715
+ // deps is a config object
1716
+ config = deps;
1717
+ if (isArray(callback)) {
1718
+ // Adjust args if there are dependencies
1719
+ deps = callback;
1720
+ callback = errback;
1721
+ errback = optional;
1722
+ } else {
1723
+ deps = [];
1724
+ }
1725
+ }
1726
+
1727
+ if (config && config.context) {
1728
+ contextName = config.context;
1729
+ }
1730
+
1731
+ context = getOwn(contexts, contextName);
1732
+ if (!context) {
1733
+ context = contexts[contextName] = req.s.newContext(contextName);
1734
+ }
1735
+
1736
+ if (config) {
1737
+ context.configure(config);
1738
+ }
1739
+
1740
+ return context.require(deps, callback, errback);
1741
+ };
1742
+
1743
+ /**
1744
+ * Support require.config() to make it easier to cooperate with other
1745
+ * AMD loaders on globally agreed names.
1746
+ */
1747
+ req.config = function (config) {
1748
+ return req(config);
1749
+ };
1750
+
1751
+ /**
1752
+ * Execute something after the current tick
1753
+ * of the event loop. Override for other envs
1754
+ * that have a better solution than setTimeout.
1755
+ * @param {Function} fn function to execute later.
1756
+ */
1757
+ req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
1758
+ setTimeout(fn, 4);
1759
+ } : function (fn) {
1760
+ fn();
1761
+ };
1762
+
1763
+ /**
1764
+ * Export require as a global, but only if it does not already exist.
1765
+ */
1766
+ if (!require) {
1767
+ require = req;
1768
+ }
1769
+
1770
+ req.version = version;
1771
+
1772
+ //Used to filter out dependencies that are already paths.
1773
+ req.jsExtRegExp = /^\/|:|\?|\.js$/;
1774
+ req.isBrowser = isBrowser;
1775
+ s = req.s = {
1776
+ contexts: contexts,
1777
+ newContext: newContext
1778
+ };
1779
+
1780
+ //Create default context.
1781
+ req({});
1782
+
1783
+ //Exports some context-sensitive methods on global require.
1784
+ each([
1785
+ 'toUrl',
1786
+ 'undef',
1787
+ 'defined',
1788
+ 'specified'
1789
+ ], function (prop) {
1790
+ //Reference from contexts instead of early binding to default context,
1791
+ //so that during builds, the latest instance of the default context
1792
+ //with its config gets used.
1793
+ req[prop] = function () {
1794
+ var ctx = contexts[defContextName];
1795
+ return ctx.require[prop].apply(ctx, arguments);
1796
+ };
1797
+ });
1798
+
1799
+ if (isBrowser) {
1800
+ head = s.head = document.getElementsByTagName('head')[0];
1801
+ //If BASE tag is in play, using appendChild is a problem for IE6.
1802
+ //When that browser dies, this can be removed. Details in this jQuery bug:
1803
+ //http://dev.jquery.com/ticket/2709
1804
+ baseElement = document.getElementsByTagName('base')[0];
1805
+ if (baseElement) {
1806
+ head = s.head = baseElement.parentNode;
1807
+ }
1808
+ }
1809
+
1810
+ /**
1811
+ * Any errors that require explicitly generates will be passed to this
1812
+ * function. Intercept/override it if you want custom error handling.
1813
+ * @param {Error} err the error object.
1814
+ */
1815
+ req.onError = defaultOnError;
1816
+
1817
+ /**
1818
+ * Creates the node for the load command. Only used in browser envs.
1819
+ */
1820
+ req.createNode = function (config, moduleName, url) {
1821
+ var node = config.xhtml ?
1822
+ document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
1823
+ document.createElement('script');
1824
+ node.type = config.scriptType || 'text/javascript';
1825
+ node.charset = 'utf-8';
1826
+ node.async = true;
1827
+ return node;
1828
+ };
1829
+
1830
+ /**
1831
+ * Does the request to load a module for the browser case.
1832
+ * Make this a separate function to allow other environments
1833
+ * to override it.
1834
+ *
1835
+ * @param {Object} context the require context to find state.
1836
+ * @param {String} moduleName the name of the module.
1837
+ * @param {Object} url the URL to the module.
1838
+ */
1839
+ req.load = function (context, moduleName, url) {
1840
+ var config = (context && context.config) || {},
1841
+ node;
1842
+ if (isBrowser) {
1843
+ //In the browser so use a script tag
1844
+ node = req.createNode(config, moduleName, url);
1845
+
1846
+ node.setAttribute('data-requirecontext', context.contextName);
1847
+ node.setAttribute('data-requiremodule', moduleName);
1848
+
1849
+ //Set up load listener. Test attachEvent first because IE9 has
1850
+ //a subtle issue in its addEventListener and script onload firings
1851
+ //that do not match the behavior of all other browsers with
1852
+ //addEventListener support, which fire the onload event for a
1853
+ //script right after the script execution. See:
1854
+ //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
1855
+ //UNFORTUNATELY Opera implements attachEvent but does not follow the script
1856
+ //script execution mode.
1857
+ if (node.attachEvent &&
1858
+ //Check if node.attachEvent is artificially added by custom script or
1859
+ //natively supported by browser
1860
+ //read https://github.com/jrburke/requirejs/issues/187
1861
+ //if we can NOT find [native code] then it must NOT natively supported.
1862
+ //in IE8, node.attachEvent does not have toString()
1863
+ //Note the test for "[native code" with no closing brace, see:
1864
+ //https://github.com/jrburke/requirejs/issues/273
1865
+ !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) && !isOpera) {
1866
+ //Probably IE. IE (at least 6-8) do not fire
1867
+ //script onload right after executing the script, so
1868
+ //we cannot tie the anonymous define call to a name.
1869
+ //However, IE reports the script as being in 'interactive'
1870
+ //readyState at the time of the define call.
1871
+ useInteractive = true;
1872
+
1873
+ node.attachEvent('onreadystatechange', context.onScriptLoad);
1874
+ //It would be great to add an error handler here to catch
1875
+ //404s in IE9+. However, onreadystatechange will fire before
1876
+ //the error handler, so that does not help. If addEventListener
1877
+ //is used, then IE will fire error before load, but we cannot
1878
+ //use that pathway given the connect.microsoft.com issue
1879
+ //mentioned above about not doing the 'script execute,
1880
+ //then fire the script load event listener before execute
1881
+ //next script' that other browsers do.
1882
+ //Best hope: IE10 fixes the issues,
1883
+ //and then destroys all installs of IE 6-9.
1884
+ //node.attachEvent('onerror', context.onScriptError);
1885
+ } else {
1886
+ node.addEventListener('load', context.onScriptLoad, false);
1887
+ node.addEventListener('error', context.onScriptError, false);
1888
+ }
1889
+ node.src = url;
1890
+
1891
+ //For some cache cases in IE 6-8, the script executes before the end
1892
+ //of the appendChild execution, so to tie an anonymous define
1893
+ //call to the module name (which is stored on the node), hold on
1894
+ //to a reference to this node, but clear after the DOM insertion.
1895
+ currentlyAddingScript = node;
1896
+ if (baseElement) {
1897
+ head.insertBefore(node, baseElement);
1898
+ } else {
1899
+ head.appendChild(node);
1900
+ }
1901
+ currentlyAddingScript = null;
1902
+
1903
+ return node;
1904
+ } else if (isWebWorker) {
1905
+ try {
1906
+ //In a web worker, use importScripts. This is not a very
1907
+ //efficient use of importScripts, importScripts will block until
1908
+ //its script is downloaded and evaluated. However, if web workers
1909
+ //are in play, the expectation that a build has been done so that
1910
+ //only one script needs to be loaded anyway. This may need to be
1911
+ //reevaluated if other use cases become common.
1912
+ importScripts(url);
1913
+
1914
+ //Account for anonymous modules
1915
+ context.completeLoad(moduleName);
1916
+ } catch (e) {
1917
+ context.onError(makeError('importscripts',
1918
+ 'importScripts failed for ' +
1919
+ moduleName + ' at ' + url,
1920
+ e,
1921
+ [moduleName]));
1922
+ }
1923
+ }
1924
+ };
1925
+
1926
+ function getInteractiveScript() {
1927
+ if (interactiveScript && interactiveScript.readyState === 'interactive') {
1928
+ return interactiveScript;
1929
+ }
1930
+
1931
+ eachReverse(scripts(), function (script) {
1932
+ if (script.readyState === 'interactive') {
1933
+ return (interactiveScript = script);
1934
+ }
1935
+ });
1936
+ return interactiveScript;
1937
+ }
1938
+
1939
+ //Look for a data-main script attribute, which could also adjust the baseUrl.
1940
+ if (isBrowser && !cfg.skipDataMain) {
1941
+ //Figure out baseUrl. Get it from the script tag with require.js in it.
1942
+ eachReverse(scripts(), function (script) {
1943
+ //Set the 'head' where we can append children by
1944
+ //using the script's parent.
1945
+ if (!head) {
1946
+ head = script.parentNode;
1947
+ }
1948
+
1949
+ //Look for a data-main attribute to set main script for the page
1950
+ //to load. If it is there, the path to data main becomes the
1951
+ //baseUrl, if it is not already set.
1952
+ dataMain = script.getAttribute('data-main');
1953
+ if (dataMain) {
1954
+ //Preserve dataMain in case it is a path (i.e. contains '?')
1955
+ mainScript = dataMain;
1956
+
1957
+ //Set final baseUrl if there is not already an explicit one.
1958
+ if (!cfg.baseUrl) {
1959
+ //Pull off the directory of data-main for use as the
1960
+ //baseUrl.
1961
+ src = mainScript.split('/');
1962
+ mainScript = src.pop();
1963
+ subPath = src.length ? src.join('/') + '/' : './';
1964
+
1965
+ cfg.baseUrl = subPath;
1966
+ }
1967
+
1968
+ //Strip off any trailing .js since mainScript is now
1969
+ //like a module name.
1970
+ mainScript = mainScript.replace(jsSuffixRegExp, '');
1971
+
1972
+ //If mainScript is still a path, fall back to dataMain
1973
+ if (req.jsExtRegExp.test(mainScript)) {
1974
+ mainScript = dataMain;
1975
+ }
1976
+
1977
+ //Put the data-main script in the files to load.
1978
+ cfg.deps = cfg.deps ? cfg.deps.concat(mainScript) : [mainScript];
1979
+
1980
+ return true;
1981
+ }
1982
+ });
1983
+ }
1984
+
1985
+ /**
1986
+ * The function that handles definitions of modules. Differs from
1987
+ * require() in that a string for the module should be the first argument,
1988
+ * and the function to execute after dependencies are loaded should
1989
+ * return a value to define the module corresponding to the first argument's
1990
+ * name.
1991
+ */
1992
+ define = function (name, deps, callback) {
1993
+ var node, context;
1994
+
1995
+ //Allow for anonymous modules
1996
+ if (typeof name !== 'string') {
1997
+ //Adjust args appropriately
1998
+ callback = deps;
1999
+ deps = name;
2000
+ name = null;
2001
+ }
2002
+
2003
+ //This module may not have dependencies
2004
+ if (!isArray(deps)) {
2005
+ callback = deps;
2006
+ deps = null;
2007
+ }
2008
+
2009
+ //If no name, and callback is a function, then figure out if it a
2010
+ //CommonJS thing with dependencies.
2011
+ if (!deps && isFunction(callback)) {
2012
+ deps = [];
2013
+ //Remove comments from the callback string,
2014
+ //look for require calls, and pull them into the dependencies,
2015
+ //but only if there are function args.
2016
+ if (callback.length) {
2017
+ callback
2018
+ .toString()
2019
+ .replace(commentRegExp, '')
2020
+ .replace(cjsRequireRegExp, function (match, dep) {
2021
+ deps.push(dep);
2022
+ });
2023
+
2024
+ //May be a CommonJS thing even without require calls, but still
2025
+ //could use exports, and module. Avoid doing exports and module
2026
+ //work though if it just needs require.
2027
+ //REQUIRES the function to expect the CommonJS variables in the
2028
+ //order listed below.
2029
+ deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);
2030
+ }
2031
+ }
2032
+
2033
+ //If in IE 6-8 and hit an anonymous define() call, do the interactive
2034
+ //work.
2035
+ if (useInteractive) {
2036
+ node = currentlyAddingScript || getInteractiveScript();
2037
+ if (node) {
2038
+ if (!name) {
2039
+ name = node.getAttribute('data-requiremodule');
2040
+ }
2041
+ context = contexts[node.getAttribute('data-requirecontext')];
2042
+ }
2043
+ }
2044
+
2045
+ //Always save off evaluating the def call until the script onload handler.
2046
+ //This allows multiple modules to be in a file without prematurely
2047
+ //tracing dependencies, and allows for anonymous module support,
2048
+ //where the module name is not known until the script onload event
2049
+ //occurs. If no context, use the global queue, and get it processed
2050
+ //in the onscript load callback.
2051
+ (context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
2052
+ };
2053
+
2054
+ define.amd = {
2055
+ jQuery: true
2056
+ };
2057
+
2058
+
2059
+ /**
2060
+ * Executes the text. Normally just uses eval, but can be modified
2061
+ * to use a better, environment-specific call. Only used for transpiling
2062
+ * loader plugins, not for plain JS modules.
2063
+ * @param {String} text the text to execute/evaluate.
2064
+ */
2065
+ req.exec = function (text) {
2066
+ /*jslint evil: true */
2067
+ return eval(text);
2068
+ };
2069
+
2070
+ //Set up with config info.
2071
+ req(cfg);
2072
+ }(this));