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