Skip to content

Commit

Permalink
fixes #13058; fixes #12788; !strict
Browse files Browse the repository at this point in the history
  • Loading branch information
rcgill committed May 24, 2011
1 parent ec323d0 commit bb8c85b
Show file tree
Hide file tree
Showing 35 changed files with 220 additions and 192 deletions.
1 change: 0 additions & 1 deletion _base/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ define([
"./sniff",
"./connect", // until we decide if connect is going back into non-browser environments
"./unload",
"./url",
"./window",
"./event",
"./html",
Expand Down
45 changes: 45 additions & 0 deletions _base/kernel.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,50 @@ define(["../has", "./config", "require"], function(has, config, require){
dojo.deprecated = dojo.experimental = function(){};
}


has.add("dojo-moduleUrl",
// include dojo.moduleUrl
1
);
if(has("dojo-debug-messages")){
dojo.moduleUrl = function(/*String*/module, /*String?*/url){
// summary:
// Returns a URL relative to a module.
// example:
// | var pngPath = dojo.moduleUrl("acme","images/small.png");
// | console.dir(pngPath); // list the object properties
// | // create an image and set it's source to pngPath's value:
// | var img = document.createElement("img");
// | img.src = pngPath;
// | // add our image to the document
// | dojo.body().appendChild(img);
// 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,
// the `acme.widget` and `acme.util` directories may be located
// under different roots (see `dojo.registerModulePath`) but the
// the modules which reference them can be unaware of their
// relative locations on the filesystem:
// | // 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");

// TODOC v1.6- returns a trailing slash if url is missing; v1.7+ does not
// TODOC v1.6- returns null iff module is falsy

// require.toUrl requires a filetype; therefore, just append the suffix "/x.y" to guarantee a filetype, then
// remove the suffix from the result. This way clients can request a url w/out a filetype. This should be
// rare, but it maintains backcompat for the v1.x line (note: dojo.moduleUrl will be removed in v2.0)
return require.toUrl(module.replace(/\./g, "/") + (url ? ("/" + url) : "") + "/x.y").match(/(.+)\/x\.\y$/)[1];
};
}

return dojo;
});
17 changes: 0 additions & 17 deletions _base/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,21 +108,4 @@ define(["./kernel"], function(dojo) {

dojo._Url.prototype.toString = function(){ return this.uri; };

dojo.moduleUrl = function(module, url){
// TODO what does v1.6- seems to return a trailing slash if url is missing; see dojo/tests/store/JsonRest.js fix from 1.6 - 1.7
if(!module){
//TODO: don't understand why this would ever be so, but that's the logic in 1.6- loader
return null;
}
module = module.replace(/\./g, "/") + (url ? ("/" + url) : "");
var
type= "",
match= module.match(/(.+)(\.[^\/]*?)$/);
if (match) {
module= match[1];
type= match[2];
}
return new dojo._Url(require.nameToUrl(module, type)); // dojo._Url
};

});
4 changes: 2 additions & 2 deletions _firebug/firebug.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["../_base/kernel", "../_base/html", "../_base/sniff", "../_base/array", "../_base/lang", "../_base/event", "../_base/url", "../_base/unload"], function(dojo) {
define(["../_base/kernel", "require", "../_base/html", "../_base/sniff", "../_base/array", "../_base/lang", "../_base/event", "../_base/unload"], function(dojo, require) {
// module:
// dojo/_firebug/firebug
// summary:
Expand Down Expand Up @@ -456,7 +456,7 @@ define(["../_base/kernel", "../_base/html", "../_base/sniff", "../_base/array",
}

var styleElement = _firebugDoc.createElement("link");
styleElement.href = dojo.moduleUrl("dojo._firebug", "firebug.css")+"";
styleElement.href = require.toUrl("./firebug.css");
styleElement.rel = "stylesheet";
styleElement.type = "text/css";
var styleParent = _firebugDoc.getElementsByTagName("head");
Expand Down
4 changes: 2 additions & 2 deletions back.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ dojo.back = {

function loadIframeHistory(){
//summary: private method. Do not call this directly.
var url = (dojo.config["dojoIframeHistoryUrl"] || require.nameToUrl("./resources/iframe_history.html")) + "?" + (new Date()).getTime();
var url = (dojo.config["dojoIframeHistoryUrl"] || require.toUrl("./resources/iframe_history.html")) + "?" + (new Date()).getTime();
moveForward = true;
if(historyIframe){
dojo.isWebKit ? historyIframe.location = url : window.frames[historyIframe.name].location = url;
Expand Down Expand Up @@ -151,7 +151,7 @@ dojo.back = {
// it will not work. Be careful with xdomain loading or djConfig.debugAtAllCosts scenarios,
// in order for this method to work, dojo.back will need to be part of a build layer.
if(dojo.byId("dj_history")){ return; } // prevent reinit
var src = dojo.config["dojoIframeHistoryUrl"] || require.nameToUrl("./resources/iframe_history.html");
var src = dojo.config["dojoIframeHistoryUrl"] || require.toUrl("./resources/iframe_history.html");
if (dojo._postLoad) {
console.error("dojo.back.init() must be called before the DOM has loaded. "
+ "If using xdomain loading or djConfig.debugAtAllCosts, include dojo.back "
Expand Down
19 changes: 10 additions & 9 deletions dojo.js
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@
return contextRequire(a1, a2, a3, module, result);
};
module.require = mix(result, req);
result.nameToUrl = result.toUrl = function(name, ext){
return nameToUrl(name, ext, module);
result.toUrl = function(name){
return toUrl(name, module);
};
result.toAbsMid = function(mid){
// FIXME: the .path is wrong for a package main module
Expand Down Expand Up @@ -729,16 +729,17 @@
}
},

nameToUrl = req.nameToUrl = req.toUrl = function(name, ext, referenceModule){
// slightly different algorithm depending upon whether or not name contains
// a filetype. This is a requirejs artifact which we don't like.
toUrl = req.toUrl = function(name, referenceModule){
// name must include a filetype; fault tolerate to allow no filetype (but things like "path/to/version2.13" will assume filetype of ".13")
var
match = !ext && name.match(/(.+)(\.[^\/]+?)$/),
moduleInfo = getModuleInfo((match && match[1]) || name, referenceModule, packs, modules, req.baseUrl, packageMapProg, pathsMapProg),
match = name.match(/(.+)(\.[^\/\.]+?)$/),
root = (match && match[1]) || name,
ext = (match && match[2]) || "",
moduleInfo = getModuleInfo(root, referenceModule, packs, modules, req.baseUrl, packageMapProg, pathsMapProg),
url= moduleInfo.url;
// recall, getModuleInfo always returns a url with a ".js" suffix iff pid; therefore, we've got to trim it
url= typeof moduleInfo.pid == "string" ? url.substring(0, url.length - 3) : url;
return url + (ext ? ext : (match ? match[2] : ""));
return url + ext;
},

nonModuleProps = {
Expand Down Expand Up @@ -1719,7 +1720,7 @@
},
requireLocalization:function(moduleName, bundleName, locale){
var i18nMid= dojo.getL10nName(moduleName, bundleName, locale);
if(isXdPath(nameToUrl(i18nMid))){
if(isXdPath(toUrl(i18nMid + ".js"))){
dojo.require(i18nMid);
}// else the bundle will be loaded synchronously when needed via dojo.getLocalization(moduleName, bundleName, locale)
}
Expand Down
2 changes: 1 addition & 1 deletion hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ define(["./main", "require"], function(dojo, require) {
// create and append iframe
var ifr = document.createElement("iframe"),
IFRAME_ID = "dojo-hash-iframe",
ifrSrc = dojo.config.dojoBlankHtmlUrl || require.nameToUrl("./resources/blank.html");
ifrSrc = dojo.config.dojoBlankHtmlUrl || require.toUrl("./resources/blank.html");

if(dojo.config.useXDomain && !dojo.config.dojoBlankHtmlUrl){
console.warn("dojo.hash: When using cross-domain Dojo builds,"
Expand Down
2 changes: 1 addition & 1 deletion i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ define(["./main", "require", "./has"], function(dojo, require, has) {
var syncRequire= function(deps, callback){
var results= [];
dojo.forEach(deps, function(mid){
var url= require.nameToUrl(mid) + ".js";
var url= require.toUrl(mid + ".js");
if(cache[url]){
results.push(cache[url]);
}else{
Expand Down
2 changes: 1 addition & 1 deletion io/iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ dojo.io.iframe = {
+ " please save dojo/resources/blank.html to your domain and set djConfig.dojoBlankHtmlUrl"
+ " to the path on your domain to blank.html");
}
turi = (dojo.config["dojoBlankHtmlUrl"]||require.nameToUrl("../resources/blank.html"));
turi = (dojo.config["dojoBlankHtmlUrl"]||require.toUrl("../resources/blank.html"));
}
var cframe = dojo.place(
'<iframe id="'+fname+'" name="'+fname+'" src="'+turi+'" onload="'+onloadstr+
Expand Down
2 changes: 1 addition & 1 deletion tests/NodeList-data.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(["doh", "require"], function(doh, require){
if(doh.isBrowser){
doh.register("tests.NodeList-data", require.nameToUrl("./NodeList-data.html"), 30000);
doh.register("tests.NodeList-data", require.toUrl("./NodeList-data.html"), 30000);
}
});
2 changes: 1 addition & 1 deletion tests/NodeList-manipulate.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(["doh", "require"], function(doh, require){
if(doh.isBrowser){
doh.register("tests.NodeList-manipulate", require.nameToUrl("./NodeList-manipulate.html"), 30000);
doh.register("tests.NodeList-manipulate", require.toUrl("./NodeList-manipulate.html"), 30000);
}
});
2 changes: 1 addition & 1 deletion tests/NodeList-traverse.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(["doh", "require"], function(doh, require){
if(doh.isBrowser){
doh.register("tests.NodeList-traverse", require.nameToUrl("./NodeList-traverse.html"), 30000);
doh.register("tests.NodeList-traverse", require.toUrl("./NodeList-traverse.html"), 30000);
}
});
1 change: 0 additions & 1 deletion tests/_base.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
define([
//TODO: "dojo/tests/_base/url",
"dojo/tests/_base/loader",
"dojo/tests/_base/array",
"dojo/tests/_base/Color",
Expand Down
2 changes: 1 addition & 1 deletion tests/_base/fx.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(["doh", "require"], function(doh, require){
if(doh.isBrowser){
doh.register("tests._base.fx", require.nameToUrl("./fx.html"), 15000);
doh.register("tests._base.fx", require.toUrl("./fx.html"), 15000);
}
});
18 changes: 9 additions & 9 deletions tests/_base/html.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
define(["doh", "require"], function(doh, require){
if(doh.isBrowser){
doh.register("tests._base.html", require.nameToUrl("./html.html"), 15000);
doh.register("tests._base.html_id", require.nameToUrl("./html_id.html"), 15000);
doh.register("tests._base.html_element", require.nameToUrl("./html_element.html"), 15000);
doh.register("tests._base.html_rtl", require.nameToUrl("./html_rtl.html"), 15000);
doh.register("tests._base.html_quirks", require.nameToUrl("./html_quirks.html"), 15000);
doh.register("tests._base.html_box", require.nameToUrl("./html_box.html"), 35000);
doh.register("tests._base.html_box_quirks", require.nameToUrl("./html_box_quirks.html"), 35000);
doh.register("tests._base.html_isBoyLtr", require.nameToUrl("./html_isBodyLtr.html"), 35000);
doh.register("tests._base.html_docScroll", require.nameToUrl("./html_docScroll.html"), 35000);
doh.register("tests._base.html", require.toUrl("./html.html"), 15000);
doh.register("tests._base.html_id", require.toUrl("./html_id.html"), 15000);
doh.register("tests._base.html_element", require.toUrl("./html_element.html"), 15000);
doh.register("tests._base.html_rtl", require.toUrl("./html_rtl.html"), 15000);
doh.register("tests._base.html_quirks", require.toUrl("./html_quirks.html"), 15000);
doh.register("tests._base.html_box", require.toUrl("./html_box.html"), 35000);
doh.register("tests._base.html_box_quirks", require.toUrl("./html_box_quirks.html"), 35000);
doh.register("tests._base.html_isBoyLtr", require.toUrl("./html_isBodyLtr.html"), 35000);
doh.register("tests._base.html_docScroll", require.toUrl("./html_docScroll.html"), 35000);
}
});
Loading

0 comments on commit bb8c85b

Please sign in to comment.