update require.js in demo

This commit is contained in:
nightwing 2012-05-11 16:12:39 +04:00
commit adbed85f97
2 changed files with 161 additions and 48 deletions

View file

@ -677,13 +677,6 @@ require("ace/multi_select").MultiSelect(env.editor);
/* var Editor = require("ace/editor").Editor;
var UndoManager = require("ace/undomanager").UndoManager;
var Renderer = require("ace/virtual_renderer").VirtualRenderer;
var MultiSelect = require("ace/multi_select").MultiSelect; */
function singleLineEditor(el) { function singleLineEditor(el) {
var renderer = new Renderer(el); var renderer = new Renderer(el);
renderer.scrollBar.element.style.display = "none"; renderer.scrollBar.element.style.display = "none";
@ -734,7 +727,7 @@ function singleLineEditor(el) {
editor.setHighlightActiveLine(false); editor.setHighlightActiveLine(false);
editor.setShowPrintMargin(false); editor.setShowPrintMargin(false);
editor.renderer.setShowGutter(false); editor.renderer.setShowGutter(false);
editor.renderer.setHighlightGutterLine(false); // editor.renderer.setHighlightGutterLine(false);
return editor; return editor;
}; };

View file

@ -1,17 +1,15 @@
/** vim: et:ts=4:sw=4:sts=4 /** 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.8 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
* Available via the MIT or new BSD license. * Available via the MIT or new BSD license.
* see: http://github.com/jrburke/requirejs for details * see: http://github.com/jrburke/requirejs for details
*/ */
/*jslint strict: false, plusplus: false, sub: true */ /*jslint strict: false, plusplus: false, sub: true */
/*global window: false, navigator: false, document: false, importScripts: false, /*global window, navigator, document, importScripts, jQuery, setTimeout, opera */
jQuery: false, clearInterval: false, setInterval: false, self: false,
setTimeout: false, opera: false */
var requirejs, require, define; var requirejs, require, define;
(function () { (function (undefined) {
//Change this version number for each release. //Change this version number for each release.
var version = "1.0.3", var version = "1.0.8",
commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg, commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g, cjsRequireRegExp = /require\(\s*["']([^'"\s]+)["']\s*\)/g,
currDirRegExp = /^\.\//, currDirRegExp = /^\.\//,
@ -37,8 +35,13 @@ var requirejs, require, define;
interactiveScript = null, interactiveScript = null,
checkLoadedDepth = 0, checkLoadedDepth = 0,
useInteractive = false, useInteractive = false,
reservedDependencies = {
require: true,
module: true,
exports: true
},
req, cfg = {}, currentlyAddingScript, s, head, baseElement, scripts, script, 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) { function isFunction(it) {
return ostring.call(it) === "[object Function]"; return ostring.call(it) === "[object Function]";
@ -323,7 +326,15 @@ var requirejs, require, define;
url = urlMap[normalizedName]; url = urlMap[normalizedName];
if (!url) { if (!url) {
//Calculate url for the module, if it has a name. //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. //Store the URL mapping for later.
urlMap[normalizedName] = url; urlMap[normalizedName] = url;
@ -383,8 +394,8 @@ var requirejs, require, define;
* per module because of the implication of path mappings that may * per module because of the implication of path mappings that may
* need to be relative to the module name. * need to be relative to the module name.
*/ */
function makeRequire(relModuleMap, enableBuildCallback) { function makeRequire(relModuleMap, enableBuildCallback, altRequire) {
var modRequire = makeContextModuleFunc(context.require, relModuleMap, enableBuildCallback); var modRequire = makeContextModuleFunc(altRequire || context.require, relModuleMap, enableBuildCallback);
mixin(modRequire, { mixin(modRequire, {
nameToUrl: makeContextModuleFunc(context.nameToUrl, relModuleMap), nameToUrl: makeContextModuleFunc(context.nameToUrl, relModuleMap),
@ -412,18 +423,19 @@ var requirejs, require, define;
fullName = map.fullName, fullName = map.fullName,
args = manager.deps, args = manager.deps,
listeners = manager.listeners, listeners = manager.listeners,
execCb = config.requireExecCb || req.execCb,
cjsModule; cjsModule;
//Call the callback to define the module, if necessary. //Call the callback to define the module, if necessary.
if (cb && isFunction(cb)) { if (cb && isFunction(cb)) {
if (config.catchError.define) { if (config.catchError.define) {
try { try {
ret = req.execCb(fullName, manager.callback, args, defined[fullName]); ret = execCb(fullName, manager.callback, args, defined[fullName]);
} catch (e) { } catch (e) {
err = e; err = e;
} }
} else { } else {
ret = req.execCb(fullName, manager.callback, args, defined[fullName]); ret = execCb(fullName, manager.callback, args, defined[fullName]);
} }
if (fullName) { if (fullName) {
@ -599,7 +611,22 @@ var requirejs, require, define;
//Use parentName here since the plugin's name is not reliable, //Use parentName here since the plugin's name is not reliable,
//could be some weird string with no path that actually wants to //could be some weird string with no path that actually wants to
//reference the parentName's path. //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 +655,7 @@ var requirejs, require, define;
prefix = map.prefix, prefix = map.prefix,
plugin = prefix ? plugins[prefix] || plugin = prefix ? plugins[prefix] ||
(plugins[prefix] = defined[prefix]) : null, (plugins[prefix] = defined[prefix]) : null,
manager, created, pluginManager; manager, created, pluginManager, prefixMap;
if (fullName) { if (fullName) {
manager = managerCallbacks[fullName]; manager = managerCallbacks[fullName];
@ -666,7 +693,18 @@ var requirejs, require, define;
//If there is a plugin needed, but it is not loaded, //If there is a plugin needed, but it is not loaded,
//first load the plugin, then continue on. //first load the plugin, then continue on.
if (prefix && !plugin) { 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) { pluginManager.add(function (plugin) {
//Create a new manager for the normalized //Create a new manager for the normalized
//resource ID and have it call this manager when //resource ID and have it call this manager when
@ -855,15 +893,62 @@ var requirejs, require, define;
} }
}; };
function forceExec(manager, traced) { function findCycle(manager, traced) {
if (manager.isDone) { var fullName = manager.map.fullName,
return undefined; 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, var fullName = manager.map.fullName,
depArray = manager.depArray, depArray = manager.depArray,
i, depName, depManager, prefix, prefixManager, value; i, depName, depManager, prefix, prefixManager, value;
if (manager.isDone || !fullName || !loaded[fullName]) {
return undefined;
}
if (fullName) { if (fullName) {
if (traced[fullName]) { if (traced[fullName]) {
return defined[fullName]; return defined[fullName];
@ -894,7 +979,7 @@ var requirejs, require, define;
} }
} }
return fullName ? defined[fullName] : undefined; return defined[fullName];
} }
/** /**
@ -907,8 +992,9 @@ var requirejs, require, define;
var waitInterval = config.waitSeconds * 1000, var waitInterval = config.waitSeconds * 1000,
//It is possible to disable the wait interval by using waitSeconds of 0. //It is possible to disable the wait interval by using waitSeconds of 0.
expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(), expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
noLoads = "", hasLoadedProp = false, stillLoading = false, prop, noLoads = "", hasLoadedProp = false, stillLoading = false,
err, manager; cycleDeps = [],
i, prop, err, manager, cycleManager, moduleDeps;
//If there are items still in the paused queue processing wait. //If there are items still in the paused queue processing wait.
//This is particularly important in the sync case where each paused //This is particularly important in the sync case where each paused
@ -938,7 +1024,20 @@ var requirejs, require, define;
noLoads += prop + " "; noLoads += prop + " ";
} else { } else {
stillLoading = true; 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);
}
}
} }
} }
} }
@ -955,9 +1054,26 @@ var requirejs, require, define;
err = makeError("timeout", "Load timeout for modules: " + noLoads); err = makeError("timeout", "Load timeout for modules: " + noLoads);
err.requireType = "timeout"; err.requireType = "timeout";
err.requireModules = noLoads; err.requireModules = noLoads;
err.contextName = context.contextName;
return req.onError(err); 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 //Something is still waiting to load. Wait for it, but only
//if a timeout is not already in effect. //if a timeout is not already in effect.
if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) { if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
@ -1015,6 +1131,9 @@ var requirejs, require, define;
resume = function () { resume = function () {
var manager, map, url, i, p, args, fullName; var manager, map, url, i, p, args, fullName;
//Any defined modules in the global queue, intake them now.
context.takeGlobalQueue();
resumeDepth += 1; resumeDepth += 1;
if (context.scriptCount <= 0) { if (context.scriptCount <= 0) {
@ -1056,7 +1175,7 @@ var requirejs, require, define;
} else { } else {
//Regular dependency. //Regular dependency.
if (!urlFetched[url] && !loaded[fullName]) { if (!urlFetched[url] && !loaded[fullName]) {
req.load(context, fullName, url); (config.requireLoad || req.load)(context, fullName, url);
//Mark the URL as fetched, but only if it is //Mark the URL as fetched, but only if it is
//not an empty: URL, used by the optimizer. //not an empty: URL, used by the optimizer.
@ -1178,8 +1297,7 @@ var requirejs, require, define;
context.requireWait = false; context.requireWait = false;
//But first, call resume to register any defined modules that may //But first, call resume to register any defined modules that may
//be in a data-main built file before the priority config //be in a data-main built file before the priority config
//call. Also grab any waiting define calls for this context. //call.
context.takeGlobalQueue();
resume(); resume();
context.require(cfg.priority); context.require(cfg.priority);
@ -1256,10 +1374,6 @@ var requirejs, require, define;
//then resume the dependency processing. //then resume the dependency processing.
if (!context.requireWait) { if (!context.requireWait) {
while (!context.scriptCount && context.paused.length) { 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(); resume();
} }
} }
@ -1365,7 +1479,8 @@ var requirejs, require, define;
moduleName = normalize(moduleName, relModuleMap && relModuleMap.fullName); moduleName = normalize(moduleName, relModuleMap && relModuleMap.fullName);
//If a colon is in the URL, it indicates a protocol is used and it is just //If a colon is in the URL, it indicates a protocol is used and it is just
//an URL to a file, or if it starts with a slash or ends with .js, it is just a plain file. //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
//or ends with .js, then assume the user meant to use an url and not a module id.
//The slash is important for protocol-less URLs as well as full paths. //The slash is important for protocol-less URLs as well as full paths.
if (req.jsExtRegExp.test(moduleName)) { if (req.jsExtRegExp.test(moduleName)) {
//Just a plain path, not module name lookup, so just return it. //Just a plain path, not module name lookup, so just return it.
@ -1401,7 +1516,7 @@ var requirejs, require, define;
//Join the path parts together, then figure out if baseUrl is needed. //Join the path parts together, then figure out if baseUrl is needed.
url = syms.join("/") + (ext || ".js"); url = syms.join("/") + (ext || ".js");
url = (url.charAt(0) === '/' || url.match(/^\w+:/) ? "" : config.baseUrl) + url; url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? "" : config.baseUrl) + url;
} }
return config.urlArgs ? url + return config.urlArgs ? url +
@ -1737,7 +1852,8 @@ var requirejs, require, define;
node = context && context.config && context.config.xhtml ? node = context && context.config && context.config.xhtml ?
document.createElementNS("http://www.w3.org/1999/xhtml", "html:script") : document.createElementNS("http://www.w3.org/1999/xhtml", "html:script") :
document.createElement("script"); document.createElement("script");
node.type = type || "text/javascript"; node.type = type || (context && context.config.scriptType) ||
"text/javascript";
node.charset = "utf-8"; node.charset = "utf-8";
//Use async so Gecko does not block on executing the script if something //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 //like a long-polling comet tag is being run first. Gecko likes
@ -1764,7 +1880,15 @@ var requirejs, require, define;
//https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
//UNFORTUNATELY Opera implements attachEvent but does not follow the script //UNFORTUNATELY Opera implements attachEvent but does not follow the script
//script execution mode. //script execution mode.
if (node.attachEvent && !isOpera) { if (node.attachEvent &&
// check if node.attachEvent is artificially added by custom script or
// natively supported by browser
// read https://github.com/jrburke/requirejs/issues/187
// if we can NOT find [native code] then it must NOT natively supported.
// in IE8, node.attachEvent does not have toString()
// TODO: a better way to check interactive mode
!(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code]') < 0) &&
!isOpera) {
//Probably IE. IE (at least 6-8) do not fire //Probably IE. IE (at least 6-8) do not fire
//script onload right after executing the script, so //script onload right after executing the script, so
//we cannot tie the anonymous define call to a name. //we cannot tie the anonymous define call to a name.
@ -1822,7 +1946,7 @@ var requirejs, require, define;
//Figure out baseUrl. Get it from the script tag with require.js in it. //Figure out baseUrl. Get it from the script tag with require.js in it.
scripts = document.getElementsByTagName("script"); 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 //Set the "head" where we can append children by
//using the script's parent. //using the script's parent.
if (!head) { if (!head) {
@ -1930,10 +2054,6 @@ var requirejs, require, define;
setTimeout(function () { setTimeout(function () {
ctx.requireWait = false; 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) { if (!ctx.scriptCount) {
ctx.resume(); ctx.resume();
} }