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