diff --git a/external/requirejs/require.js b/external/requirejs/require.js index f661bd3e..3aa738fb 100644 --- a/external/requirejs/require.js +++ b/external/requirejs/require.js @@ -1,17 +1,15 @@ /** vim: et:ts=4:sw=4:sts=4 - * @license RequireJS 1.0.3 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved. + * @license RequireJS 1.0.5 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved. * Available via the MIT or new BSD license. * see: http://github.com/jrburke/requirejs for details */ /*jslint strict: false, plusplus: false, sub: true */ -/*global window: false, navigator: false, document: false, importScripts: false, - jQuery: false, clearInterval: false, setInterval: false, self: false, - setTimeout: false, opera: false */ +/*global window, navigator, document, importScripts, jQuery, setTimeout, opera */ var requirejs, require, define; (function () { //Change this version number for each release. - var version = "1.0.3", + var version = "1.0.5", commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g, currDirRegExp = /^\.\//, @@ -37,8 +35,13 @@ var requirejs, require, define; interactiveScript = null, checkLoadedDepth = 0, useInteractive = false, + reservedDependencies = { + require: true, + module: true, + exports: true + }, req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script, - src, subPath, mainScript, dataMain, i, ctx, jQueryCheck, checkLoadedTimeoutId; + src, subPath, mainScript, dataMain, globalI, ctx, jQueryCheck, checkLoadedTimeoutId; function isFunction(it) { return ostring.call(it) === "[object Function]"; @@ -323,7 +326,15 @@ var requirejs, require, define; url = urlMap[normalizedName]; if (!url) { //Calculate url for the module, if it has a name. - url = context.nameToUrl(normalizedName, null, parentModuleMap); + //Use name here since nameToUrl also calls normalize, + //and for relative names that are outside the baseUrl + //this causes havoc. Was thinking of just removing + //parentModuleMap to avoid extra normalization, but + //normalize() still does a dot removal because of + //issue #142, so just pass in name here and redo + //the normalization. Paths outside baseUrl are just + //messy to support. + url = context.nameToUrl(name, null, parentModuleMap); //Store the URL mapping for later. urlMap[normalizedName] = url; @@ -383,8 +394,8 @@ var requirejs, require, define; * per module because of the implication of path mappings that may * need to be relative to the module name. */ - function makeRequire(relModuleMap, enableBuildCallback) { - var modRequire = makeContextModuleFunc(context.require, relModuleMap, enableBuildCallback); + function makeRequire(relModuleMap, enableBuildCallback, altRequire) { + var modRequire = makeContextModuleFunc(altRequire || context.require, relModuleMap, enableBuildCallback); mixin(modRequire, { nameToUrl: makeContextModuleFunc(context.nameToUrl, relModuleMap), @@ -599,7 +610,22 @@ var requirejs, require, define; //Use parentName here since the plugin's name is not reliable, //could be some weird string with no path that actually wants to //reference the parentName's path. - plugin.load(name, makeRequire(map.parentMap, true), load, config); + plugin.load(name, makeRequire(map.parentMap, true, function (deps, cb) { + var moduleDeps = [], + i, dep, depMap; + //Convert deps to full names and hold on to them + //for reference later, when figuring out if they + //are blocked by a circular dependency. + for (i = 0; (dep = deps[i]); i++) { + depMap = makeModuleMap(dep, map.parentMap); + deps[i] = depMap.fullName; + if (!depMap.prefix) { + moduleDeps.push(deps[i]); + } + } + depManager.moduleDeps = (depManager.moduleDeps || []).concat(moduleDeps); + return context.require(deps, cb); + }), load, config); } } @@ -628,7 +654,7 @@ var requirejs, require, define; prefix = map.prefix, plugin = prefix ? plugins[prefix] || (plugins[prefix] = defined[prefix]) : null, - manager, created, pluginManager; + manager, created, pluginManager, prefixMap; if (fullName) { manager = managerCallbacks[fullName]; @@ -666,7 +692,18 @@ var requirejs, require, define; //If there is a plugin needed, but it is not loaded, //first load the plugin, then continue on. if (prefix && !plugin) { - pluginManager = getManager(makeModuleMap(prefix), true); + prefixMap = makeModuleMap(prefix); + + //Clear out defined and urlFetched if the plugin was previously + //loaded/defined, but not as full module (as in a build + //situation). However, only do this work if the plugin is in + //defined but does not have a module export value. + if (prefix in defined && !defined[prefix]) { + delete defined[prefix]; + delete urlFetched[prefixMap.url]; + } + + pluginManager = getManager(prefixMap, true); pluginManager.add(function (plugin) { //Create a new manager for the normalized //resource ID and have it call this manager when @@ -855,15 +892,62 @@ var requirejs, require, define; } }; - function forceExec(manager, traced) { - if (manager.isDone) { - return undefined; + function findCycle(manager, traced) { + var fullName = manager.map.fullName, + depArray = manager.depArray, + fullyLoaded = true, + i, depName, depManager, result; + + if (manager.isDone || !fullName || !loaded[fullName]) { + return result; } + //Found the cycle. + if (traced[fullName]) { + return manager; + } + + traced[fullName] = true; + + //Trace through the dependencies. + if (depArray) { + for (i = 0; i < depArray.length; i++) { + //Some array members may be null, like if a trailing comma + //IE, so do the explicit [i] access and check if it has a value. + depName = depArray[i]; + if (!loaded[depName] && !reservedDependencies[depName]) { + fullyLoaded = false; + break; + } + depManager = waiting[depName]; + if (depManager && !depManager.isDone && loaded[depName]) { + result = findCycle(depManager, traced); + if (result) { + break; + } + } + } + if (!fullyLoaded) { + //Discard the cycle that was found, since it cannot + //be forced yet. Also clear this module from traced. + result = undefined; + delete traced[fullName]; + } + } + + return result; + } + + function forceExec(manager, traced) { var fullName = manager.map.fullName, depArray = manager.depArray, i, depName, depManager, prefix, prefixManager, value; + + if (manager.isDone || !fullName || !loaded[fullName]) { + return undefined; + } + if (fullName) { if (traced[fullName]) { return defined[fullName]; @@ -894,7 +978,7 @@ var requirejs, require, define; } } - return fullName ? defined[fullName] : undefined; + return defined[fullName]; } /** @@ -907,8 +991,9 @@ var requirejs, require, define; var waitInterval = config.waitSeconds * 1000, //It is possible to disable the wait interval by using waitSeconds of 0. expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(), - noLoads = "", hasLoadedProp = false, stillLoading = false, prop, - err, manager; + noLoads = "", hasLoadedProp = false, stillLoading = false, + cycleDeps = [], + i, prop, err, manager, cycleManager, moduleDeps; //If there are items still in the paused queue processing wait. //This is particularly important in the sync case where each paused @@ -938,7 +1023,20 @@ var requirejs, require, define; noLoads += prop + " "; } else { stillLoading = true; - break; + if (prop.indexOf('!') === -1) { + //No reason to keep looking for unfinished + //loading. If the only stillLoading is a + //plugin resource though, keep going, + //because it may be that a plugin resource + //is waiting on a non-plugin cycle. + cycleDeps = []; + break; + } else { + moduleDeps = managerCallbacks[prop] && managerCallbacks[prop].moduleDeps; + if (moduleDeps) { + cycleDeps.push.apply(cycleDeps, moduleDeps); + } + } } } } @@ -957,7 +1055,23 @@ var requirejs, require, define; err.requireModules = noLoads; return req.onError(err); } - if (stillLoading || context.scriptCount) { + + //If still loading but a plugin is waiting on a regular module cycle + //break the cycle. + if (stillLoading && cycleDeps.length) { + for (i = 0; (manager = waiting[cycleDeps[i]]); i++) { + if ((cycleManager = findCycle(manager, {}))) { + forceExec(cycleManager, {}); + break; + } + } + + } + + //If still waiting on loads, and the waiting load is something + //other than a plugin resource, or there are still outstanding + //scripts, then just try back later. + if (!expired && (stillLoading || context.scriptCount)) { //Something is still waiting to load. Wait for it, but only //if a timeout is not already in effect. if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) { @@ -1015,6 +1129,9 @@ var requirejs, require, define; resume = function () { var manager, map, url, i, p, args, fullName; + //Any defined modules in the global queue, intake them now. + context.takeGlobalQueue(); + resumeDepth += 1; if (context.scriptCount <= 0) { @@ -1178,8 +1295,7 @@ var requirejs, require, define; context.requireWait = false; //But first, call resume to register any defined modules that may //be in a data-main built file before the priority config - //call. Also grab any waiting define calls for this context. - context.takeGlobalQueue(); + //call. resume(); context.require(cfg.priority); @@ -1256,10 +1372,6 @@ var requirejs, require, define; //then resume the dependency processing. if (!context.requireWait) { while (!context.scriptCount && context.paused.length) { - //For built layers, there can be some defined - //modules waiting for intake into the context, - //in particular module plugins. Take them. - context.takeGlobalQueue(); resume(); } } @@ -1737,7 +1849,8 @@ var requirejs, require, define; node = context && context.config && context.config.xhtml ? document.createElementNS("http://www.w3.org/1999/xhtml", "html:script") : document.createElement("script"); - node.type = type || "text/javascript"; + node.type = type || (context && context.config.scriptType) || + "text/javascript"; node.charset = "utf-8"; //Use async so Gecko does not block on executing the script if something //like a long-polling comet tag is being run first. Gecko likes @@ -1822,7 +1935,7 @@ var requirejs, require, define; //Figure out baseUrl. Get it from the script tag with require.js in it. scripts = document.getElementsByTagName("script"); - for (i = scripts.length - 1; i > -1 && (script = scripts[i]); i--) { + for (globalI = scripts.length - 1; globalI > -1 && (script = scripts[globalI]); globalI--) { //Set the "head" where we can append children by //using the script's parent. if (!head) { @@ -1930,10 +2043,6 @@ var requirejs, require, define; setTimeout(function () { ctx.requireWait = false; - //Any modules included with the require.js file will be in the - //global queue, assign them to this context. - ctx.takeGlobalQueue(); - if (!ctx.scriptCount) { ctx.resume(); }