From 48300005d82e89cbfce3d8995352e4d8d66b9719 Mon Sep 17 00:00:00 2001 From: Rawld Gill Date: Mon, 24 Jan 2011 11:59:45 +0000 Subject: [PATCH] fixes #12200 #12199, refs #11869 #11893, !strict git-svn-id: http://svn.dojotoolkit.org/src/dojo/trunk@23633 560b804f-0ae3-0310-86f3-f6aa0a117693 --- _base/Color.js | 2 +- _base/Deferred.js | 2 +- _base/NodeList.js | 2 +- _base/_loader/bootstrap.js | 84 ++++++++--- _base/_loader/hostenv_browser.js | 16 +- _base/_loader/loader.js | 60 ++++---- _base/_loader/package-main.js | 13 -- _base/array.js | 2 +- _base/connect.js | 2 +- _base/declare.js | 2 +- _base/event.js | 2 +- _base/fx.js | 2 +- _base/html.js | 2 +- _base/json.js | 2 +- _base/lang.js | 2 +- _base/query.js | 40 ++--- _base/window.js | 2 +- _base/xhr.js | 2 +- lib/backCompat.js | 252 +++++++++++++++++++++++++++++++ lib/kernel.js | 20 +++ lib/main-browser.js | 54 +++++++ lib/plugins/i18n.js | 55 +++++++ lib/plugins/text.js | 52 +++++++ package.json | 2 +- tests/_base.js | 4 +- tests/currency.js | 8 +- tests/date/locale.js | 10 +- tests/i18n.js | 4 +- tests/number.js | 8 +- 29 files changed, 599 insertions(+), 109 deletions(-) delete mode 100644 _base/_loader/package-main.js create mode 100644 lib/backCompat.js create mode 100644 lib/kernel.js create mode 100644 lib/main-browser.js create mode 100644 lib/plugins/i18n.js create mode 100644 lib/plugins/text.js diff --git a/_base/Color.js b/_base/Color.js index 94ff4e31dc..6a51d032de 100644 --- a/_base/Color.js +++ b/_base/Color.js @@ -1,4 +1,4 @@ -define("dojo/_base/Color", ["dojo", "dojo/_base/array", "dojo/_base/lang"], function(dojo) { +define("dojo/_base/Color", ["dojo/lib/kernel", "dojo/_base/array", "dojo/_base/lang"], function(dojo){ (function(){ diff --git a/_base/Deferred.js b/_base/Deferred.js index 9d0e9eb3ca..ff09651893 100644 --- a/_base/Deferred.js +++ b/_base/Deferred.js @@ -1,4 +1,4 @@ -define("dojo/_base/Deferred", ["dojo", "dojo/_base/lang"], function(dojo) { +define("dojo/_base/Deferred", ["dojo/lib/kernel", "dojo/_base/lang"], function(dojo){ (function(){ var mutator = function(){}; diff --git a/_base/NodeList.js b/_base/NodeList.js index 0121da4402..0645c5c927 100644 --- a/_base/NodeList.js +++ b/_base/NodeList.js @@ -1,4 +1,4 @@ -define("dojo/_base/NodeList", ["dojo", "dojo/_base/lang", "dojo/_base/array", "dojo/_base/connect", "dojo/_base/html"], function(dojo) { +define("dojo/_base/NodeList", ["dojo/lib/kernel", "dojo/_base/lang", "dojo/_base/array", "dojo/_base/connect", "dojo/_base/html"], function(dojo){ //>>excludeStart("webkitMobile", kwArgs.webkitMobile); (function(){ diff --git a/_base/_loader/bootstrap.js b/_base/_loader/bootstrap.js index 0548a904ca..51f4762d15 100644 --- a/_base/_loader/bootstrap.js +++ b/_base/_loader/bootstrap.js @@ -1,3 +1,9 @@ +//>>includeStart("amdLoader", kwArgs.asynchLoader); +(function(){ + +function bootstrapDojo(dojo, dijit, dojox){ + +//>>includeEnd("amdLoader"); /*===== // note: // 'djConfig' does not exist under 'dojo.*' so that it can be set before the @@ -163,23 +169,14 @@ djConfig = { //TODOC: HOW TO DOC THIS? // dojo is the root variable of (almost all) our public symbols -- make sure it is defined. if(typeof dojo == "undefined"){ - if(typeof require == "function"){ - // loaded by another module loader like RequireJS - dojo = require("dojo"); - define("dojo/_base/_loader/bootstrap", [], dojo); - }else{ - // Dojo is the module loader - define = function(id, deps, factory){factory(dojo)}; - define.dojo = true; - dojo = {}; - } - dojo._scopeName = "dojo"; - dojo._scopePrefix = ""; - dojo._scopePrefixArgs = ""; - dojo._scopeSuffix = ""; - dojo._scopeMap = {}; - dojo._scopeMapRev = {}; - + dojo = { + _scopeName: "dojo", + _scopePrefix: "", + _scopePrefixArgs: "", + _scopeSuffix: "", + _scopeMap: {}, + _scopeMapRev: {} + }; } var d = dojo; @@ -513,3 +510,56 @@ dojo.global = { })(); //>>excludeEnd("webkitMobile"); // vim:ai:ts=4:noet +//>>includeStart("amdLoader", kwArgs.asynchLoader); + +return {dojo:dojo, dijit:dijit, dojox:dojox}; +} + +// This resource ("bootstrap") is responsible for creating and starting to populate the +// dojo, dijit, and dojox objects. With the introduction of AMD loading, there are +// several ways bootstrap could be evaluated: +// +// 1. Consequent to dojo.js script-injecting it. In this case it is expected to be +// evaluated immediately and dojo, dijit, and dojox are expected to be located +// in the global namespace. Note that if bootstrap is injected by dojo.js, then +// an AMD loader is *not* being used. +// +// 2. Consequent to an AMD loader script-injecting it. In this case, it is expected +// to delay evaluation, and instead publish a factory function to be executed under +// the control of the AMD loader. IAW AMD loader design, the global space should +// not be polluted; therefore dojo, dijit, and dojox are not be published into +// the global space. +// +// 3. Consequent to a built version of dojo (sync or xdomain loader). +// +// For [1], a bootstrap version of define is provided below. the v1.6 sync loader +// will replace this with a better AMD simulation. The bootstrap version ensures bootstrap +// is executed immediately--just as with all dojo versions prior to v1.6. +// +// For [2], a factory function is provided to the loader that executes the bootstrap +// without polluting the global namespace. The factory returns the dojo object, and the +// dijit and dojox objects are stuffed into the dojo object (at _dijit and _dojox) so +// that dojo, dijit, and dojox bootstraps used with AMD can retrieve and control these +// objects. +// +// For [3], the build util with v1.6 strips *all* AMD artifacts from this resource and reverts it +// to look like v1.5. This ensures the built version, with either the sync or xdomain loader, work +// *exactly* as in v1.5. While it may be possible to do more, any solution that does not +// include significant work on the build util is likely to introduce edge cases that fail. Therefore +// this work is delayed for 1.7 when a AMD-capable built util will be provided. + +if(!this.define){ + // bootstrapping dojo with sync loader; dojo, dijit, and dojox go into the global space + var result = bootstrapDojo(); + dojo = result.dojo; + dijit = result.dijit; + dojox = result.dojox; +}else{ + // bootstrapping dojo with an AMD loader + define([], function(){ + return bootstrapDojo().dojo; + }); +} + +})(); +//>>includeEnd("amdLoader"); diff --git a/_base/_loader/hostenv_browser.js b/_base/_loader/hostenv_browser.js index b1c69a4842..3c59f53042 100644 --- a/_base/_loader/hostenv_browser.js +++ b/_base/_loader/hostenv_browser.js @@ -1,3 +1,14 @@ +//>>includeStart("amdLoader", kwArgs.asynchLoader); +define(["dojo/lib/backCompat"], function(dojo){ +// Note: if this resource is being loaded *without* an AMD loader, then +// it is loaded by dojo.js which injects it into the doc with a script element. The simulated +// AMD define function in _loader.js will cause the factory to be executed. +// +// The build util with v1.6 strips all AMD artifacts from this resource and reverts it +// to look like v1.5. This ensures the built version, with either the sync or xdomain loader, work +// *exactly* as in v1.5. + +//>>includeEnd("amdLoader"); /*===== dojo.isBrowser = { // example: @@ -64,7 +75,6 @@ dojo = { // True if the client runs on Mac } =====*/ -define("dojo/_base/_loader/hostenv_browser", ["./loader"], function(){ //>>excludeStart("webkitMobile", kwArgs.webkitMobile); if(typeof window != 'undefined'){ //>>excludeEnd("webkitMobile"); @@ -486,4 +496,8 @@ if(dojo.config.debugAtAllCosts){ dojo.require("dojo._base._loader.loader_debug"); dojo.require("dojo.i18n"); } + +//>>includeStart("amdLoader", kwArgs.asynchLoader); +return dojo; }); +//>>includeEnd("amdLoader"); diff --git a/_base/_loader/loader.js b/_base/_loader/loader.js index 1fd31920e7..5a27f743a0 100644 --- a/_base/_loader/loader.js +++ b/_base/_loader/loader.js @@ -3,7 +3,7 @@ * all of the package loading methods. */ //>>excludeStart("webkitMobile", kwArgs.webkitMobile); -define("dojo/_base/_loader/loader", ["./bootstrap"], function(){ +(function(){ var d = dojo, currentModule; //>>excludeEnd("webkitMobile"); @@ -802,21 +802,12 @@ define("dojo/_base/_loader/loader", ["./bootstrap"], function(){ } return new d._Url(loc, url); // dojo._Url - } + }; - //addition to support script-inject module format - var originalDefine = this.define; - define = !originalDefine.dojo ? - function(name, obj){ - // an existing define is already defined, need to hook into define callbacks - if(typeof name == "string"){ - if(/dojo|dijit/.test(name)){ - dojo.provide(name.replace(/\//g, ".")); - } - } - return originalDefine.apply(this, arguments); - } : - function(name, deps, def){ +//>>includeStart("amdLoader", kwArgs.asynchLoader); + // addition to support AMD module format + // replace the bootstrap define function (defined in _base/boostrap.js) with the dojo v1.x simulated AMD loader... + define= function(name, deps, def){ if(!def){ // less than 3 args if(deps){ @@ -860,15 +851,26 @@ define("dojo/_base/_loader/loader", ["./bootstrap"], function(){ }else{ var arg; switch(depName){ - case "require": arg = function(relativeId){ - return dojo.require(resolvePath(relativeId)); - }; break; - case "exports": arg = exports; break; - case "module": var module = arg = {exports: exports}; break; + case "require": + arg = function(relativeId){ + return dojo.require(resolvePath(relativeId)); + }; + break; + case "exports": + arg = exports; + break; + case "module": + var module = arg = {exports: exports}; + break; case "dojox": arg = dojo.getObject(depName); - break; - default: arg = dojo.require(depName); + break; + case "dojo/lib/kernel": + case "dojo/lib/backCompat": + arg = dojo; + break; + default: + arg = dojo.require(depName); } } args.push(arg); @@ -888,11 +890,15 @@ define("dojo/_base/_loader/loader", ["./bootstrap"], function(){ return returned; }; - define("dojo", [], d); + define.vendor = "dojotoolkit.org"; + define.version = dojo.version; + define("dojo/lib/kernel", [], dojo); + define("dojo/lib/backCompat", [], dojo); + define("dojo", [], dojo); define("dijit", [], this.dijit || (this.dijit = {})); - define("dojo/_base/_loader/loader",[],{}); - dojo.simulatedLoading = 1; - +//>>includeEnd("amdLoader"); + + //>>excludeStart("webkitMobile", kwArgs.webkitMobile); -}); +})(); //>>excludeEnd("webkitMobile"); diff --git a/_base/_loader/package-main.js b/_base/_loader/package-main.js deleted file mode 100644 index 5157c15388..0000000000 --- a/_base/_loader/package-main.js +++ /dev/null @@ -1,13 +0,0 @@ -define([ - 'exports', - 'dojo/_base/_loader/hostenv_browser', - // this list of includes is needed because of the conditional used in dojo/_base.js - 'dojo/_base/lang', - 'dojo/_base/array', - 'dojo/_base/declare', - 'dojo/_base/connect', - 'dojo/_base/Deferred', - 'dojo/_base/json', - 'dojo/_base/Color', - 'dojo/_base/browser' -], function () {}); \ No newline at end of file diff --git a/_base/array.js b/_base/array.js index 1ea6d0798a..eacf7925ec 100644 --- a/_base/array.js +++ b/_base/array.js @@ -1,4 +1,4 @@ -define("dojo/_base/array", ["dojo", "dojo/_base/lang"], function(dojo) { +define("dojo/_base/array", ["dojo/lib/kernel", "dojo/_base/lang"], function(dojo){ //>>excludeStart("webkitMobile", kwArgs.webkitMobile); (function(){ diff --git a/_base/connect.js b/_base/connect.js index 986d3999b5..5db2a57d7b 100644 --- a/_base/connect.js +++ b/_base/connect.js @@ -1,4 +1,4 @@ -define("dojo/_base/connect", ["dojo", "dojo/_base/lang"], function(dojo) { +define("dojo/_base/connect", ["dojo/lib/kernel", "dojo/_base/lang"], function(dojo){ // this file courtesy of the TurboAjax Group, licensed under a Dojo CLA diff --git a/_base/declare.js b/_base/declare.js index 0154b87793..1b17377dec 100644 --- a/_base/declare.js +++ b/_base/declare.js @@ -1,4 +1,4 @@ -define("dojo/_base/declare", ["dojo", "dojo/_base/lang", "dojo/_base/array"], function(dojo) { +define("dojo/_base/declare", ["dojo/lib/kernel", "dojo/_base/lang", "dojo/_base/array"], function(dojo){ (function(){ var d = dojo, mix = d._mixin, op = Object.prototype, opts = op.toString, diff --git a/_base/event.js b/_base/event.js index af89be0c04..bfb0575def 100644 --- a/_base/event.js +++ b/_base/event.js @@ -1,4 +1,4 @@ -define("dojo/_base/event", ["dojo", "dojo/_base/connect"], function(dojo) { +define("dojo/_base/event", ["dojo/lib/kernel", "dojo/_base/connect"], function(dojo){ // this file courtesy of the TurboAjax Group, licensed under a Dojo CLA diff --git a/_base/fx.js b/_base/fx.js index 25a9802060..55f71c83a4 100644 --- a/_base/fx.js +++ b/_base/fx.js @@ -1,4 +1,4 @@ -define("dojo/_base/fx", ["dojo", "dojo/_base/Color", "dojo/_base/connect", "dojo/_base/lang", "dojo/_base/html"], function(dojo) { +define("dojo/_base/fx", ["dojo/lib/kernel", "dojo/_base/Color", "dojo/_base/connect", "dojo/_base/lang", "dojo/_base/html"], function(dojo){ /* Animation loosely package based on Dan Pupius' work, contributed under CLA: diff --git a/_base/html.js b/_base/html.js index 16c9758d26..a96a01592b 100644 --- a/_base/html.js +++ b/_base/html.js @@ -1,4 +1,4 @@ -define("dojo/_base/html", ["dojo", "dojo/_base/lang"], function(dojo) { +define("dojo/_base/html", ["dojo/lib/kernel", "dojo/_base/lang"], function(dojo){ // FIXME: need to add unit tests for all the semi-public methods diff --git a/_base/json.js b/_base/json.js index 01e25ff166..eabd785f34 100644 --- a/_base/json.js +++ b/_base/json.js @@ -1,4 +1,4 @@ -define("dojo/_base/json", ["dojo"], function(dojo) { +define("dojo/_base/json", ["dojo/lib/kernel"], function(dojo){ dojo.fromJson = function(/*String*/ json){ // summary: diff --git a/_base/lang.js b/_base/lang.js index 0c0b248c21..9d249d2919 100644 --- a/_base/lang.js +++ b/_base/lang.js @@ -1,4 +1,4 @@ -define("dojo/_base/lang", ["dojo"], function(dojo) { +define("dojo/_base/lang", ["dojo/lib/kernel"], function(dojo){ (function(){ var d = dojo, opts = Object.prototype.toString; diff --git a/_base/query.js b/_base/query.js index d7187cfddd..782b08bcdd 100644 --- a/_base/query.js +++ b/_base/query.js @@ -1,5 +1,5 @@ //>>excludeStart("webkitMobile", kwArgs.webkitMobile); -(function() { +(function(){ /* dojo.query() architectural overview: @@ -1576,25 +1576,25 @@ var defineAcme= function(){ }; //prefers queryPortability, then acme, then dojo -if (this["dojo"]) { - var defined= 0; -//>>includeStart("asyncLoader", kwArgs.asynchLoader); - defined= 1; - define("dojo/_base/query", ["dojo", "dojo/_base/NodeList", "dojo/_base/lang"], function(dojo) { - defineQuery(this["queryPortability"]||this["acme"]||dojo); - }); -//>>includeEnd("asyncLoader"); -//>>excludeStart("asyncLoader", kwArgs.asynchLoader); - if (!defined) { - // must be in a built version that stripped out the define above - dojo.provide("dojo._base.query"); - dojo.require("dojo._base.NodeList"); - dojo.require("dojo._base.lang"); - defineQuery(this["queryPortability"]||this["acme"]||dojo); - } // else must be in a source version (or a build that likes define) -//>>excludeEnd("asyncLoader"); -} else { - defineQuery(this["queryPortability"]||this["acme"]||defineAcme()); +if(this["dojo"]){ + var defined = 0; +//>>includeStart("amdLoader", kwArgs.asynchLoader); + defined = 1; + define("dojo/_base/query", ["dojo/lib/kernel", "dojo/_base/NodeList", "dojo/_base/lang", "dojo/_base/window"], function(dojo){ + defineQuery(this["queryPortability"]||this["acme"]||dojo); + }); +//>>includeEnd("amdLoader"); +//>>excludeStart("amdLoader", kwArgs.asynchLoader); + if(!defined){ + // must be in a built version that stripped out the define above + dojo.provide("dojo._base.query"); + dojo.require("dojo._base.NodeList"); + dojo.require("dojo._base.lang"); + defineQuery(this["queryPortability"]||this["acme"]||dojo); + } // else must be in a source version (or a build that likes define) +//>>excludeEnd("amdLoader"); +}else{ + defineQuery(this["queryPortability"]||this["acme"]||defineAcme()); } })(); diff --git a/_base/window.js b/_base/window.js index 3d4be40c1b..1c28563280 100644 --- a/_base/window.js +++ b/_base/window.js @@ -1,4 +1,4 @@ -define("dojo/_base/window", ["dojo"], function(dojo) { +define("dojo/_base/window", ["dojo/lib/kernel"], function(dojo){ /*===== dojo.doc = { diff --git a/_base/xhr.js b/_base/xhr.js index deefb53656..bf0855b1fb 100644 --- a/_base/xhr.js +++ b/_base/xhr.js @@ -1,4 +1,4 @@ -define("dojo/_base/xhr", ["dojo", "dojo/_base/Deferred", "dojo/_base/json", "dojo/_base/lang", "dojo/_base/query"], function(dojo) { +define("dojo/_base/xhr", ["dojo/lib/kernel", "dojo/_base/Deferred", "dojo/_base/json", "dojo/_base/lang", "dojo/_base/query"], function(dojo){ //>>excludeStart("webkitMobile", kwArgs.webkitMobile); (function(){ diff --git a/lib/backCompat.js b/lib/backCompat.js new file mode 100644 index 0000000000..245fb502f7 --- /dev/null +++ b/lib/backCompat.js @@ -0,0 +1,252 @@ +// AMD module id = dojo/lib/backCompat +// +// This module defines those dojo properties/methods that are defined by +// dojo/_base/_loader/loader and are still needed when loading with and +// AMD loader (when loading with an AMD loader, dojo/_base/_loader/loader +// is never loaded). +// +// note: this module is relevant only when loading dojo with an AMD loader; +// it is never evaluated otherwise. + +define(["require", "dojo/_base/_loader/bootstrap"], function(require, dojo){ + + // the following dojo properties do not exist in the AMD-loaded version of dojo 1.x: + var names= [ + "_loadedModules", + "_inFlightCount", + "_hasResource", + "_modulePrefixes", + "_moduleHasPrefix", + "_loadedUrls", + "_loadNotifying", + "_loadPath", + "_loadUri", + "_loadUriAndCheck", + "loaded", + "_callLoaded", + "_getModuleSymbols", + "_loadModule", + "require", + "provide", + "platformRequire", + "requireIf", + "requireAfterIf", + "registerModulePath" + ], i, name; + for(i = 0; i 0 && !(j == 1 && segs[0] == "") && + segs[j] == ".." && segs[j-1] != ".."){ + // flatten "../" references + if(j == (segs.length - 1)){ + segs.splice(j, 1); + segs[j - 1] = ""; + }else{ + segs.splice(j - 1, 2); + j -= 2; + } + } + } + relobj.path = segs.join("/"); + } + } + } + + uri = []; + if(relobj.scheme){ + uri.push(relobj.scheme, ":"); + } + if(relobj.authority){ + uri.push("//", relobj.authority); + } + uri.push(relobj.path); + if(relobj.query){ + uri.push("?", relobj.query); + } + if(relobj.fragment){ + uri.push("#", relobj.fragment); + } + } + + this.uri = uri.join(""); + + // break the uri into its main components + var r = this.uri.match(ore); + + this.scheme = r[2] || (r[1] ? "" : n); + this.authority = r[4] || (r[3] ? "" : n); + this.path = r[5]; // can never be undefined + this.query = r[7] || (r[6] ? "" : n); + this.fragment = r[9] || (r[8] ? "" : n); + + if(this.authority != n){ + // server based naming authority + r = this.authority.match(ire); + + this.user = r[3] || n; + this.password = r[4] || n; + this.host = r[6] || r[7]; // ipv6 || ipv4 + this.port = r[9] || n; + } + }; + + dojo._Url.prototype.toString = function(){ return this.uri; }; + + dojo.moduleUrl= function(module, url){ + if(!module){ + //TODO: don't understand why this would ever be so, but that's the logic in loader + return null; + } + module = amdModuleName(module); + if(module.lastIndexOf("/") != module.length-1){ + module+= "/"; + } + return new dojo._Url(require.nameToUrl(module + (url || ""))); // dojo._Url + }; + + return dojo; +}); diff --git a/lib/kernel.js b/lib/kernel.js new file mode 100644 index 0000000000..1ee230b136 --- /dev/null +++ b/lib/kernel.js @@ -0,0 +1,20 @@ +// AMD module id = dojo/lib/kernel +// +// This module ensures the dojo object is initialized by... +// +// * dojo/_base/_loader/bootstrap +// * dojo/lib/backCompat +// * dojo/_base/_loader/hostenv_browser +// +// This is roughly equivalent to the work that dojo.js does by injecting +// bootstrap, loader, and hostenv_browser. +// +// note: this module is relevant only when loading dojo with an AMD loader; +// it is never evaluated otherwise. + +// for now, we publish dojo into the global namespace because so many tests and apps expect it. +var dojo; +define(["dojo/_base/_loader/hostenv_browser"], function(dojo_){ + dojo= dojo_; + return dojo_; +}); diff --git a/lib/main-browser.js b/lib/main-browser.js new file mode 100644 index 0000000000..f842dfd0cb --- /dev/null +++ b/lib/main-browser.js @@ -0,0 +1,54 @@ +// AMD module id = dojo +// +// This is a package main module for the dojo package implemented so that the *absolute minimal* +// changes are made to the dojo 1.x code. It is by no means optimal and should/will be replaced with +// a less naive design--particularly as dojo v2.0 evolves. +// +// There are a few key design weaknesses in this implementation: +// +// * generally, v1.x bootstrap, tests, and apps assume dojo is global +// +// * the v1.x dojo/_base modules assume dojo is defined before they are defined +// and their factory functions go about populating dojo--which is really part of defining +// dojo. This leads to the appearance of a circular dependency and is a somewhat obtuse +// design since the dojo object must be delivered to them under a different module +// name (dojo/lib/kernel). +// +// * bootstrap modules tend to incorporate unrelated features (e.g., hostenv_browser includes +// DOMContentLoad detection, thereby making it impossible to build out this feature if a +// particular app does not need it). +// +// * The back compatibility layer requires/contains some non-optimal code that needs to be improved. +// +// As 1.7 and 2.0 evolve, these items will be addressed with more robust implementation. +// +// The boot sequence is as follows: +// +// dojo (this module) depends on... +// dojo/lib/kernel which depends on... +// dojo/_base/_loader/hostenv_browser which depends on... +// dojo/lib/backCompat which depends on... +// dojo/_base/_loader/bootstrap which depends on nothing +// +// This module further depends on the fairly ordinary modules in dojo/_base; each of these +// modules depends on dojo/lib/kernel (at least) which provide the dojo object for them to augment. + +define("dojo", [ + "dojo/lib/kernel", + "dojo/_base/lang", + "dojo/_base/array", + "dojo/_base/declare", + "dojo/_base/connect", + "dojo/_base/Deferred", + "dojo/_base/json", + "dojo/_base/Color", + "dojo/_base/window", + "dojo/_base/event", + "dojo/_base/html", + "dojo/_base/NodeList", + "dojo/_base/query", + "dojo/_base/xhr", + "dojo/_base/fx" +], function(dojo){ + return dojo; +}); diff --git a/lib/plugins/i18n.js b/lib/plugins/i18n.js new file mode 100644 index 0000000000..e94221cd1a --- /dev/null +++ b/lib/plugins/i18n.js @@ -0,0 +1,55 @@ +// +// dojo i18n! plugin +// +// We choose to include our own plugin in hopes of leveraging functionality already contained in dojo +// and thereby reducing the size of the plugin compared to various loader implementations. Naturally, this +// allows AMD loaders to be used without their plugins. + +define(["dojo"], function(dojo) { + var + nlsRe= + // regexp for reconstructing the master bundle name from parts of the regexp match + // nlsRe.exec("foo/bar/baz/nls/en-ca/foo") gives: + // ["foo/bar/baz/nls/en-ca/foo", "foo/bar/baz/nls/", "/", "/", "en-ca", "foo"] + // nlsRe.exec("foo/bar/baz/nls/foo") gives: + // ["foo/bar/baz/nls/foo", "foo/bar/baz/nls/", "/", "/", "foo", ""] + // so, if match[5] is blank, it means this is the top bundle definition. + // courtesy of http://requirejs.org + /(^.*(^|\/)nls(\/|$))([^\/]*)\/?([^\/]*)/, + + getAvailableLocales= function( + root, + locale, + bundlePath, + bundleName + ){ + for(var result= [bundlePath + bundleName], localeParts= locale.split("-"), current= "", i= 0; i declarations so that external SVG and XML + //documents can be added to a document without worry. Also, if the string + //is an HTML document, only the part inside the body tag is returned. + if(text){ + text= text.replace(/^\s*<\?xml(\s)+version=[\'\"](\d)*.(\d)*[\'\"](\s)*\?>/im, ""); + var matches= text.match(/]*>\s*([\s\S]+)\s*<\/body>/im); + if (matches) { + text= matches[1]; + } + }else{ + text = ""; + } + return text; + }; + + return { + load: function(require, id, loaded){ + var + parts= id.split("!"), + url= require.nameToUrl(parts[0]), + pqn= "text!"+url; + if(url in cached){ + loaded(parts[1] && parts[1]=="strip" ? strip(cached[url]) : cached[url]); + }else{ + dojo.xhrGet({ + url:url, + load:function(text){ + cache(url, text); + loaded(parts[1] && parts[1]=="strip" ? strip(text) : text); + } + }); + } + }, + cache:cache + }; +}); diff --git a/package.json b/package.json index 73548e41a7..5855be51ff 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "directories": { "lib": "." }, - "main":"./_base/_loader/package-main", + "main":"./lib/main-browser", "description": "Dojo core is a powerful, lightweight library that makes common tasks quicker and easier. Animate elements, manipulate the DOM, and query with easy CSS syntax, all without sacrificing performance.", "licenses": [ { diff --git a/tests/_base.js b/tests/_base.js index 22f664d660..1ec28073e3 100644 --- a/tests/_base.js +++ b/tests/_base.js @@ -109,8 +109,8 @@ if(doh.selfTest){ try{ // go grab the others dojo.require("tests._base._loader.bootstrap"); - dojo.simulatedLoading && dojo.require("tests._base._loader.loader"); - dojo.require("dojo.tests._base._loader.modules"); + dojo.require("tests._base._loader.loader"); + this.define && define.vendor=="dojotoolkit.org" && dojo.require("dojo.tests._base._loader.modules"); dojo.platformRequire({ browser: ["tests._base._loader.hostenv_browser"], rhino: ["tests._base._loader.hostenv_rhino"], diff --git a/tests/currency.js b/tests/currency.js index 7d8f2e741c..7e72674a3e 100644 --- a/tests/currency.js +++ b/tests/currency.js @@ -25,8 +25,8 @@ t.t(isNaN(dojo.currency.parse("$1,234", {currency: "USD", fractional: true, locale: "en-us"}))); }; -if (!dojo.simulatedLoading) { //tests for the asynchronous loader machinery - define(["dojo", "dojo/currency", "plugin/i18n"], function(dojo) { +if(dojo.global.define && define.vendor!="dojotoolkit.org"){ //tests for the AMD loader + define(["dojo", "dojo/currency", "plugin/i18n"], function(dojo){ tests.register("tests.currency", [ { @@ -36,11 +36,11 @@ if (!dojo.simulatedLoading) { //tests for the asynchronous loader machinery var def = new doh.Deferred(), deps= ["dojo"]; - dojo.forEach(["en-us", "en-ca", "de-de"], function(locale) { + dojo.forEach(["en-us", "en-ca", "de-de"], function(locale){ deps.push(dojo.getL10nName("dojo/cldr", "currency", locale)); deps.push(dojo.getL10nName("dojo/cldr", "number", locale)); }); - define(deps, function(dojo) { + define(deps, function(dojo){ runTest(dojo, t); def.callback(true); }); diff --git a/tests/date/locale.js b/tests/date/locale.js index 43e7645199..68a233ccc3 100644 --- a/tests/date/locale.js +++ b/tests/date/locale.js @@ -12,18 +12,18 @@ tests.register("tests.date.locale", name: "date.locale", runTest: function(t){ var partLocaleList = ["en-us", "fr-fr", "es", "de-at", "ja-jp", "zh-cn"]; - if (!dojo.simulatedLoading) { //tests for the asynchronous loader machinery + if(dojo.global.define && define.vendor!="dojotoolkit.org"){ //tests for the AMD loader var def = new doh.Deferred(), - deps= []; - dojo.forEach(partLocaleList, function(locale) { + deps = []; + dojo.forEach(partLocaleList, function(locale){ deps.push(dojo.getL10nName("dojo/cldr", "gregorian", locale)); }); - define(deps, function() { + define(deps, function(){ def.callback(true); }); return def; - } else { // tests for the v1.x loader/i18n machinery + }else{ // tests for the v1.x loader/i18n machinery dojo.forEach(partLocaleList, function(locale){ dojo.requireLocalization("dojo.cldr", "gregorian", locale); }); diff --git a/tests/i18n.js b/tests/i18n.js index bf83d215f7..c91eba1355 100644 --- a/tests/i18n.js +++ b/tests/i18n.js @@ -1,4 +1,4 @@ -if (!dojo.simulatedLoading) { //tests for the asynchronous loader machinery +if(this.define && define.vendor!="dojotoolkit.org"){ //tests for the AMD loader // notice the module name is more precise with async tests; to wit, "dojo/tests/ compared to "tests" // "tests" could be used, but the accompanying change must be made in each of the i18n resources in @@ -9,7 +9,7 @@ if (!dojo.simulatedLoading) { //tests for the asynchronous loader machinery getTest = function(value, locale){ return function(){ var def = new doh.Deferred(); - define([dojo.getL10nName("dojo/tests", "salutations", locale)], function(bundle) { + define([dojo.getL10nName("dojo/tests", "salutations", locale)], function(bundle){ doh.assertEqual(value, dojo.getL10n("dojo/tests", "salutations", locale).hello); def.callback(true); }); diff --git a/tests/number.js b/tests/number.js index 32725b2b17..7ffee4932c 100644 --- a/tests/number.js +++ b/tests/number.js @@ -139,18 +139,18 @@ tests.register("tests.number", runTest: function(t){ var partLocaleList = ["en-us", "fr-fr", "de-de"]; tests.number.locale = "en-us"; - if (!dojo.simulatedLoading) { //tests for the asynchronous loader machinery + if(dojo.global.define && define.vendor!="dojotoolkit.org"){ //tests for the asynchronous loader machinery var def = new doh.Deferred(), deps= []; - dojo.forEach(partLocaleList, function(locale) { + dojo.forEach(partLocaleList, function(locale){ deps.push(dojo.getL10nName("dojo/cldr", "number", locale)); }); - define(deps, function() { + define(deps, function(){ def.callback(true); }); return def; - } else { // tests for the v1.x loader/i18n machinery + }else{ // tests for the v1.x loader/i18n machinery for(var i = 0 ; i < partLocaleList.length; i ++){ dojo.requireLocalization("dojo.cldr","number",partLocaleList[i]); }