Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

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