From 81bea17aefb26859f825b9293c7c99192874806e Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 8 Nov 2011 20:40:44 +0400 Subject: upgrade Dojo to 1.6.1 --- lib/dojo/_base/_loader/bootstrap.js | 33 ++--- lib/dojo/_base/_loader/hostenv_browser.js | 37 +++--- lib/dojo/_base/_loader/hostenv_ff_ext.js | 6 +- lib/dojo/_base/_loader/hostenv_rhino.js | 20 ++- lib/dojo/_base/_loader/hostenv_spidermonkey.js | 22 ++-- lib/dojo/_base/_loader/loader.js | 176 +++++++++++++------------ lib/dojo/_base/_loader/loader_debug.js | 2 +- lib/dojo/_base/_loader/loader_xd.js | 40 +++--- 8 files changed, 181 insertions(+), 155 deletions(-) (limited to 'lib/dojo/_base/_loader') diff --git a/lib/dojo/_base/_loader/bootstrap.js b/lib/dojo/_base/_loader/bootstrap.js index 3ef3012a2..a1f99276a 100644 --- a/lib/dojo/_base/_loader/bootstrap.js +++ b/lib/dojo/_base/_loader/bootstrap.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -76,7 +76,7 @@ djConfig = { // of calling `dojo.registerModulePath("foo", "../../bar");`. Multiple // modules may be configured via `djConfig.modulePaths`. modulePaths: {}, - // afterOnLoad: Boolean + // afterOnLoad: Boolean // Indicates Dojo was added to the page after the page load. In this case // Dojo will not wait for the page DOMContentLoad/load events and fire // its dojo.addOnLoad callbacks after making sure all outstanding @@ -103,7 +103,7 @@ djConfig = { // dojoBlankHtmlUrl: String // Used by some modules to configure an empty iframe. Used by dojo.io.iframe and // dojo.back, and dijit popup support in IE where an iframe is needed to make sure native - // controls do not bleed through the popups. Normally this configuration variable + // controls do not bleed through the popups. Normally this configuration variable // does not need to be set, except when using cross-domain/CDN Dojo builds. // Save dojo/resources/blank.html to your domain and set `djConfig.dojoBlankHtmlUrl` // to the path on your domain your copy of blank.html. @@ -149,7 +149,7 @@ djConfig = { "groupEnd", "info", "profile", "profileEnd", "time", "timeEnd", "trace", "warn", "log" ]; - var i=0, tn; + var i = 0, tn; while((tn=cn[i++])){ if(!console[tn]){ (function(){ @@ -209,9 +209,13 @@ dojo.global = { debugAtAllCosts: false }; - if(typeof djConfig != "undefined"){ - for(var opt in djConfig){ - d.config[opt] = djConfig[opt]; + // FIXME: 2.0, drop djConfig support. Use dojoConfig exclusively for global config. + var cfg = typeof djConfig != "undefined" ? djConfig : + typeof dojoConfig != "undefined" ? dojoConfig : null; + + if(cfg){ + for(var c in cfg){ + d.config[c] = cfg[c]; } } @@ -223,7 +227,7 @@ dojo.global = { =====*/ dojo.locale = d.config.locale; - var rev = "$Rev: 22487 $".match(/\d+/); + var rev = "$Rev: 24595 $".match(/\d+/); /*===== dojo.version = function(){ @@ -247,7 +251,7 @@ dojo.global = { } =====*/ dojo.version = { - major: 1, minor: 5, patch: 0, flag: "", + major: 1, minor: 6, patch: 1, flag: "", revision: rev ? +rev[0] : NaN, toString: function(){ with(d.version){ @@ -323,7 +327,7 @@ dojo.global = { // | constructor: function(properties){ // | // property configuration: // | dojo.mixin(this, properties); - // | + // | // | console.log(this.quip); // | // ... // | }, @@ -344,7 +348,7 @@ dojo.global = { // | name: "Carl Brutanananadilewski" // | } // | ); - // | + // | // | // will print "Carl Brutanananadilewski" // | console.log(flattened.name); // | // will print "true" @@ -419,10 +423,7 @@ dojo.global = { // determine if an object supports a given method // description: // useful for longer api chains where you have to test each object in - // the chain. Useful only for object and method detection. - // Not useful for testing generic properties on an object. - // In particular, dojo.exists("foo.bar") when foo.bar = "" - // will return false. Use ("bar" in foo) to test for those cases. + // the chain. Useful for object and method detection. // name: // Path to an object, in the form "A.B.C". // obj: @@ -441,7 +442,7 @@ dojo.global = { // | // search from a particular scope // | dojo.exists("bar", foo); // true // | dojo.exists("bar.baz", foo); // false - return !!d.getObject(name, false, obj); // Boolean + return d.getObject(name, false, obj) !== undefined; // Boolean } dojo["eval"] = function(/*String*/ scriptFragment){ diff --git a/lib/dojo/_base/_loader/hostenv_browser.js b/lib/dojo/_base/_loader/hostenv_browser.js index 7d92d70e3..b31bd77dc 100644 --- a/lib/dojo/_base/_loader/hostenv_browser.js +++ b/lib/dojo/_base/_loader/hostenv_browser.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -26,9 +26,9 @@ dojo.isIE = { dojo.isSafari = { // example: // | if(dojo.isSafari){ ... } - // example: + // example: // Detect iPhone: - // | if(dojo.isSafari && navigator.userAgent.indexOf("iPhone") != -1){ + // | if(dojo.isSafari && navigator.userAgent.indexOf("iPhone") != -1){ // | // we are iPhone. Note, iPod touch reports "iPod" above and fails this test. // | } }; @@ -71,7 +71,6 @@ dojo = { // True if the client runs on Mac } =====*/ - if(typeof window != 'undefined'){ dojo.isBrowser = true; dojo._name = "browser"; @@ -98,7 +97,7 @@ if(typeof window != 'undefined'){ d.config.baseUrl = src.substring(0, m.index); } // and find out if we need to modify our behavior - var cfg = scripts[i].getAttribute("djConfig"); + var cfg = (scripts[i].getAttribute("djConfig") || scripts[i].getAttribute("data-dojo-config")); if(cfg){ var cfgo = eval("({ "+cfg+" })"); for(var x in cfgo){ @@ -172,7 +171,7 @@ if(typeof window != 'undefined'){ d._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0']; d._xhrObj = function(){ - // summary: + // summary: // does the work of portably generating a new XMLHTTPRequest object. var http, last_e; if(!dojo.isIE || !dojo.config.ieForceActiveXXhr){ @@ -205,10 +204,11 @@ if(typeof window != 'undefined'){ var stat = http.status || 0, lp = location.protocol; return (stat >= 200 && stat < 300) || // Boolean - stat == 304 || // allow any 2XX response code - stat == 1223 || // get it out of the cache + stat == 304 || // allow any 2XX response code + stat == 1223 || // get it out of the cache + // Internet Explorer mangled the status code // Internet Explorer mangled the status code OR we're Titanium/browser chrome/chrome extension requesting a local file - (!stat && (lp == "file:" || lp == "chrome:" || lp == "chrome-extension:" || lp == "app:") ); + (!stat && (lp == "file:" || lp == "chrome:" || lp == "chrome-extension:" || lp == "app:")); } //See if base tag is in use. @@ -303,7 +303,7 @@ if(typeof window != 'undefined'){ d.addOnWindowUnload = function(/*Object?|Function?*/obj, /*String|Function?*/functionName){ // summary: // registers a function to be triggered when window.onunload - // fires. + // fires. // description: // The first time that addOnWindowUnload is called Dojo // will register a page listener to trigger your unload @@ -334,7 +334,7 @@ if(typeof window != 'undefined'){ // description: // The first time that addOnUnload is called Dojo will // register a page listener to trigger your unload handler - // with. + // with. // // In a browser enviroment, the functions will be triggered // during the window.onbeforeunload event. Be careful of doing @@ -347,7 +347,7 @@ if(typeof window != 'undefined'){ // // Further note that calling dojo.addOnUnload will prevent // browsers from using a "fast back" cache to make page - // loading via back button instantaneous. + // loading via back button instantaneous. // example: // | dojo.addOnUnload(functionPointer) // | dojo.addOnUnload(object, "functionName") @@ -384,7 +384,7 @@ if(typeof window != 'undefined'){ } } - if(!dojo.config.afterOnLoad){ + if(!dojo.config.afterOnLoad){ if(document.addEventListener){ //Standards. Hooray! Assumption here that if standards based, //it knows about DOMContentLoaded. It is OK if it does not, the fall through @@ -401,10 +401,10 @@ if(typeof window != 'undefined'){ if(!dojo.config.skipIeDomLoaded && self === self.top){ dojo._scrollIntervalId = setInterval(function (){ try{ - //When dojo is loaded into an iframe in an IE HTML Application + //When dojo is loaded into an iframe in an IE HTML Application //(HTA), such as in a selenium test, javascript in the iframe //can't see anything outside of it, so self===self.top is true, - //but the iframe is not the top window and doScroll will be + //but the iframe is not the top window and doScroll will be //available before document.body is set. Test document.body //before trying the doScroll trick if(document.body){ @@ -467,8 +467,11 @@ if(dojo.config.isDebug){ } if(dojo.config.debugAtAllCosts){ - dojo.config.useXDomain = true; - dojo.require("dojo._base._loader.loader_xd"); + // this breaks the new AMD based module loader. The XDomain won't be necessary + // anyway if you switch to the asynchronous loader + //dojo.config.useXDomain = true; + //dojo.require("dojo._base._loader.loader_xd"); dojo.require("dojo._base._loader.loader_debug"); dojo.require("dojo.i18n"); } + diff --git a/lib/dojo/_base/_loader/hostenv_ff_ext.js b/lib/dojo/_base/_loader/hostenv_ff_ext.js index 94a0a8046..ca47a4c1c 100644 --- a/lib/dojo/_base/_loader/hostenv_ff_ext.js +++ b/lib/dojo/_base/_loader/hostenv_ff_ext.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -241,7 +241,7 @@ if(typeof window != 'undefined'){ return oc; }; - // FIXME: + // FIXME: // don't really like the current arguments and order to // _inContext, so don't make it public until it's right! dojo._inContext = function(g, d, f){ @@ -302,7 +302,7 @@ if(typeof window != 'undefined'){ // Dojo's to fire once..but we might care if pages navigate. We'll // probably need an extension-specific API if(!dojo.config.afterOnLoad){ - window.addEventListener("DOMContentLoaded",function(e){ + window.addEventListener("DOMContentLoaded",function(e){ dojo._loadInit(e); // console.log("DOM content loaded", e); }, false); diff --git a/lib/dojo/_base/_loader/hostenv_rhino.js b/lib/dojo/_base/_loader/hostenv_rhino.js index ee9ad8b43..e3aa78524 100644 --- a/lib/dojo/_base/_loader/hostenv_rhino.js +++ b/lib/dojo/_base/_loader/hostenv_rhino.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -58,6 +58,9 @@ dojo._isLocalUrl = function(/*String*/ uri) { // see comments in spidermonkey loadUri dojo._loadUri = function(uri, cb){ + if(dojo._loadedUrls[uri]){ + return true; // Boolean + } try{ var local; try{ @@ -67,29 +70,32 @@ dojo._loadUri = function(uri, cb){ return false; } + dojo._loadedUrls[uri] = true; //FIXME: Use Rhino 1.6 native readFile/readUrl if available? if(cb){ var contents = (local ? readText : readUri)(uri, "UTF-8"); // patch up the input to eval until https://bugzilla.mozilla.org/show_bug.cgi?id=471005 is fixed. if(!eval("'\u200f'").length){ - contents = String(contents).replace(/[\u200E\u200F\u202A-\u202E]/g, function(match){ - return "\\u" + match.charCodeAt(0).toString(16); + contents = String(contents).replace(/[\u200E\u200F\u202A-\u202E]/g, function(match){ + return "\\u" + match.charCodeAt(0).toString(16); }) } - - cb(eval('('+contents+')')); + contents = /^define\(/.test(contents) ? contents : '('+contents+')'; + cb(eval(contents)); }else{ load(uri); } + dojo._loadedUrls.push(uri); return true; }catch(e){ + dojo._loadedUrls[uri] = false; console.debug("rhino load('" + uri + "') failed. Exception: " + e); return false; } } -dojo.exit = function(exitcode){ +dojo.exit = function(exitcode){ quit(exitcode); } @@ -157,7 +163,7 @@ dojo._getText = function(/*URI*/ uri, /*Boolean*/ fail_ok){ dojo.doc = typeof document != "undefined" ? document : null; dojo.body = function(){ - return document.body; + return document.body; } // Supply setTimeout/clearTimeout implementations if they aren't already there diff --git a/lib/dojo/_base/_loader/hostenv_spidermonkey.js b/lib/dojo/_base/_loader/hostenv_spidermonkey.js index 17b21f5f0..a3d2dfc6f 100644 --- a/lib/dojo/_base/_loader/hostenv_spidermonkey.js +++ b/lib/dojo/_base/_loader/hostenv_spidermonkey.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -19,13 +19,13 @@ dojo._name = 'spidermonkey'; /*===== dojo.isSpidermonkey = { - // summary: Detect spidermonkey + // summary: Detect spidermonkey }; =====*/ dojo.isSpidermonkey = true; -dojo.exit = function(exitcode){ - quit(exitcode); +dojo.exit = function(exitcode){ + quit(exitcode); } if(typeof print == "function"){ @@ -37,15 +37,15 @@ if(typeof line2pc == 'undefined'){ } dojo._spidermonkeyCurrentFile = function(depth){ - // + // // This is a hack that determines the current script file by parsing a // generated stack trace (relying on the non-standard "stack" member variable // of the SpiderMonkey Error object). - // + // // If param depth is passed in, it'll return the script file which is that far down // the stack, but that does require that you know how deep your stack is when you are // calling. - // + // var s = ''; try{ throw Error("whatever"); @@ -54,23 +54,23 @@ dojo._spidermonkeyCurrentFile = function(depth){ } // lines are like: bu_getCurrentScriptURI_spidermonkey("ScriptLoader.js")@burst/Runtime.js:101 var matches = s.match(/[^@]*\.js/gi); - if(!matches){ + if(!matches){ throw Error("could not parse stack string: '" + s + "'"); } var fname = (typeof depth != 'undefined' && depth) ? matches[depth + 1] : matches[matches.length - 1]; - if(!fname){ + if(!fname){ throw Error("could not find file name in stack string '" + s + "'"); } //print("SpiderMonkeyRuntime got fname '" + fname + "' from stack string '" + s + "'"); return fname; } -// print(dojo._spidermonkeyCurrentFile(0)); +// print(dojo._spidermonkeyCurrentFile(0)); dojo._loadUri = function(uri){ // spidermonkey load() evaluates the contents into the global scope (which // is what we want). - // TODO: sigh, load() does not return a useful value. + // TODO: sigh, load() does not return a useful value. // Perhaps it is returning the value of the last thing evaluated? var ok = load(uri); // console.log("spidermonkey load(", uri, ") returned ", ok); diff --git a/lib/dojo/_base/_loader/loader.js b/lib/dojo/_base/_loader/loader.js index 9206de888..73df544fa 100644 --- a/lib/dojo/_base/_loader/loader.js +++ b/lib/dojo/_base/_loader/loader.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -11,9 +11,8 @@ dojo._hasResource["dojo.foo"] = true; * loader.js - A bootstrap module. Runs before the hostenv_*.js file. Contains * all of the package loading methods. */ - (function(){ - var d = dojo; + var d = dojo, currentModule; d.mixin(d, { _loadedModules: {}, @@ -45,11 +44,11 @@ dojo._hasResource["dojo.foo"] = true; _loadedUrls: [], - //WARNING: + //WARNING: // This variable is referenced by packages outside of bootstrap: // FloatingPane.js and undo/browser.js _postLoad: false, - + //Egad! Lots of test files push on this directly instead of using dojo.addOnLoad. _loaders: [], _unloaders: [], @@ -68,21 +67,24 @@ dojo._hasResource["dojo.foo"] = true; // not caught by us, so the caller will see it. We return a true // value if and only if the script is found. // - // relpath: + // relpath: // A relative path to a script (no leading '/', and typically ending // in '.js'). - // module: + // module: // A module whose existance to check for after loading a path. Can be // used to determine success or failure of the load. - // cb: + // cb: // a callback function to pass the result of evaluating the script var uri = ((relpath.charAt(0) == '/' || relpath.match(/^\w+:/)) ? "" : d.baseUrl) + relpath; try{ + currentModule = module; return !module ? d._loadUri(uri, cb) : d._loadUriAndCheck(uri, module, cb); // Boolean }catch(e){ console.error(e); return false; // Boolean + }finally{ + currentModule = null; } } @@ -95,7 +97,7 @@ dojo._hasResource["dojo.foo"] = true; // it succeeded. Returns false if the URI reading failed. Throws if // the evaluation throws. // uri: a uri which points at the script to be loaded - // cb: + // cb: // a callback function to process the result of evaluating the script // as an expression, typically used by the resource bundle loader to // load JSON-style resources @@ -109,7 +111,8 @@ dojo._hasResource["dojo.foo"] = true; d._loadedUrls[uri] = true; d._loadedUrls.push(uri); if(cb){ - contents = '('+contents+')'; + //conditional to support script-inject i18n bundle format + contents = /^define\(/.test(contents) ? contents : '('+contents+')'; }else{ //Only do the scoping if no callback. If a callback is specified, //it is most likely the i18n bundle stuff. @@ -121,16 +124,16 @@ dojo._hasResource["dojo.foo"] = true; } // Check to see if we need to call _callLoaded() due to an addOnLoad() that arrived while we were busy downloading if(--d._inFlightCount == 0 && d._postLoad && d._loaders.length){ - // We shouldn't be allowed to get here but Firefox allows an event - // (mouse, keybd, async xhrGet) to interrupt a synchronous xhrGet. + // We shouldn't be allowed to get here but Firefox allows an event + // (mouse, keybd, async xhrGet) to interrupt a synchronous xhrGet. // If the current script block contains multiple require() statements, then after each // require() returns, inFlightCount == 0, but we want to hold the _callLoaded() until // all require()s are done since the out-of-sequence addOnLoad() presumably needs them all. // setTimeout allows the next require() to start (if needed), and then we check this again. - setTimeout(function(){ - // If inFlightCount > 0, then multiple require()s are running sequentially and + setTimeout(function(){ + // If inFlightCount > 0, then multiple require()s are running sequentially and // the next require() started after setTimeout() was executed but before we got here. - if(d._inFlightCount == 0){ + if(d._inFlightCount == 0){ d._callLoaded(); } }, 0); @@ -153,10 +156,10 @@ dojo._hasResource["dojo.foo"] = true; dojo.loaded = function(){ // summary: // signal fired when initial environment and package loading is - // complete. You should use dojo.addOnLoad() instead of doing a + // complete. You should use dojo.addOnLoad() instead of doing a // direct dojo.connect() to this method in order to handle // initialization tasks that require the environment to be - // initialized. In a browser host, declarative widgets will + // initialized. In a browser host, declarative widgets will // be constructed when this function finishes runing. d._loadNotifying = true; d._postLoad = true; @@ -183,8 +186,8 @@ dojo._hasResource["dojo.foo"] = true; dojo.unloaded = function(){ // summary: // signal fired by impending environment destruction. You should use - // dojo.addOnUnload() instead of doing a direct dojo.connect() to this - // method to perform page/application cleanup methods. See + // dojo.addOnUnload() instead of doing a direct dojo.connect() to this + // method to perform page/application cleanup methods. See // dojo.addOnUnload for more info. var mll = d._unloaders; while(mll.length){ @@ -203,13 +206,13 @@ dojo._hasResource["dojo.foo"] = true; dojo.ready = dojo.addOnLoad = function(/*Object*/obj, /*String|Function?*/functionName){ // summary: - // Registers a function to be triggered after the DOM and dojo.require() calls + // Registers a function to be triggered after the DOM and dojo.require() calls // have finished loading. // // description: // Registers a function to be triggered after the DOM has finished - // loading and `dojo.require` modules have loaded. Widgets declared in markup - // have been instantiated if `djConfig.parseOnLoad` is true when this fires. + // loading and `dojo.require` modules have loaded. Widgets declared in markup + // have been instantiated if `djConfig.parseOnLoad` is true when this fires. // // Images and CSS files may or may not have finished downloading when // the specified function is called. (Note that widgets' CSS and HTML @@ -252,7 +255,7 @@ dojo._hasResource["dojo.foo"] = true; dojo._modulesLoaded = function(){ if(d._postLoad){ return; } - if(d._inFlightCount > 0){ + if(d._inFlightCount > 0){ console.warn("files still in flight!"); return; } @@ -284,8 +287,8 @@ dojo._hasResource["dojo.foo"] = true; var syms = modulename.split("."); for(var i = syms.length; i>0; i--){ var parentModule = syms.slice(0, i).join("."); - if(i == 1 && !d._moduleHasPrefix(parentModule)){ - // Support default module directory (sibling of dojo) for top-level modules + if(i == 1 && !d._moduleHasPrefix(parentModule)){ + // Support default module directory (sibling of dojo) for top-level modules syms[0] = "../" + syms[0]; }else{ var parentModulePath = d._getModulePrefix(parentModule); @@ -320,87 +323,95 @@ dojo._hasResource["dojo.foo"] = true; dojo._loadModule = dojo.require = function(/*String*/moduleName, /*Boolean?*/omitModuleCheck){ // summary: // loads a Javascript module from the appropriate URI - // moduleName: + // + // moduleName: String // module name to load, using periods for separators, // e.g. "dojo.date.locale". Module paths are de-referenced by dojo's // internal mapping of locations to names and are disambiguated by // longest prefix. See `dojo.registerModulePath()` for details on // registering new modules. - // omitModuleCheck: + // + // omitModuleCheck: Boolean? // if `true`, omitModuleCheck skips the step of ensuring that the // loaded file actually defines the symbol it is referenced by. // For example if it called as `dojo.require("a.b.c")` and the // file located at `a/b/c.js` does not define an object `a.b.c`, // and exception will be throws whereas no exception is raised // when called as `dojo.require("a.b.c", true)` + // // description: // Modules are loaded via dojo.require by using one of two loaders: the normal loader // and the xdomain loader. The xdomain loader is used when dojo was built with a // custom build that specified loader=xdomain and the module lives on a modulePath // that is a whole URL, with protocol and a domain. The versions of Dojo that are on // the Google and AOL CDNs use the xdomain loader. - // + // // If the module is loaded via the xdomain loader, it is an asynchronous load, since // the module is added via a dynamically created script tag. This - // means that dojo.require() can return before the module has loaded. However, this + // means that dojo.require() can return before the module has loaded. However, this // should only happen in the case where you do dojo.require calls in the top-level // HTML page, or if you purposely avoid the loader checking for dojo.require // dependencies in your module by using a syntax like dojo["require"] to load the module. - // + // // Sometimes it is useful to not have the loader detect the dojo.require calls in the // module so that you can dynamically load the modules as a result of an action on the // page, instead of right at module load time. - // + // // Also, for script blocks in an HTML page, the loader does not pre-process them, so // it does not know to download the modules before the dojo.require calls occur. - // + // // So, in those two cases, when you want on-the-fly module loading or for script blocks // in the HTML page, special care must be taken if the dojo.required code is loaded // asynchronously. To make sure you can execute code that depends on the dojo.required // modules, be sure to add the code that depends on the modules in a dojo.addOnLoad() // callback. dojo.addOnLoad waits for all outstanding modules to finish loading before - // executing. Example: - // - // | - // + // executing. + // // This type of syntax works with both xdomain and normal loaders, so it is good // practice to always use this idiom for on-the-fly code loading and in HTML script // blocks. If at some point you change loaders and where the code is loaded from, // it will all still work. - // + // // More on how dojo.require // `dojo.require("A.B")` first checks to see if symbol A.B is // defined. If it is, it is simply returned (nothing to do). - // + // // If it is not defined, it will look for `A/B.js` in the script root // directory. - // - // `dojo.require` throws an excpetion if it cannot find a file + // + // `dojo.require` throws an exception if it cannot find a file // to load, or if the symbol `A.B` is not defined after loading. - // + // // It returns the object `A.B`, but note the caveats above about on-the-fly loading and // HTML script blocks when the xdomain loader is loading a module. - // + // // `dojo.require()` does nothing about importing symbols into // the current namespace. It is presumed that the caller will - // take care of that. For example, to import all symbols into a - // local block, you might write: - // + // take care of that. + // + // example: + // To use dojo.require in conjunction with dojo.ready: + // + // | dojo.require("foo"); + // | dojo.require("bar"); + // | dojo.addOnLoad(function(){ + // | //you can now safely do something with foo and bar + // | }); + // + // example: + // For example, to import all symbols into a local block, you might write: + // // | with (dojo.require("A.B")) { // | ... // | } - // + // // And to import just the leaf symbol to a local variable: - // + // // | var B = dojo.require("A.B"); // | ... - // returns: the required namespace object + // + // returns: + // the required namespace object omitModuleCheck = d._global_omit_module_check || omitModuleCheck; //Check if it is already loaded. @@ -411,10 +422,8 @@ dojo._hasResource["dojo.foo"] = true; // convert periods to slashes var relpath = d._getModuleSymbols(moduleName).join("/") + '.js'; - var modArg = !omitModuleCheck ? moduleName : null; var ok = d._loadPath(relpath, modArg); - if(!ok && !omitModuleCheck){ throw new Error("Could not load '" + moduleName + "'; last tried '" + relpath + "'"); } @@ -425,7 +434,7 @@ dojo._hasResource["dojo.foo"] = true; // pass in false so we can give better error module = d._loadedModules[moduleName]; if(!module){ - throw new Error("symbol '" + moduleName + "' is not defined after loading '" + relpath + "'"); + throw new Error("symbol '" + moduleName + "' is not defined after loading '" + relpath + "'"); } } @@ -446,14 +455,14 @@ dojo._hasResource["dojo.foo"] = true; // the file name. For example, `js/dojo/foo.js` must have // `dojo.provide("dojo.foo");` before any calls to // `dojo.require()` are made. - // + // // For backwards compatibility reasons, in addition to registering // the resource, `dojo.provide()` also ensures that the javascript // object for the module exists. For example, // `dojo.provide("dojox.data.FlickrStore")`, in addition to // registering that `FlickrStore.js` is a resource for the // `dojox.data` module, will ensure that the `dojox.data` - // javascript object exists, so that calls like + // javascript object exists, so that calls like // `dojo.data.foo = function(){ ... }` don't fail. // // In the case of a build where multiple javascript source files @@ -462,11 +471,11 @@ dojo._hasResource["dojo.foo"] = true; // note that it includes multiple resources. // // resourceName: String - // A dot-sperated string identifying a resource. + // A dot-sperated string identifying a resource. // // example: // Safely create a `my` object, and make dojo.require("my.CustomModule") work - // | dojo.provide("my.CustomModule"); + // | dojo.provide("my.CustomModule"); //Make sure we have a string. resourceName = resourceName + ""; @@ -523,7 +532,7 @@ dojo._hasResource["dojo.foo"] = true; if(condition === true){ // FIXME: why do we support chained require()'s here? does the build system? var args = []; - for(var i = 1; i < arguments.length; i++){ + for(var i = 1; i < arguments.length; i++){ args.push(arguments[i]); } d.require.apply(d, args); @@ -533,13 +542,13 @@ dojo._hasResource["dojo.foo"] = true; dojo.requireAfterIf = d.requireIf; dojo.registerModulePath = function(/*String*/module, /*String*/prefix){ - // summary: + // summary: // Maps a module name to a path - // description: + // description: // An unregistered module is given the default path of ../[module], // relative to Dojo root. For example, module acme is mapped to // ../acme. If you want to use a different module name, use - // dojo.registerModulePath. + // dojo.registerModulePath. // example: // If your dojo.js is located at this location in the web root: // | /myapp/js/dojo/dojo/dojo.js @@ -552,7 +561,7 @@ dojo._hasResource["dojo.foo"] = true; // At which point you can then use dojo.require() to load the // modules (assuming they provide() the same things which are // required). The full code might be: - // | // | d._modulePrefixes[module] = { name: module, value: prefix }; - } - + }; + dojo.requireLocalization = function(/*String*/moduleName, /*String*/bundleName, /*String?*/locale, /*String?*/availableFlatLocales){ // summary: // Declares translated resources and loads them if necessary, in the @@ -573,7 +582,7 @@ dojo._hasResource["dojo.foo"] = true; // description: // Load translated resource bundles provided underneath the "nls" // directory within a package. Translated resources may be located in - // different packages throughout the source tree. + // different packages throughout the source tree. // // Each directory is named for a locale as specified by RFC 3066, // (http://www.ietf.org/rfc/rfc3066.txt), normalized in lowercase. @@ -588,21 +597,21 @@ dojo._hasResource["dojo.foo"] = true; // preload the bundles to avoid data redundancy and the multiple // network hits normally required to load these resources. // - // moduleName: + // moduleName: // name of the package containing the "nls" directory in which the // bundle is found // - // bundleName: + // bundleName: // bundle name, i.e. the filename without the '.js' suffix. Using "nls" as a // a bundle name is not supported, since "nls" is the name of the folder // that holds bundles. Using "nls" as the bundle name will cause problems // with the custom build. // - // locale: + // locale: // the locale to load (optional) By default, the browser's user // locale as defined by dojo.locale // - // availableFlatLocales: + // availableFlatLocales: // A comma-separated list of the available, flattened locales for this // bundle. This argument should only be set by the build process. // @@ -644,11 +653,11 @@ dojo._hasResource["dojo.foo"] = true; ire = new RegExp("^((([^\\[:]+):)?([^@]+)@)?(\\[([^\\]]+)\\]|([^\\[:]*))(:([0-9]+))?$"); dojo._Url = function(/*dojo._Url|String...*/){ - // summary: + // summary: // Constructor to create an object representing a URL. // It is marked as private, since we might consider removing // or simplifying it. - // description: + // description: // Each argument is evaluated in order relative to the next until // a canonical uri is produced. To get an absolute Uri relative to // the current document use: @@ -715,7 +724,7 @@ dojo._hasResource["dojo.foo"] = true; } uri = []; - if(relobj.scheme){ + if(relobj.scheme){ uri.push(relobj.scheme, ":"); } if(relobj.authority){ @@ -755,7 +764,7 @@ dojo._hasResource["dojo.foo"] = true; dojo._Url.prototype.toString = function(){ return this.uri; }; dojo.moduleUrl = function(/*String*/module, /*dojo._Url||String*/url){ - // summary: + // summary: // Returns a `dojo._Url` object relative to a module. // example: // | var pngPath = dojo.moduleUrl("acme","images/small.png"); @@ -763,10 +772,10 @@ dojo._hasResource["dojo.foo"] = true; // | // create an image and set it's source to pngPath's value: // | var img = document.createElement("img"); // | // NOTE: we assign the string representation of the url object - // | img.src = pngPath.toString(); + // | img.src = pngPath.toString(); // | // add our image to the document // | dojo.body().appendChild(img); - // example: + // example: // you may de-reference as far as you like down the package // hierarchy. This is sometimes handy to avoid lenghty relative // urls or for building portable sub-packages. In this example, @@ -777,9 +786,9 @@ dojo._hasResource["dojo.foo"] = true; // | // somewhere in a configuration block // | dojo.registerModulePath("acme.widget", "../../acme/widget"); // | dojo.registerModulePath("acme.util", "../../util"); - // | + // | // | // ... - // | + // | // | // code in a module using acme resources // | var tmpltPath = dojo.moduleUrl("acme.widget","templates/template.html"); // | var dataPath = dojo.moduleUrl("acme.util","resources/data.json"); @@ -798,7 +807,10 @@ dojo._hasResource["dojo.foo"] = true; } return new d._Url(loc, url); // dojo._Url - } + }; + + + })(); } diff --git a/lib/dojo/_base/_loader/loader_debug.js b/lib/dojo/_base/_loader/loader_debug.js index fa26d8efb..f2043e4de 100644 --- a/lib/dojo/_base/_loader/loader_debug.js +++ b/lib/dojo/_base/_loader/loader_debug.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ diff --git a/lib/dojo/_base/_loader/loader_xd.js b/lib/dojo/_base/_loader/loader_xd.js index c60b86b05..e59f814c0 100644 --- a/lib/dojo/_base/_loader/loader_xd.js +++ b/lib/dojo/_base/_loader/loader_xd.js @@ -1,5 +1,5 @@ /* - Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved. + Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved. Available via Academic Free License >= 2.1 OR the modified BSD license. see: http://dojotoolkit.org/license for details */ @@ -170,23 +170,27 @@ dojo._xdIsXDomainPath = function(/*string*/relpath) { var colonIndex = relpath.indexOf(":"); var slashIndex = relpath.indexOf("/"); - if(colonIndex > 0 && colonIndex < slashIndex){ + if(colonIndex > 0 && colonIndex < slashIndex || relpath.indexOf("//") === 0){ return true; }else{ //Is the base script URI-based URL a cross domain URL? //If so, then the relpath will be evaluated relative to //baseUrl, and therefore qualify as xdomain. //Only treat it as xdomain if the page does not have a - //host (file:// url) or if the baseUrl does not match the - //current window's domain. + //host (file:// url), if the baseUrl does not match the + //current window's domain, or if the baseUrl starts with //. + //If baseUrl starts with // then it probably means that xdomain + //is wanted since it is such a specific path request. This is not completely robust, + //but something more robust would require normalizing the protocol on baseUrl and on the location + //to see if they differ. However, that requires more code, and // as a start path is unusual. var url = dojo.baseUrl; colonIndex = url.indexOf(":"); slashIndex = url.indexOf("/"); - if(colonIndex > 0 && colonIndex < slashIndex && (!location.host || url.indexOf("http://" + location.host) != 0)){ + if(url.indexOf("//") === 0 || (colonIndex > 0 && colonIndex < slashIndex && (!location.host || url.indexOf("http://" + location.host) != 0))){ return true; } } - return false; + return false; } dojo._loadPath = function(/*String*/relpath, /*String?*/module, /*Function?*/cb){ @@ -218,8 +222,8 @@ dojo._loadUri = function(/*String*/uri, /*Function?*/cb, /*boolean*/currentIsXDo } //Add the module (resource) to the list of modules. - //Only do this work if we have a modlue name. Otherwise, - //it is a non-xd i18n bundle, which can load immediately and does not + //Only do this work if we have a modlue name. Otherwise, + //it is a non-xd i18n bundle, which can load immediately and does not //need to be tracked. Also, don't track dojo.i18n, since it is a prerequisite //and will be loaded correctly if we load it right away: it has no dependencies. if(dojo._isXDomain && module && module != "dojo.i18n"){ @@ -386,7 +390,7 @@ dojo._xdResourceLoaded = function(/*Object*/res){ } //Now update the inflight status for any provided resources in this loaded resource. - //Do this at the very end (in a *separate* for loop) to avoid shutting down the + //Do this at the very end (in a *separate* for loop) to avoid shutting down the //inflight timer check too soon. for(i = 0; i < provideList.length; i++){ dojo._xdInFlight[provideList[i]] = false; @@ -490,7 +494,7 @@ dojo.xdRequireLocalization = function(/*String*/moduleName, /*String*/bundleName // Replace dojo.requireLocalization with a wrapper dojo._xdRealRequireLocalization = dojo.requireLocalization; dojo.requireLocalization = function(/*String*/moduleName, /*String*/bundleName, /*String?*/locale, /*String*/availableFlatLocales){ - // summary: loads a bundle intelligently based on whether the module is + // summary: loads a bundle intelligently based on whether the module is // local or xd. Overrides the local-case implementation. var modulePath = dojo.moduleUrl(moduleName).toString(); @@ -525,7 +529,7 @@ dojo._xdUnpackDependency = function(/*Array*/dep){ case "platformRequire": var modMap = dep[1]; var common = modMap["common"]||[]; - newDeps = (modMap[dojo.hostenv.name_]) ? common.concat(modMap[dojo.hostenv.name_]||[]) : common.concat(modMap["default"]||[]); + newDeps = (modMap[dojo.hostenv.name_]) ? common.concat(modMap[dojo.hostenv.name_]||[]) : common.concat(modMap["default"]||[]); //Flatten the array of arrays into a one-level deep array. //Each result could be an array of 3 elements (the 3 arguments to dojo.require). //We only need the first one. @@ -562,7 +566,7 @@ dojo._xdUnpackDependency = function(/*Array*/dep){ } dojo._xdWalkReqs = function(){ - //summary: Internal xd loader function. + //summary: Internal xd loader function. //Walks the requires and evaluates module resource contents in //the right order. var reqChain = null; @@ -578,7 +582,7 @@ dojo._xdWalkReqs = function(){ } dojo._xdEvalReqs = function(/*Array*/reqChain){ - //summary: Internal xd loader function. + //summary: Internal xd loader function. //Does a depth first, breadth second search and eval of required modules. while(reqChain.length > 0){ var req = reqChain[reqChain.length - 1]; @@ -673,7 +677,7 @@ dojo._xdWatchInFlight = function(){ dojo._xdDebugQueue.push({resourceName: content.resourceName, resourcePath: content.resourcePath}); }else{ //Evaluate the resource to bring it into being. - //Pass in scope args to allow multiple versions of modules in a page. + //Pass in scope args to allow multiple versions of modules in a page. content.apply(dojo.global, dojo._scopeArgs); } } @@ -685,7 +689,7 @@ dojo._xdWatchInFlight = function(){ for(i = 0; i < dojo._xdContents.length; i++){ var current = dojo._xdContents[i]; if(current.content && !current.isDefined){ - //Pass in scope args to allow multiple versions of modules in a page. + //Pass in scope args to allow multiple versions of modules in a page. current.content.apply(dojo.global, dojo._scopeArgs); } } @@ -712,10 +716,10 @@ dojo._xdNotifyLoaded = function(){ } } - dojo._inFlightCount = 0; + dojo._inFlightCount = 0; - //Only trigger call loaded if dj_load_init has run. - if(dojo._initFired && !dojo._loadNotifying){ + //Only trigger call loaded if dj_load_init has run. + if(dojo._initFired && !dojo._loadNotifying){ dojo._callLoaded(); } } -- cgit v1.2.3