Hubiquitus Android  0.3
Android client for hubiquitus protocol
require.js
Go to the documentation of this file.
00001 
00006 /*jslint strict: false, plusplus: false, sub: true */
00007 /*global window, navigator, document, importScripts, jQuery, setTimeout, opera */
00008 
00009 var requirejs, require, define;
00010 (function () {
00011     //Change this version number for each release.
00012     var version = "1.0.5",
00013         commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
00014         cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g,
00015         currDirRegExp = /^\.\//,
00016         jsSuffixRegExp = /\.js$/,
00017         ostring = Object.prototype.toString,
00018         ap = Array.prototype,
00019         aps = ap.slice,
00020         apsp = ap.splice,
00021         isBrowser = !!(typeof window !== "undefined" && navigator && document),
00022         isWebWorker = !isBrowser && typeof importScripts !== "undefined",
00023         //PS3 indicates loaded and complete, but need to wait for complete
00024         //specifically. Sequence is "loading", "loaded", execution,
00025         // then "complete". The UA check is unfortunate, but not sure how
00026         //to feature test w/o causing perf issues.
00027         readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
00028                       /^complete$/ : /^(complete|loaded)$/,
00029         defContextName = "_",
00030         //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
00031         isOpera = typeof opera !== "undefined" && opera.toString() === "[object Opera]",
00032         empty = {},
00033         contexts = {},
00034         globalDefQueue = [],
00035         interactiveScript = null,
00036         checkLoadedDepth = 0,
00037         useInteractive = false,
00038         reservedDependencies = {
00039             require: true,
00040             module: true,
00041             exports: true
00042         },
00043         req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script,
00044         src, subPath, mainScript, dataMain, globalI, ctx, jQueryCheck, checkLoadedTimeoutId;
00045 
00046     function isFunction(it) {
00047         return ostring.call(it) === "[object Function]";
00048     }
00049 
00050     function isArray(it) {
00051         return ostring.call(it) === "[object Array]";
00052     }
00053 
00061     function mixin(target, source, force) {
00062         for (var prop in source) {
00063             if (!(prop in empty) && (!(prop in target) || force)) {
00064                 target[prop] = source[prop];
00065             }
00066         }
00067         return req;
00068     }
00069 
00078     function makeError(id, msg, err) {
00079         var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
00080         if (err) {
00081             e.originalError = err;
00082         }
00083         return e;
00084     }
00085 
00092     function configurePackageDir(pkgs, currentPackages, dir) {
00093         var i, location, pkgObj;
00094 
00095         for (i = 0; (pkgObj = currentPackages[i]); i++) {
00096             pkgObj = typeof pkgObj === "string" ? { name: pkgObj } : pkgObj;
00097             location = pkgObj.location;
00098 
00099             //Add dir to the path, but avoid paths that start with a slash
00100             //or have a colon (indicates a protocol)
00101             if (dir && (!location || (location.indexOf("/") !== 0 && location.indexOf(":") === -1))) {
00102                 location = dir + "/" + (location || pkgObj.name);
00103             }
00104 
00105             //Create a brand new object on pkgs, since currentPackages can
00106             //be passed in again, and config.pkgs is the internal transformed
00107             //state for all package configs.
00108             pkgs[pkgObj.name] = {
00109                 name: pkgObj.name,
00110                 location: location || pkgObj.name,
00111                 //Remove leading dot in main, so main paths are normalized,
00112                 //and remove any trailing .js, since different package
00113                 //envs have different conventions: some use a module name,
00114                 //some use a file name.
00115                 main: (pkgObj.main || "main")
00116                       .replace(currDirRegExp, '')
00117                       .replace(jsSuffixRegExp, '')
00118             };
00119         }
00120     }
00121 
00128     function jQueryHoldReady($, shouldHold) {
00129         if ($.holdReady) {
00130             $.holdReady(shouldHold);
00131         } else if (shouldHold) {
00132             $.readyWait += 1;
00133         } else {
00134             $.ready(true);
00135         }
00136     }
00137 
00138     if (typeof define !== "undefined") {
00139         //If a define is already in play via another AMD loader,
00140         //do not overwrite.
00141         return;
00142     }
00143 
00144     if (typeof requirejs !== "undefined") {
00145         if (isFunction(requirejs)) {
00146             //Do not overwrite and existing requirejs instance.
00147             return;
00148         } else {
00149             cfg = requirejs;
00150             requirejs = undefined;
00151         }
00152     }
00153 
00154     //Allow for a require config object
00155     if (typeof require !== "undefined" && !isFunction(require)) {
00156         //assume it is a config object.
00157         cfg = require;
00158         require = undefined;
00159     }
00160 
00171     function newContext(contextName) {
00172         var context, resume,
00173             config = {
00174                 waitSeconds: 7,
00175                 baseUrl: "./",
00176                 paths: {},
00177                 pkgs: {},
00178                 catchError: {}
00179             },
00180             defQueue = [],
00181             specified = {
00182                 "require": true,
00183                 "exports": true,
00184                 "module": true
00185             },
00186             urlMap = {},
00187             defined = {},
00188             loaded = {},
00189             waiting = {},
00190             waitAry = [],
00191             urlFetched = {},
00192             managerCounter = 0,
00193             managerCallbacks = {},
00194             plugins = {},
00195             //Used to indicate which modules in a build scenario
00196             //need to be full executed.
00197             needFullExec = {},
00198             fullExec = {},
00199             resumeDepth = 0;
00200 
00210         function trimDots(ary) {
00211             var i, part;
00212             for (i = 0; (part = ary[i]); i++) {
00213                 if (part === ".") {
00214                     ary.splice(i, 1);
00215                     i -= 1;
00216                 } else if (part === "..") {
00217                     if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
00218                         //End of the line. Keep at least one non-dot
00219                         //path segment at the front so it can be mapped
00220                         //correctly to disk. Otherwise, there is likely
00221                         //no path mapping for a path starting with '..'.
00222                         //This can still fail, but catches the most reasonable
00223                         //uses of ..
00224                         break;
00225                     } else if (i > 0) {
00226                         ary.splice(i - 1, 2);
00227                         i -= 2;
00228                     }
00229                 }
00230             }
00231         }
00232 
00241         function normalize(name, baseName) {
00242             var pkgName, pkgConfig;
00243 
00244             //Adjust any relative paths.
00245             if (name && name.charAt(0) === ".") {
00246                 //If have a base name, try to normalize against it,
00247                 //otherwise, assume it is a top-level require that will
00248                 //be relative to baseUrl in the end.
00249                 if (baseName) {
00250                     if (config.pkgs[baseName]) {
00251                         //If the baseName is a package name, then just treat it as one
00252                         //name to concat the name with.
00253                         baseName = [baseName];
00254                     } else {
00255                         //Convert baseName to array, and lop off the last part,
00256                         //so that . matches that "directory" and not name of the baseName's
00257                         //module. For instance, baseName of "one/two/three", maps to
00258                         //"one/two/three.js", but we want the directory, "one/two" for
00259                         //this normalization.
00260                         baseName = baseName.split("/");
00261                         baseName = baseName.slice(0, baseName.length - 1);
00262                     }
00263 
00264                     name = baseName.concat(name.split("/"));
00265                     trimDots(name);
00266 
00267                     //Some use of packages may use a . path to reference the
00268                     //"main" module name, so normalize for that.
00269                     pkgConfig = config.pkgs[(pkgName = name[0])];
00270                     name = name.join("/");
00271                     if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
00272                         name = pkgName;
00273                     }
00274                 } else if (name.indexOf("./") === 0) {
00275                     // No baseName, so this is ID is resolved relative
00276                     // to baseUrl, pull off the leading dot.
00277                     name = name.substring(2);
00278                 }
00279             }
00280             return name;
00281         }
00282 
00294         function makeModuleMap(name, parentModuleMap) {
00295             var index = name ? name.indexOf("!") : -1,
00296                 prefix = null,
00297                 parentName = parentModuleMap ? parentModuleMap.name : null,
00298                 originalName = name,
00299                 normalizedName, url, pluginModule;
00300 
00301             if (index !== -1) {
00302                 prefix = name.substring(0, index);
00303                 name = name.substring(index + 1, name.length);
00304             }
00305 
00306             if (prefix) {
00307                 prefix = normalize(prefix, parentName);
00308             }
00309 
00310             //Account for relative paths if there is a base name.
00311             if (name) {
00312                 if (prefix) {
00313                     pluginModule = defined[prefix];
00314                     if (pluginModule && pluginModule.normalize) {
00315                         //Plugin is loaded, use its normalize method.
00316                         normalizedName = pluginModule.normalize(name, function (name) {
00317                             return normalize(name, parentName);
00318                         });
00319                     } else {
00320                         normalizedName = normalize(name, parentName);
00321                     }
00322                 } else {
00323                     //A regular module.
00324                     normalizedName = normalize(name, parentName);
00325 
00326                     url = urlMap[normalizedName];
00327                     if (!url) {
00328                         //Calculate url for the module, if it has a name.
00329                         //Use name here since nameToUrl also calls normalize,
00330                         //and for relative names that are outside the baseUrl
00331                         //this causes havoc. Was thinking of just removing
00332                         //parentModuleMap to avoid extra normalization, but
00333                         //normalize() still does a dot removal because of
00334                         //issue #142, so just pass in name here and redo
00335                         //the normalization. Paths outside baseUrl are just
00336                         //messy to support.
00337                         url = context.nameToUrl(name, null, parentModuleMap);
00338 
00339                         //Store the URL mapping for later.
00340                         urlMap[normalizedName] = url;
00341                     }
00342                 }
00343             }
00344 
00345             return {
00346                 prefix: prefix,
00347                 name: normalizedName,
00348                 parentMap: parentModuleMap,
00349                 url: url,
00350                 originalName: originalName,
00351                 fullName: prefix ? prefix + "!" + (normalizedName || '') : normalizedName
00352             };
00353         }
00354 
00358         function isPriorityDone() {
00359             var priorityDone = true,
00360                 priorityWait = config.priorityWait,
00361                 priorityName, i;
00362             if (priorityWait) {
00363                 for (i = 0; (priorityName = priorityWait[i]); i++) {
00364                     if (!loaded[priorityName]) {
00365                         priorityDone = false;
00366                         break;
00367                     }
00368                 }
00369                 if (priorityDone) {
00370                     delete config.priorityWait;
00371                 }
00372             }
00373             return priorityDone;
00374         }
00375 
00376         function makeContextModuleFunc(func, relModuleMap, enableBuildCallback) {
00377             return function () {
00378                 //A version of a require function that passes a moduleName
00379                 //value for items that may need to
00380                 //look up paths relative to the moduleName
00381                 var args = aps.call(arguments, 0), lastArg;
00382                 if (enableBuildCallback &&
00383                     isFunction((lastArg = args[args.length - 1]))) {
00384                     lastArg.__requireJsBuild = true;
00385                 }
00386                 args.push(relModuleMap);
00387                 return func.apply(null, args);
00388             };
00389         }
00390 
00397         function makeRequire(relModuleMap, enableBuildCallback, altRequire) {
00398             var modRequire = makeContextModuleFunc(altRequire || context.require, relModuleMap, enableBuildCallback);
00399 
00400             mixin(modRequire, {
00401                 nameToUrl: makeContextModuleFunc(context.nameToUrl, relModuleMap),
00402                 toUrl: makeContextModuleFunc(context.toUrl, relModuleMap),
00403                 defined: makeContextModuleFunc(context.requireDefined, relModuleMap),
00404                 specified: makeContextModuleFunc(context.requireSpecified, relModuleMap),
00405                 isBrowser: req.isBrowser
00406             });
00407             return modRequire;
00408         }
00409 
00410         /*
00411          * Queues a dependency for checking after the loader is out of a
00412          * "paused" state, for example while a script file is being loaded
00413          * in the browser, where it may have many modules defined in it.
00414          */
00415         function queueDependency(manager) {
00416             context.paused.push(manager);
00417         }
00418 
00419         function execManager(manager) {
00420             var i, ret, err, errFile, errModuleTree,
00421                 cb = manager.callback,
00422                 map = manager.map,
00423                 fullName = map.fullName,
00424                 args = manager.deps,
00425                 listeners = manager.listeners,
00426                 cjsModule;
00427 
00428             //Call the callback to define the module, if necessary.
00429             if (cb && isFunction(cb)) {
00430                 if (config.catchError.define) {
00431                     try {
00432                         ret = req.execCb(fullName, manager.callback, args, defined[fullName]);
00433                     } catch (e) {
00434                         err = e;
00435                     }
00436                 } else {
00437                     ret = req.execCb(fullName, manager.callback, args, defined[fullName]);
00438                 }
00439 
00440                 if (fullName) {
00441                     //If setting exports via "module" is in play,
00442                     //favor that over return value and exports. After that,
00443                     //favor a non-undefined return value over exports use.
00444                     cjsModule = manager.cjsModule;
00445                     if (cjsModule &&
00446                         cjsModule.exports !== undefined &&
00447                         //Make sure it is not already the exports value
00448                         cjsModule.exports !== defined[fullName]) {
00449                         ret = defined[fullName] = manager.cjsModule.exports;
00450                     } else if (ret === undefined && manager.usingExports) {
00451                         //exports already set the defined value.
00452                         ret = defined[fullName];
00453                     } else {
00454                         //Use the return value from the function.
00455                         defined[fullName] = ret;
00456                         //If this module needed full execution in a build
00457                         //environment, mark that now.
00458                         if (needFullExec[fullName]) {
00459                             fullExec[fullName] = true;
00460                         }
00461                     }
00462                 }
00463             } else if (fullName) {
00464                 //May just be an object definition for the module. Only
00465                 //worry about defining if have a module name.
00466                 ret = defined[fullName] = cb;
00467 
00468                 //If this module needed full execution in a build
00469                 //environment, mark that now.
00470                 if (needFullExec[fullName]) {
00471                     fullExec[fullName] = true;
00472                 }
00473             }
00474 
00475             //Clean up waiting. Do this before error calls, and before
00476             //calling back listeners, so that bookkeeping is correct
00477             //in the event of an error and error is reported in correct order,
00478             //since the listeners will likely have errors if the
00479             //onError function does not throw.
00480             if (waiting[manager.id]) {
00481                 delete waiting[manager.id];
00482                 manager.isDone = true;
00483                 context.waitCount -= 1;
00484                 if (context.waitCount === 0) {
00485                     //Clear the wait array used for cycles.
00486                     waitAry = [];
00487                 }
00488             }
00489 
00490             //Do not need to track manager callback now that it is defined.
00491             delete managerCallbacks[fullName];
00492 
00493             //Allow instrumentation like the optimizer to know the order
00494             //of modules executed and their dependencies.
00495             if (req.onResourceLoad && !manager.placeholder) {
00496                 req.onResourceLoad(context, map, manager.depArray);
00497             }
00498 
00499             if (err) {
00500                 errFile = (fullName ? makeModuleMap(fullName).url : '') ||
00501                            err.fileName || err.sourceURL;
00502                 errModuleTree = err.moduleTree;
00503                 err = makeError('defineerror', 'Error evaluating ' +
00504                                 'module "' + fullName + '" at location "' +
00505                                 errFile + '":\n' +
00506                                 err + '\nfileName:' + errFile +
00507                                 '\nlineNumber: ' + (err.lineNumber || err.line), err);
00508                 err.moduleName = fullName;
00509                 err.moduleTree = errModuleTree;
00510                 return req.onError(err);
00511             }
00512 
00513             //Let listeners know of this manager's value.
00514             for (i = 0; (cb = listeners[i]); i++) {
00515                 cb(ret);
00516             }
00517 
00518             return undefined;
00519         }
00520 
00526         function makeArgCallback(manager, i) {
00527             return function (value) {
00528                 //Only do the work if it has not been done
00529                 //already for a dependency. Cycle breaking
00530                 //logic in forceExec could mean this function
00531                 //is called more than once for a given dependency.
00532                 if (!manager.depDone[i]) {
00533                     manager.depDone[i] = true;
00534                     manager.deps[i] = value;
00535                     manager.depCount -= 1;
00536                     if (!manager.depCount) {
00537                         //All done, execute!
00538                         execManager(manager);
00539                     }
00540                 }
00541             };
00542         }
00543 
00544         function callPlugin(pluginName, depManager) {
00545             var map = depManager.map,
00546                 fullName = map.fullName,
00547                 name = map.name,
00548                 plugin = plugins[pluginName] ||
00549                         (plugins[pluginName] = defined[pluginName]),
00550                 load;
00551 
00552             //No need to continue if the manager is already
00553             //in the process of loading.
00554             if (depManager.loading) {
00555                 return;
00556             }
00557             depManager.loading = true;
00558 
00559             load = function (ret) {
00560                 depManager.callback = function () {
00561                     return ret;
00562                 };
00563                 execManager(depManager);
00564 
00565                 loaded[depManager.id] = true;
00566 
00567                 //The loading of this plugin
00568                 //might have placed other things
00569                 //in the paused queue. In particular,
00570                 //a loader plugin that depends on
00571                 //a different plugin loaded resource.
00572                 resume();
00573             };
00574 
00575             //Allow plugins to load other code without having to know the
00576             //context or how to "complete" the load.
00577             load.fromText = function (moduleName, text) {
00578                 /*jslint evil: true */
00579                 var hasInteractive = useInteractive;
00580 
00581                 //Indicate a the module is in process of loading.
00582                 loaded[moduleName] = false;
00583                 context.scriptCount += 1;
00584 
00585                 //Indicate this is not a "real" module, so do not track it
00586                 //for builds, it does not map to a real file.
00587                 context.fake[moduleName] = true;
00588 
00589                 //Turn off interactive script matching for IE for any define
00590                 //calls in the text, then turn it back on at the end.
00591                 if (hasInteractive) {
00592                     useInteractive = false;
00593                 }
00594 
00595                 req.exec(text);
00596 
00597                 if (hasInteractive) {
00598                     useInteractive = true;
00599                 }
00600 
00601                 //Support anonymous modules.
00602                 context.completeLoad(moduleName);
00603             };
00604 
00605             //No need to continue if the plugin value has already been
00606             //defined by a build.
00607             if (fullName in defined) {
00608                 load(defined[fullName]);
00609             } else {
00610                 //Use parentName here since the plugin's name is not reliable,
00611                 //could be some weird string with no path that actually wants to
00612                 //reference the parentName's path.
00613                 plugin.load(name, makeRequire(map.parentMap, true, function (deps, cb) {
00614                     var moduleDeps = [],
00615                         i, dep, depMap;
00616                     //Convert deps to full names and hold on to them
00617                     //for reference later, when figuring out if they
00618                     //are blocked by a circular dependency.
00619                     for (i = 0; (dep = deps[i]); i++) {
00620                         depMap = makeModuleMap(dep, map.parentMap);
00621                         deps[i] = depMap.fullName;
00622                         if (!depMap.prefix) {
00623                             moduleDeps.push(deps[i]);
00624                         }
00625                     }
00626                     depManager.moduleDeps = (depManager.moduleDeps || []).concat(moduleDeps);
00627                     return context.require(deps, cb);
00628                 }), load, config);
00629             }
00630         }
00631 
00636         function addWait(manager) {
00637             if (!waiting[manager.id]) {
00638                 waiting[manager.id] = manager;
00639                 waitAry.push(manager);
00640                 context.waitCount += 1;
00641             }
00642         }
00643 
00648         function managerAdd(cb) {
00649             this.listeners.push(cb);
00650         }
00651 
00652         function getManager(map, shouldQueue) {
00653             var fullName = map.fullName,
00654                 prefix = map.prefix,
00655                 plugin = prefix ? plugins[prefix] ||
00656                                 (plugins[prefix] = defined[prefix]) : null,
00657                 manager, created, pluginManager, prefixMap;
00658 
00659             if (fullName) {
00660                 manager = managerCallbacks[fullName];
00661             }
00662 
00663             if (!manager) {
00664                 created = true;
00665                 manager = {
00666                     //ID is just the full name, but if it is a plugin resource
00667                     //for a plugin that has not been loaded,
00668                     //then add an ID counter to it.
00669                     id: (prefix && !plugin ?
00670                         (managerCounter++) + '__p@:' : '') +
00671                         (fullName || '__r@' + (managerCounter++)),
00672                     map: map,
00673                     depCount: 0,
00674                     depDone: [],
00675                     depCallbacks: [],
00676                     deps: [],
00677                     listeners: [],
00678                     add: managerAdd
00679                 };
00680 
00681                 specified[manager.id] = true;
00682 
00683                 //Only track the manager/reuse it if this is a non-plugin
00684                 //resource. Also only track plugin resources once
00685                 //the plugin has been loaded, and so the fullName is the
00686                 //true normalized value.
00687                 if (fullName && (!prefix || plugins[prefix])) {
00688                     managerCallbacks[fullName] = manager;
00689                 }
00690             }
00691 
00692             //If there is a plugin needed, but it is not loaded,
00693             //first load the plugin, then continue on.
00694             if (prefix && !plugin) {
00695                 prefixMap = makeModuleMap(prefix);
00696 
00697                 //Clear out defined and urlFetched if the plugin was previously
00698                 //loaded/defined, but not as full module (as in a build
00699                 //situation). However, only do this work if the plugin is in
00700                 //defined but does not have a module export value.
00701                 if (prefix in defined && !defined[prefix]) {
00702                     delete defined[prefix];
00703                     delete urlFetched[prefixMap.url];
00704                 }
00705 
00706                 pluginManager = getManager(prefixMap, true);
00707                 pluginManager.add(function (plugin) {
00708                     //Create a new manager for the normalized
00709                     //resource ID and have it call this manager when
00710                     //done.
00711                     var newMap = makeModuleMap(map.originalName, map.parentMap),
00712                         normalizedManager = getManager(newMap, true);
00713 
00714                     //Indicate this manager is a placeholder for the real,
00715                     //normalized thing. Important for when trying to map
00716                     //modules and dependencies, for instance, in a build.
00717                     manager.placeholder = true;
00718 
00719                     normalizedManager.add(function (resource) {
00720                         manager.callback = function () {
00721                             return resource;
00722                         };
00723                         execManager(manager);
00724                     });
00725                 });
00726             } else if (created && shouldQueue) {
00727                 //Indicate the resource is not loaded yet if it is to be
00728                 //queued.
00729                 loaded[manager.id] = false;
00730                 queueDependency(manager);
00731                 addWait(manager);
00732             }
00733 
00734             return manager;
00735         }
00736 
00737         function main(inName, depArray, callback, relModuleMap) {
00738             var moduleMap = makeModuleMap(inName, relModuleMap),
00739                 name = moduleMap.name,
00740                 fullName = moduleMap.fullName,
00741                 manager = getManager(moduleMap),
00742                 id = manager.id,
00743                 deps = manager.deps,
00744                 i, depArg, depName, depPrefix, cjsMod;
00745 
00746             if (fullName) {
00747                 //If module already defined for context, or already loaded,
00748                 //then leave. Also leave if jQuery is registering but it does
00749                 //not match the desired version number in the config.
00750                 if (fullName in defined || loaded[id] === true ||
00751                     (fullName === "jquery" && config.jQuery &&
00752                      config.jQuery !== callback().fn.jquery)) {
00753                     return;
00754                 }
00755 
00756                 //Set specified/loaded here for modules that are also loaded
00757                 //as part of a layer, where onScriptLoad is not fired
00758                 //for those cases. Do this after the inline define and
00759                 //dependency tracing is done.
00760                 specified[id] = true;
00761                 loaded[id] = true;
00762 
00763                 //If module is jQuery set up delaying its dom ready listeners.
00764                 if (fullName === "jquery" && callback) {
00765                     jQueryCheck(callback());
00766                 }
00767             }
00768 
00769             //Attach real depArray and callback to the manager. Do this
00770             //only if the module has not been defined already, so do this after
00771             //the fullName checks above. IE can call main() more than once
00772             //for a module.
00773             manager.depArray = depArray;
00774             manager.callback = callback;
00775 
00776             //Add the dependencies to the deps field, and register for callbacks
00777             //on the dependencies.
00778             for (i = 0; i < depArray.length; i++) {
00779                 depArg = depArray[i];
00780                 //There could be cases like in IE, where a trailing comma will
00781                 //introduce a null dependency, so only treat a real dependency
00782                 //value as a dependency.
00783                 if (depArg) {
00784                     //Split the dependency name into plugin and name parts
00785                     depArg = makeModuleMap(depArg, (name ? moduleMap : relModuleMap));
00786                     depName = depArg.fullName;
00787                     depPrefix = depArg.prefix;
00788 
00789                     //Fix the name in depArray to be just the name, since
00790                     //that is how it will be called back later.
00791                     depArray[i] = depName;
00792 
00793                     //Fast path CommonJS standard dependencies.
00794                     if (depName === "require") {
00795                         deps[i] = makeRequire(moduleMap);
00796                     } else if (depName === "exports") {
00797                         //CommonJS module spec 1.1
00798                         deps[i] = defined[fullName] = {};
00799                         manager.usingExports = true;
00800                     } else if (depName === "module") {
00801                         //CommonJS module spec 1.1
00802                         manager.cjsModule = cjsMod = deps[i] = {
00803                             id: name,
00804                             uri: name ? context.nameToUrl(name, null, relModuleMap) : undefined,
00805                             exports: defined[fullName]
00806                         };
00807                     } else if (depName in defined && !(depName in waiting) &&
00808                                (!(fullName in needFullExec) ||
00809                                 (fullName in needFullExec && fullExec[depName]))) {
00810                         //Module already defined, and not in a build situation
00811                         //where the module is a something that needs full
00812                         //execution and this dependency has not been fully
00813                         //executed. See r.js's requirePatch.js for more info
00814                         //on fullExec.
00815                         deps[i] = defined[depName];
00816                     } else {
00817                         //Mark this dependency as needing full exec if
00818                         //the current module needs full exec.
00819                         if (fullName in needFullExec) {
00820                             needFullExec[depName] = true;
00821                             //Reset state so fully executed code will get
00822                             //picked up correctly.
00823                             delete defined[depName];
00824                             urlFetched[depArg.url] = false;
00825                         }
00826 
00827                         //Either a resource that is not loaded yet, or a plugin
00828                         //resource for either a plugin that has not
00829                         //loaded yet.
00830                         manager.depCount += 1;
00831                         manager.depCallbacks[i] = makeArgCallback(manager, i);
00832                         getManager(depArg, true).add(manager.depCallbacks[i]);
00833                     }
00834                 }
00835             }
00836 
00837             //Do not bother tracking the manager if it is all done.
00838             if (!manager.depCount) {
00839                 //All done, execute!
00840                 execManager(manager);
00841             } else {
00842                 addWait(manager);
00843             }
00844         }
00845 
00850         function callDefMain(args) {
00851             main.apply(null, args);
00852         }
00853 
00863         jQueryCheck = function (jqCandidate) {
00864             if (!context.jQuery) {
00865                 var $ = jqCandidate || (typeof jQuery !== "undefined" ? jQuery : null);
00866 
00867                 if ($) {
00868                     //If a specific version of jQuery is wanted, make sure to only
00869                     //use this jQuery if it matches.
00870                     if (config.jQuery && $.fn.jquery !== config.jQuery) {
00871                         return;
00872                     }
00873 
00874                     if ("holdReady" in $ || "readyWait" in $) {
00875                         context.jQuery = $;
00876 
00877                         //Manually create a "jquery" module entry if not one already
00878                         //or in process. Note this could trigger an attempt at
00879                         //a second jQuery registration, but does no harm since
00880                         //the first one wins, and it is the same value anyway.
00881                         callDefMain(["jquery", [], function () {
00882                             return jQuery;
00883                         }]);
00884 
00885                         //Ask jQuery to hold DOM ready callbacks.
00886                         if (context.scriptCount) {
00887                             jQueryHoldReady($, true);
00888                             context.jQueryIncremented = true;
00889                         }
00890                     }
00891                 }
00892             }
00893         };
00894 
00895         function findCycle(manager, traced) {
00896             var fullName = manager.map.fullName,
00897                 depArray = manager.depArray,
00898                 fullyLoaded = true,
00899                 i, depName, depManager, result;
00900 
00901             if (manager.isDone || !fullName || !loaded[fullName]) {
00902                 return result;
00903             }
00904 
00905             //Found the cycle.
00906             if (traced[fullName]) {
00907                 return manager;
00908             }
00909 
00910             traced[fullName] = true;
00911 
00912             //Trace through the dependencies.
00913             if (depArray) {
00914                 for (i = 0; i < depArray.length; i++) {
00915                     //Some array members may be null, like if a trailing comma
00916                     //IE, so do the explicit [i] access and check if it has a value.
00917                     depName = depArray[i];
00918                     if (!loaded[depName] && !reservedDependencies[depName]) {
00919                         fullyLoaded = false;
00920                         break;
00921                     }
00922                     depManager = waiting[depName];
00923                     if (depManager && !depManager.isDone && loaded[depName]) {
00924                         result = findCycle(depManager, traced);
00925                         if (result) {
00926                             break;
00927                         }
00928                     }
00929                 }
00930                 if (!fullyLoaded) {
00931                     //Discard the cycle that was found, since it cannot
00932                     //be forced yet. Also clear this module from traced.
00933                     result = undefined;
00934                     delete traced[fullName];
00935                 }
00936             }
00937 
00938             return result;
00939         }
00940 
00941         function forceExec(manager, traced) {
00942             var fullName = manager.map.fullName,
00943                 depArray = manager.depArray,
00944                 i, depName, depManager, prefix, prefixManager, value;
00945 
00946 
00947             if (manager.isDone || !fullName || !loaded[fullName]) {
00948                 return undefined;
00949             }
00950 
00951             if (fullName) {
00952                 if (traced[fullName]) {
00953                     return defined[fullName];
00954                 }
00955 
00956                 traced[fullName] = true;
00957             }
00958 
00959             //Trace through the dependencies.
00960             if (depArray) {
00961                 for (i = 0; i < depArray.length; i++) {
00962                     //Some array members may be null, like if a trailing comma
00963                     //IE, so do the explicit [i] access and check if it has a value.
00964                     depName = depArray[i];
00965                     if (depName) {
00966                         //First, make sure if it is a plugin resource that the
00967                         //plugin is not blocked.
00968                         prefix = makeModuleMap(depName).prefix;
00969                         if (prefix && (prefixManager = waiting[prefix])) {
00970                             forceExec(prefixManager, traced);
00971                         }
00972                         depManager = waiting[depName];
00973                         if (depManager && !depManager.isDone && loaded[depName]) {
00974                             value = forceExec(depManager, traced);
00975                             manager.depCallbacks[i](value);
00976                         }
00977                     }
00978                 }
00979             }
00980 
00981             return defined[fullName];
00982         }
00983 
00990         function checkLoaded() {
00991             var waitInterval = config.waitSeconds * 1000,
00992                 //It is possible to disable the wait interval by using waitSeconds of 0.
00993                 expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
00994                 noLoads = "", hasLoadedProp = false, stillLoading = false,
00995                 cycleDeps = [],
00996                 i, prop, err, manager, cycleManager, moduleDeps;
00997 
00998             //If there are items still in the paused queue processing wait.
00999             //This is particularly important in the sync case where each paused
01000             //item is processed right away but there may be more waiting.
01001             if (context.pausedCount > 0) {
01002                 return undefined;
01003             }
01004 
01005             //Determine if priority loading is done. If so clear the priority. If
01006             //not, then do not check
01007             if (config.priorityWait) {
01008                 if (isPriorityDone()) {
01009                     //Call resume, since it could have
01010                     //some waiting dependencies to trace.
01011                     resume();
01012                 } else {
01013                     return undefined;
01014                 }
01015             }
01016 
01017             //See if anything is still in flight.
01018             for (prop in loaded) {
01019                 if (!(prop in empty)) {
01020                     hasLoadedProp = true;
01021                     if (!loaded[prop]) {
01022                         if (expired) {
01023                             noLoads += prop + " ";
01024                         } else {
01025                             stillLoading = true;
01026                             if (prop.indexOf('!') === -1) {
01027                                 //No reason to keep looking for unfinished
01028                                 //loading. If the only stillLoading is a
01029                                 //plugin resource though, keep going,
01030                                 //because it may be that a plugin resource
01031                                 //is waiting on a non-plugin cycle.
01032                                 cycleDeps = [];
01033                                 break;
01034                             } else {
01035                                 moduleDeps = managerCallbacks[prop] && managerCallbacks[prop].moduleDeps;
01036                                 if (moduleDeps) {
01037                                     cycleDeps.push.apply(cycleDeps, moduleDeps);
01038                                 }
01039                             }
01040                         }
01041                     }
01042                 }
01043             }
01044 
01045             //Check for exit conditions.
01046             if (!hasLoadedProp && !context.waitCount) {
01047                 //If the loaded object had no items, then the rest of
01048                 //the work below does not need to be done.
01049                 return undefined;
01050             }
01051             if (expired && noLoads) {
01052                 //If wait time expired, throw error of unloaded modules.
01053                 err = makeError("timeout", "Load timeout for modules: " + noLoads);
01054                 err.requireType = "timeout";
01055                 err.requireModules = noLoads;
01056                 return req.onError(err);
01057             }
01058 
01059             //If still loading but a plugin is waiting on a regular module cycle
01060             //break the cycle.
01061             if (stillLoading && cycleDeps.length) {
01062                 for (i = 0; (manager = waiting[cycleDeps[i]]); i++) {
01063                     if ((cycleManager = findCycle(manager, {}))) {
01064                         forceExec(cycleManager, {});
01065                         break;
01066                     }
01067                 }
01068 
01069             }
01070 
01071             //If still waiting on loads, and the waiting load is something
01072             //other than a plugin resource, or there are still outstanding
01073             //scripts, then just try back later.
01074             if (!expired && (stillLoading || context.scriptCount)) {
01075                 //Something is still waiting to load. Wait for it, but only
01076                 //if a timeout is not already in effect.
01077                 if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
01078                     checkLoadedTimeoutId = setTimeout(function () {
01079                         checkLoadedTimeoutId = 0;
01080                         checkLoaded();
01081                     }, 50);
01082                 }
01083                 return undefined;
01084             }
01085 
01086             //If still have items in the waiting cue, but all modules have
01087             //been loaded, then it means there are some circular dependencies
01088             //that need to be broken.
01089             //However, as a waiting thing is fired, then it can add items to
01090             //the waiting cue, and those items should not be fired yet, so
01091             //make sure to redo the checkLoaded call after breaking a single
01092             //cycle, if nothing else loaded then this logic will pick it up
01093             //again.
01094             if (context.waitCount) {
01095                 //Cycle through the waitAry, and call items in sequence.
01096                 for (i = 0; (manager = waitAry[i]); i++) {
01097                     forceExec(manager, {});
01098                 }
01099 
01100                 //If anything got placed in the paused queue, run it down.
01101                 if (context.paused.length) {
01102                     resume();
01103                 }
01104 
01105                 //Only allow this recursion to a certain depth. Only
01106                 //triggered by errors in calling a module in which its
01107                 //modules waiting on it cannot finish loading, or some circular
01108                 //dependencies that then may add more dependencies.
01109                 //The value of 5 is a bit arbitrary. Hopefully just one extra
01110                 //pass, or two for the case of circular dependencies generating
01111                 //more work that gets resolved in the sync node case.
01112                 if (checkLoadedDepth < 5) {
01113                     checkLoadedDepth += 1;
01114                     checkLoaded();
01115                 }
01116             }
01117 
01118             checkLoadedDepth = 0;
01119 
01120             //Check for DOM ready, and nothing is waiting across contexts.
01121             req.checkReadyState();
01122 
01123             return undefined;
01124         }
01125 
01129         resume = function () {
01130             var manager, map, url, i, p, args, fullName;
01131 
01132             //Any defined modules in the global queue, intake them now.
01133             context.takeGlobalQueue();
01134 
01135             resumeDepth += 1;
01136 
01137             if (context.scriptCount <= 0) {
01138                 //Synchronous envs will push the number below zero with the
01139                 //decrement above, be sure to set it back to zero for good measure.
01140                 //require() calls that also do not end up loading scripts could
01141                 //push the number negative too.
01142                 context.scriptCount = 0;
01143             }
01144 
01145             //Make sure any remaining defQueue items get properly processed.
01146             while (defQueue.length) {
01147                 args = defQueue.shift();
01148                 if (args[0] === null) {
01149                     return req.onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
01150                 } else {
01151                     callDefMain(args);
01152                 }
01153             }
01154 
01155             //Skip the resume of paused dependencies
01156             //if current context is in priority wait.
01157             if (!config.priorityWait || isPriorityDone()) {
01158                 while (context.paused.length) {
01159                     p = context.paused;
01160                     context.pausedCount += p.length;
01161                     //Reset paused list
01162                     context.paused = [];
01163 
01164                     for (i = 0; (manager = p[i]); i++) {
01165                         map = manager.map;
01166                         url = map.url;
01167                         fullName = map.fullName;
01168 
01169                         //If the manager is for a plugin managed resource,
01170                         //ask the plugin to load it now.
01171                         if (map.prefix) {
01172                             callPlugin(map.prefix, manager);
01173                         } else {
01174                             //Regular dependency.
01175                             if (!urlFetched[url] && !loaded[fullName]) {
01176                                 req.load(context, fullName, url);
01177 
01178                                 //Mark the URL as fetched, but only if it is
01179                                 //not an empty: URL, used by the optimizer.
01180                                 //In that case we need to be sure to call
01181                                 //load() for each module that is mapped to
01182                                 //empty: so that dependencies are satisfied
01183                                 //correctly.
01184                                 if (url.indexOf('empty:') !== 0) {
01185                                     urlFetched[url] = true;
01186                                 }
01187                             }
01188                         }
01189                     }
01190 
01191                     //Move the start time for timeout forward.
01192                     context.startTime = (new Date()).getTime();
01193                     context.pausedCount -= p.length;
01194                 }
01195             }
01196 
01197             //Only check if loaded when resume depth is 1. It is likely that
01198             //it is only greater than 1 in sync environments where a factory
01199             //function also then calls the callback-style require. In those
01200             //cases, the checkLoaded should not occur until the resume
01201             //depth is back at the top level.
01202             if (resumeDepth === 1) {
01203                 checkLoaded();
01204             }
01205 
01206             resumeDepth -= 1;
01207 
01208             return undefined;
01209         };
01210 
01211         //Define the context object. Many of these fields are on here
01212         //just to make debugging easier.
01213         context = {
01214             contextName: contextName,
01215             config: config,
01216             defQueue: defQueue,
01217             waiting: waiting,
01218             waitCount: 0,
01219             specified: specified,
01220             loaded: loaded,
01221             urlMap: urlMap,
01222             urlFetched: urlFetched,
01223             scriptCount: 0,
01224             defined: defined,
01225             paused: [],
01226             pausedCount: 0,
01227             plugins: plugins,
01228             needFullExec: needFullExec,
01229             fake: {},
01230             fullExec: fullExec,
01231             managerCallbacks: managerCallbacks,
01232             makeModuleMap: makeModuleMap,
01233             normalize: normalize,
01238             configure: function (cfg) {
01239                 var paths, prop, packages, pkgs, packagePaths, requireWait;
01240 
01241                 //Make sure the baseUrl ends in a slash.
01242                 if (cfg.baseUrl) {
01243                     if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== "/") {
01244                         cfg.baseUrl += "/";
01245                     }
01246                 }
01247 
01248                 //Save off the paths and packages since they require special processing,
01249                 //they are additive.
01250                 paths = config.paths;
01251                 packages = config.packages;
01252                 pkgs = config.pkgs;
01253 
01254                 //Mix in the config values, favoring the new values over
01255                 //existing ones in context.config.
01256                 mixin(config, cfg, true);
01257 
01258                 //Adjust paths if necessary.
01259                 if (cfg.paths) {
01260                     for (prop in cfg.paths) {
01261                         if (!(prop in empty)) {
01262                             paths[prop] = cfg.paths[prop];
01263                         }
01264                     }
01265                     config.paths = paths;
01266                 }
01267 
01268                 packagePaths = cfg.packagePaths;
01269                 if (packagePaths || cfg.packages) {
01270                     //Convert packagePaths into a packages config.
01271                     if (packagePaths) {
01272                         for (prop in packagePaths) {
01273                             if (!(prop in empty)) {
01274                                 configurePackageDir(pkgs, packagePaths[prop], prop);
01275                             }
01276                         }
01277                     }
01278 
01279                     //Adjust packages if necessary.
01280                     if (cfg.packages) {
01281                         configurePackageDir(pkgs, cfg.packages);
01282                     }
01283 
01284                     //Done with modifications, assing packages back to context config
01285                     config.pkgs = pkgs;
01286                 }
01287 
01288                 //If priority loading is in effect, trigger the loads now
01289                 if (cfg.priority) {
01290                     //Hold on to requireWait value, and reset it after done
01291                     requireWait = context.requireWait;
01292 
01293                     //Allow tracing some require calls to allow the fetching
01294                     //of the priority config.
01295                     context.requireWait = false;
01296                     //But first, call resume to register any defined modules that may
01297                     //be in a data-main built file before the priority config
01298                     //call.
01299                     resume();
01300 
01301                     context.require(cfg.priority);
01302 
01303                     //Trigger a resume right away, for the case when
01304                     //the script with the priority load is done as part
01305                     //of a data-main call. In that case the normal resume
01306                     //call will not happen because the scriptCount will be
01307                     //at 1, since the script for data-main is being processed.
01308                     resume();
01309 
01310                     //Restore previous state.
01311                     context.requireWait = requireWait;
01312                     config.priorityWait = cfg.priority;
01313                 }
01314 
01315                 //If a deps array or a config callback is specified, then call
01316                 //require with those args. This is useful when require is defined as a
01317                 //config object before require.js is loaded.
01318                 if (cfg.deps || cfg.callback) {
01319                     context.require(cfg.deps || [], cfg.callback);
01320                 }
01321             },
01322 
01323             requireDefined: function (moduleName, relModuleMap) {
01324                 return makeModuleMap(moduleName, relModuleMap).fullName in defined;
01325             },
01326 
01327             requireSpecified: function (moduleName, relModuleMap) {
01328                 return makeModuleMap(moduleName, relModuleMap).fullName in specified;
01329             },
01330 
01331             require: function (deps, callback, relModuleMap) {
01332                 var moduleName, fullName, moduleMap;
01333                 if (typeof deps === "string") {
01334                     if (isFunction(callback)) {
01335                         //Invalid call
01336                         return req.onError(makeError("requireargs", "Invalid require call"));
01337                     }
01338 
01339                     //Synchronous access to one module. If require.get is
01340                     //available (as in the Node adapter), prefer that.
01341                     //In this case deps is the moduleName and callback is
01342                     //the relModuleMap
01343                     if (req.get) {
01344                         return req.get(context, deps, callback);
01345                     }
01346 
01347                     //Just return the module wanted. In this scenario, the
01348                     //second arg (if passed) is just the relModuleMap.
01349                     moduleName = deps;
01350                     relModuleMap = callback;
01351 
01352                     //Normalize module name, if it contains . or ..
01353                     moduleMap = makeModuleMap(moduleName, relModuleMap);
01354                     fullName = moduleMap.fullName;
01355 
01356                     if (!(fullName in defined)) {
01357                         return req.onError(makeError("notloaded", "Module name '" +
01358                                     moduleMap.fullName +
01359                                     "' has not been loaded yet for context: " +
01360                                     contextName));
01361                     }
01362                     return defined[fullName];
01363                 }
01364 
01365                 //Call main but only if there are dependencies or
01366                 //a callback to call.
01367                 if (deps && deps.length || callback) {
01368                     main(null, deps, callback, relModuleMap);
01369                 }
01370 
01371                 //If the require call does not trigger anything new to load,
01372                 //then resume the dependency processing.
01373                 if (!context.requireWait) {
01374                     while (!context.scriptCount && context.paused.length) {
01375                         resume();
01376                     }
01377                 }
01378                 return context.require;
01379             },
01380 
01385             takeGlobalQueue: function () {
01386                 //Push all the globalDefQueue items into the context's defQueue
01387                 if (globalDefQueue.length) {
01388                     //Array splice in the values since the context code has a
01389                     //local var ref to defQueue, so cannot just reassign the one
01390                     //on context.
01391                     apsp.apply(context.defQueue,
01392                                [context.defQueue.length - 1, 0].concat(globalDefQueue));
01393                     globalDefQueue = [];
01394                 }
01395             },
01396 
01403             completeLoad: function (moduleName) {
01404                 var args;
01405 
01406                 context.takeGlobalQueue();
01407 
01408                 while (defQueue.length) {
01409                     args = defQueue.shift();
01410 
01411                     if (args[0] === null) {
01412                         args[0] = moduleName;
01413                         break;
01414                     } else if (args[0] === moduleName) {
01415                         //Found matching define call for this script!
01416                         break;
01417                     } else {
01418                         //Some other named define call, most likely the result
01419                         //of a build layer that included many define calls.
01420                         callDefMain(args);
01421                         args = null;
01422                     }
01423                 }
01424                 if (args) {
01425                     callDefMain(args);
01426                 } else {
01427                     //A script that does not call define(), so just simulate
01428                     //the call for it. Special exception for jQuery dynamic load.
01429                     callDefMain([moduleName, [],
01430                                 moduleName === "jquery" && typeof jQuery !== "undefined" ?
01431                                 function () {
01432                                     return jQuery;
01433                                 } : null]);
01434                 }
01435 
01436                 //Doing this scriptCount decrement branching because sync envs
01437                 //need to decrement after resume, otherwise it looks like
01438                 //loading is complete after the first dependency is fetched.
01439                 //For browsers, it works fine to decrement after, but it means
01440                 //the checkLoaded setTimeout 50 ms cost is taken. To avoid
01441                 //that cost, decrement beforehand.
01442                 if (req.isAsync) {
01443                     context.scriptCount -= 1;
01444                 }
01445                 resume();
01446                 if (!req.isAsync) {
01447                     context.scriptCount -= 1;
01448                 }
01449             },
01450 
01456             toUrl: function (moduleNamePlusExt, relModuleMap) {
01457                 var index = moduleNamePlusExt.lastIndexOf("."),
01458                     ext = null;
01459 
01460                 if (index !== -1) {
01461                     ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
01462                     moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
01463                 }
01464 
01465                 return context.nameToUrl(moduleNamePlusExt, ext, relModuleMap);
01466             },
01467 
01472             nameToUrl: function (moduleName, ext, relModuleMap) {
01473                 var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
01474                     config = context.config;
01475 
01476                 //Normalize module name if have a base relative module name to work from.
01477                 moduleName = normalize(moduleName, relModuleMap && relModuleMap.fullName);
01478 
01479                 //If a colon is in the URL, it indicates a protocol is used and it is just
01480                 //an URL to a file, or if it starts with a slash or ends with .js, it is just a plain file.
01481                 //The slash is important for protocol-less URLs as well as full paths.
01482                 if (req.jsExtRegExp.test(moduleName)) {
01483                     //Just a plain path, not module name lookup, so just return it.
01484                     //Add extension if it is included. This is a bit wonky, only non-.js things pass
01485                     //an extension, this method probably needs to be reworked.
01486                     url = moduleName + (ext ? ext : "");
01487                 } else {
01488                     //A module that needs to be converted to a path.
01489                     paths = config.paths;
01490                     pkgs = config.pkgs;
01491 
01492                     syms = moduleName.split("/");
01493                     //For each module name segment, see if there is a path
01494                     //registered for it. Start with most specific name
01495                     //and work up from it.
01496                     for (i = syms.length; i > 0; i--) {
01497                         parentModule = syms.slice(0, i).join("/");
01498                         if (paths[parentModule]) {
01499                             syms.splice(0, i, paths[parentModule]);
01500                             break;
01501                         } else if ((pkg = pkgs[parentModule])) {
01502                             //If module name is just the package name, then looking
01503                             //for the main module.
01504                             if (moduleName === pkg.name) {
01505                                 pkgPath = pkg.location + '/' + pkg.main;
01506                             } else {
01507                                 pkgPath = pkg.location;
01508                             }
01509                             syms.splice(0, i, pkgPath);
01510                             break;
01511                         }
01512                     }
01513 
01514                     //Join the path parts together, then figure out if baseUrl is needed.
01515                     url = syms.join("/") + (ext || ".js");
01516                     url = (url.charAt(0) === '/' || url.match(/^\w+:/) ? "" : config.baseUrl) + url;
01517                 }
01518 
01519                 return config.urlArgs ? url +
01520                                         ((url.indexOf('?') === -1 ? '?' : '&') +
01521                                          config.urlArgs) : url;
01522             }
01523         };
01524 
01525         //Make these visible on the context so can be called at the very
01526         //end of the file to bootstrap
01527         context.jQueryCheck = jQueryCheck;
01528         context.resume = resume;
01529 
01530         return context;
01531     }
01532 
01547     req = requirejs = function (deps, callback) {
01548 
01549         //Find the right context, use default
01550         var contextName = defContextName,
01551             context, config;
01552 
01553         // Determine if have config object in the call.
01554         if (!isArray(deps) && typeof deps !== "string") {
01555             // deps is a config object
01556             config = deps;
01557             if (isArray(callback)) {
01558                 // Adjust args if there are dependencies
01559                 deps = callback;
01560                 callback = arguments[2];
01561             } else {
01562                 deps = [];
01563             }
01564         }
01565 
01566         if (config && config.context) {
01567             contextName = config.context;
01568         }
01569 
01570         context = contexts[contextName] ||
01571                   (contexts[contextName] = newContext(contextName));
01572 
01573         if (config) {
01574             context.configure(config);
01575         }
01576 
01577         return context.require(deps, callback);
01578     };
01579 
01584     req.config = function (config) {
01585         return req(config);
01586     };
01587 
01591     if (!require) {
01592         require = req;
01593     }
01594 
01599     req.toUrl = function (moduleNamePlusExt) {
01600         return contexts[defContextName].toUrl(moduleNamePlusExt);
01601     };
01602 
01603     req.version = version;
01604 
01605     //Used to filter out dependencies that are already paths.
01606     req.jsExtRegExp = /^\/|:|\?|\.js$/;
01607     s = req.s = {
01608         contexts: contexts,
01609         //Stores a list of URLs that should not get async script tag treatment.
01610         skipAsync: {}
01611     };
01612 
01613     req.isAsync = req.isBrowser = isBrowser;
01614     if (isBrowser) {
01615         head = s.head = document.getElementsByTagName("head")[0];
01616         //If BASE tag is in play, using appendChild is a problem for IE6.
01617         //When that browser dies, this can be removed. Details in this jQuery bug:
01618         //http://dev.jquery.com/ticket/2709
01619         baseElement = document.getElementsByTagName("base")[0];
01620         if (baseElement) {
01621             head = s.head = baseElement.parentNode;
01622         }
01623     }
01624 
01630     req.onError = function (err) {
01631         throw err;
01632     };
01633 
01643     req.load = function (context, moduleName, url) {
01644         req.resourcesReady(false);
01645 
01646         context.scriptCount += 1;
01647         req.attach(url, context, moduleName);
01648 
01649         //If tracking a jQuery, then make sure its ready callbacks
01650         //are put on hold to prevent its ready callbacks from
01651         //triggering too soon.
01652         if (context.jQuery && !context.jQueryIncremented) {
01653             jQueryHoldReady(context.jQuery, true);
01654             context.jQueryIncremented = true;
01655         }
01656     };
01657 
01658     function getInteractiveScript() {
01659         var scripts, i, script;
01660         if (interactiveScript && interactiveScript.readyState === 'interactive') {
01661             return interactiveScript;
01662         }
01663 
01664         scripts = document.getElementsByTagName('script');
01665         for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) {
01666             if (script.readyState === 'interactive') {
01667                 return (interactiveScript = script);
01668             }
01669         }
01670 
01671         return null;
01672     }
01673 
01681     define = function (name, deps, callback) {
01682         var node, context;
01683 
01684         //Allow for anonymous functions
01685         if (typeof name !== 'string') {
01686             //Adjust args appropriately
01687             callback = deps;
01688             deps = name;
01689             name = null;
01690         }
01691 
01692         //This module may not have dependencies
01693         if (!isArray(deps)) {
01694             callback = deps;
01695             deps = [];
01696         }
01697 
01698         //If no name, and callback is a function, then figure out if it a
01699         //CommonJS thing with dependencies.
01700         if (!deps.length && isFunction(callback)) {
01701             //Remove comments from the callback string,
01702             //look for require calls, and pull them into the dependencies,
01703             //but only if there are function args.
01704             if (callback.length) {
01705                 callback
01706                     .toString()
01707                     .replace(commentRegExp, "")
01708                     .replace(cjsRequireRegExp, function (match, dep) {
01709                         deps.push(dep);
01710                     });
01711 
01712                 //May be a CommonJS thing even without require calls, but still
01713                 //could use exports, and module. Avoid doing exports and module
01714                 //work though if it just needs require.
01715                 //REQUIRES the function to expect the CommonJS variables in the
01716                 //order listed below.
01717                 deps = (callback.length === 1 ? ["require"] : ["require", "exports", "module"]).concat(deps);
01718             }
01719         }
01720 
01721         //If in IE 6-8 and hit an anonymous define() call, do the interactive
01722         //work.
01723         if (useInteractive) {
01724             node = currentlyAddingScript || getInteractiveScript();
01725             if (node) {
01726                 if (!name) {
01727                     name = node.getAttribute("data-requiremodule");
01728                 }
01729                 context = contexts[node.getAttribute("data-requirecontext")];
01730             }
01731         }
01732 
01733         //Always save off evaluating the def call until the script onload handler.
01734         //This allows multiple modules to be in a file without prematurely
01735         //tracing dependencies, and allows for anonymous module support,
01736         //where the module name is not known until the script onload event
01737         //occurs. If no context, use the global queue, and get it processed
01738         //in the onscript load callback.
01739         (context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
01740 
01741         return undefined;
01742     };
01743 
01744     define.amd = {
01745         multiversion: true,
01746         plugins: true,
01747         jQuery: true
01748     };
01749 
01755     req.exec = function (text) {
01756         return eval(text);
01757     };
01758 
01766     req.execCb = function (name, callback, args, exports) {
01767         return callback.apply(exports, args);
01768     };
01769 
01770 
01775     req.addScriptToDom = function (node) {
01776         //For some cache cases in IE 6-8, the script executes before the end
01777         //of the appendChild execution, so to tie an anonymous define
01778         //call to the module name (which is stored on the node), hold on
01779         //to a reference to this node, but clear after the DOM insertion.
01780         currentlyAddingScript = node;
01781         if (baseElement) {
01782             head.insertBefore(node, baseElement);
01783         } else {
01784             head.appendChild(node);
01785         }
01786         currentlyAddingScript = null;
01787     };
01788 
01797     req.onScriptLoad = function (evt) {
01798         //Using currentTarget instead of target for Firefox 2.0's sake. Not
01799         //all old browsers will be supported, but this one was easy enough
01800         //to support and still makes sense.
01801         var node = evt.currentTarget || evt.srcElement, contextName, moduleName,
01802             context;
01803 
01804         if (evt.type === "load" || (node && readyRegExp.test(node.readyState))) {
01805             //Reset interactive script so a script node is not held onto for
01806             //to long.
01807             interactiveScript = null;
01808 
01809             //Pull out the name of the module and the context.
01810             contextName = node.getAttribute("data-requirecontext");
01811             moduleName = node.getAttribute("data-requiremodule");
01812             context = contexts[contextName];
01813 
01814             contexts[contextName].completeLoad(moduleName);
01815 
01816             //Clean up script binding. Favor detachEvent because of IE9
01817             //issue, see attachEvent/addEventListener comment elsewhere
01818             //in this file.
01819             if (node.detachEvent && !isOpera) {
01820                 //Probably IE. If not it will throw an error, which will be
01821                 //useful to know.
01822                 node.detachEvent("onreadystatechange", req.onScriptLoad);
01823             } else {
01824                 node.removeEventListener("load", req.onScriptLoad, false);
01825             }
01826         }
01827     };
01828 
01844     req.attach = function (url, context, moduleName, callback, type, fetchOnlyFunction) {
01845         var node;
01846         if (isBrowser) {
01847             //In the browser so use a script tag
01848             callback = callback || req.onScriptLoad;
01849             node = context && context.config && context.config.xhtml ?
01850                     document.createElementNS("http://www.w3.org/1999/xhtml", "html:script") :
01851                     document.createElement("script");
01852             node.type = type || (context && context.config.scriptType) ||
01853                         "text/javascript";
01854             node.charset = "utf-8";
01855             //Use async so Gecko does not block on executing the script if something
01856             //like a long-polling comet tag is being run first. Gecko likes
01857             //to evaluate scripts in DOM order, even for dynamic scripts.
01858             //It will fetch them async, but only evaluate the contents in DOM
01859             //order, so a long-polling script tag can delay execution of scripts
01860             //after it. But telling Gecko we expect async gets us the behavior
01861             //we want -- execute it whenever it is finished downloading. Only
01862             //Helps Firefox 3.6+
01863             //Allow some URLs to not be fetched async. Mostly helps the order!
01864             //plugin
01865             node.async = !s.skipAsync[url];
01866 
01867             if (context) {
01868                 node.setAttribute("data-requirecontext", context.contextName);
01869             }
01870             node.setAttribute("data-requiremodule", moduleName);
01871 
01872             //Set up load listener. Test attachEvent first because IE9 has
01873             //a subtle issue in its addEventListener and script onload firings
01874             //that do not match the behavior of all other browsers with
01875             //addEventListener support, which fire the onload event for a
01876             //script right after the script execution. See:
01877             //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
01878             //UNFORTUNATELY Opera implements attachEvent but does not follow the script
01879             //script execution mode.
01880             if (node.attachEvent && !isOpera) {
01881                 //Probably IE. IE (at least 6-8) do not fire
01882                 //script onload right after executing the script, so
01883                 //we cannot tie the anonymous define call to a name.
01884                 //However, IE reports the script as being in "interactive"
01885                 //readyState at the time of the define call.
01886                 useInteractive = true;
01887 
01888 
01889                 if (fetchOnlyFunction) {
01890                     //Need to use old school onreadystate here since
01891                     //when the event fires and the node is not attached
01892                     //to the DOM, the evt.srcElement is null, so use
01893                     //a closure to remember the node.
01894                     node.onreadystatechange = function (evt) {
01895                         //Script loaded but not executed.
01896                         //Clear loaded handler, set the real one that
01897                         //waits for script execution.
01898                         if (node.readyState === 'loaded') {
01899                             node.onreadystatechange = null;
01900                             node.attachEvent("onreadystatechange", callback);
01901                             fetchOnlyFunction(node);
01902                         }
01903                     };
01904                 } else {
01905                     node.attachEvent("onreadystatechange", callback);
01906                 }
01907             } else {
01908                 node.addEventListener("load", callback, false);
01909             }
01910             node.src = url;
01911 
01912             //Fetch only means waiting to attach to DOM after loaded.
01913             if (!fetchOnlyFunction) {
01914                 req.addScriptToDom(node);
01915             }
01916 
01917             return node;
01918         } else if (isWebWorker) {
01919             //In a web worker, use importScripts. This is not a very
01920             //efficient use of importScripts, importScripts will block until
01921             //its script is downloaded and evaluated. However, if web workers
01922             //are in play, the expectation that a build has been done so that
01923             //only one script needs to be loaded anyway. This may need to be
01924             //reevaluated if other use cases become common.
01925             importScripts(url);
01926 
01927             //Account for anonymous modules
01928             context.completeLoad(moduleName);
01929         }
01930         return null;
01931     };
01932 
01933     //Look for a data-main script attribute, which could also adjust the baseUrl.
01934     if (isBrowser) {
01935         //Figure out baseUrl. Get it from the script tag with require.js in it.
01936         scripts = document.getElementsByTagName("script");
01937 
01938         for (globalI = scripts.length - 1; globalI > -1 && (script = scripts[globalI]); globalI--) {
01939             //Set the "head" where we can append children by
01940             //using the script's parent.
01941             if (!head) {
01942                 head = script.parentNode;
01943             }
01944 
01945             //Look for a data-main attribute to set main script for the page
01946             //to load. If it is there, the path to data main becomes the
01947             //baseUrl, if it is not already set.
01948             if ((dataMain = script.getAttribute('data-main'))) {
01949                 if (!cfg.baseUrl) {
01950                     //Pull off the directory of data-main for use as the
01951                     //baseUrl.
01952                     src = dataMain.split('/');
01953                     mainScript = src.pop();
01954                     subPath = src.length ? src.join('/')  + '/' : './';
01955 
01956                     //Set final config.
01957                     cfg.baseUrl = subPath;
01958                     //Strip off any trailing .js since dataMain is now
01959                     //like a module name.
01960                     dataMain = mainScript.replace(jsSuffixRegExp, '');
01961                 }
01962 
01963                 //Put the data-main script in the files to load.
01964                 cfg.deps = cfg.deps ? cfg.deps.concat(dataMain) : [dataMain];
01965 
01966                 break;
01967             }
01968         }
01969     }
01970 
01971     //See if there is nothing waiting across contexts, and if not, trigger
01972     //resourcesReady.
01973     req.checkReadyState = function () {
01974         var contexts = s.contexts, prop;
01975         for (prop in contexts) {
01976             if (!(prop in empty)) {
01977                 if (contexts[prop].waitCount) {
01978                     return;
01979                 }
01980             }
01981         }
01982         req.resourcesReady(true);
01983     };
01984 
01991     req.resourcesReady = function (isReady) {
01992         var contexts, context, prop;
01993 
01994         //First, set the public variable indicating that resources are loading.
01995         req.resourcesDone = isReady;
01996 
01997         if (req.resourcesDone) {
01998             //If jQuery with DOM ready delayed, release it now.
01999             contexts = s.contexts;
02000             for (prop in contexts) {
02001                 if (!(prop in empty)) {
02002                     context = contexts[prop];
02003                     if (context.jQueryIncremented) {
02004                         jQueryHoldReady(context.jQuery, false);
02005                         context.jQueryIncremented = false;
02006                     }
02007                 }
02008             }
02009         }
02010     };
02011 
02012     //FF < 3.6 readyState fix. Needed so that domReady plugin
02013     //works well in that environment, since require.js is normally
02014     //loaded via an HTML script tag so it will be there before window load,
02015     //where the domReady plugin is more likely to be loaded after window load.
02016     req.pageLoaded = function () {
02017         if (document.readyState !== "complete") {
02018             document.readyState = "complete";
02019         }
02020     };
02021     if (isBrowser) {
02022         if (document.addEventListener) {
02023             if (!document.readyState) {
02024                 document.readyState = "loading";
02025                 window.addEventListener("load", req.pageLoaded, false);
02026             }
02027         }
02028     }
02029 
02030     //Set up default context. If require was a configuration object, use that as base config.
02031     req(cfg);
02032 
02033     //If modules are built into require.js, then need to make sure dependencies are
02034     //traced. Use a setTimeout in the browser world, to allow all the modules to register
02035     //themselves. In a non-browser env, assume that modules are not built into require.js,
02036     //which seems odd to do on the server.
02037     if (req.isAsync && typeof setTimeout !== "undefined") {
02038         ctx = s.contexts[(cfg.context || defContextName)];
02039         //Indicate that the script that includes require() is still loading,
02040         //so that require()'d dependencies are not traced until the end of the
02041         //file is parsed (approximated via the setTimeout call).
02042         ctx.requireWait = true;
02043         setTimeout(function () {
02044             ctx.requireWait = false;
02045 
02046             if (!ctx.scriptCount) {
02047                 ctx.resume();
02048             }
02049             req.checkReadyState();
02050         }, 0);
02051     }
02052 }());
 All Classes Namespaces Files Functions Variables