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