UNPKG

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