annotate node_modules/requirejs/require.js @ 101:52e44ee1c791 tip master

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