diff options
Diffstat (limited to 'js/dojo-1.6/dojo/lib/plugins')
| -rw-r--r-- | js/dojo-1.6/dojo/lib/plugins/i18n.js | 94 | ||||
| -rw-r--r-- | js/dojo-1.6/dojo/lib/plugins/i18n.xd.js | 98 | ||||
| -rw-r--r-- | js/dojo-1.6/dojo/lib/plugins/text.js | 70 | ||||
| -rw-r--r-- | js/dojo-1.6/dojo/lib/plugins/text.xd.js | 74 |
4 files changed, 336 insertions, 0 deletions
diff --git a/js/dojo-1.6/dojo/lib/plugins/i18n.js b/js/dojo-1.6/dojo/lib/plugins/i18n.js new file mode 100644 index 0000000..a4c992a --- /dev/null +++ b/js/dojo-1.6/dojo/lib/plugins/i18n.js @@ -0,0 +1,94 @@ +/*
+ 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
+*/
+
+
+//
+// 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.
+
+// CAUTION, this module may return improper results if the AMD loader does not support toAbsMid and client
+// code passes relative plugin resource module ids. In that case, you should consider using the i18n! plugin
+// that comes with your loader.
+
+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
+ ){
+ // return a vector of module ids containing all available locales with respect to the target locale
+ // For example, assuming:
+ // * the root bundle indicates specific bundles for "fr" and "fr-ca",
+ // * bundlePath is "myPackage/nls"
+ // * bundleName is "myBundle"
+ // Then a locale argument of "fr-ca" would return
+ // ["myPackage/nls/myBundle", "myPackage/nls/fr/myBundle", "myPackage/nls/fr-ca/myBundle"]
+ // Notice that bundles are returned least-specific to most-specific, starting with the root.
+
+ for(var result= [bundlePath + bundleName], localeParts= locale.split("-"), current= "", i= 0; i<localeParts.length; i++){
+ current+= localeParts[i];
+ if(root[current]){
+ result.push(bundlePath + current + "/" + bundleName);
+ }
+ }
+ return result;
+ },
+
+ cache= {};
+
+ return {
+ load: function(id, require, load){
+ // note: id may be relative
+ var
+ match= nlsRe.exec(id),
+ bundlePath= (require.toAbsMid && require.toAbsMid(match[1])) || match[1],
+ bundleName= match[5] || match[4],
+ bundlePathAndName= bundlePath + bundleName,
+ locale= (match[5] && match[4]) || dojo.locale,
+ target= bundlePathAndName + "/" + locale;
+
+ // if we've already resolved this request, just return it
+ if (cache[target]) {
+ load(cache[target]);
+ return;
+ }
+
+ // get the root bundle which instructs which other bundles are required to contruct the localized bundle
+ require([bundlePathAndName], function(root){
+ var
+ current= cache[bundlePathAndName + "/"]= dojo.clone(root.root),
+ availableLocales= getAvailableLocales(root, locale, bundlePath, bundleName);
+ require(availableLocales, function(){
+ for (var i= 1; i<availableLocales.length; i++){
+ cache[bundlePathAndName + "/" + availableLocales[i]]= current= dojo.mixin(dojo.clone(current), arguments[i]);
+ }
+ // target may not have been resolve (e.g., maybe only "fr" exists when "fr-ca" was requested)
+ cache[target]= current;
+ load(current);
+ });
+ });
+ },
+
+ cache: function(mid, value){
+ cache[mid]= value;
+ }
+ };
+});
diff --git a/js/dojo-1.6/dojo/lib/plugins/i18n.xd.js b/js/dojo-1.6/dojo/lib/plugins/i18n.xd.js new file mode 100644 index 0000000..aa85cfb --- /dev/null +++ b/js/dojo-1.6/dojo/lib/plugins/i18n.xd.js @@ -0,0 +1,98 @@ +/*
+ 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
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {
+defineResource: function(dojo, dijit, dojox){//
+// 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.
+
+// CAUTION, this module may return improper results if the AMD loader does not support toAbsMid and client
+// code passes relative plugin resource module ids. In that case, you should consider using the i18n! plugin
+// that comes with your loader.
+
+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
+ ){
+ // return a vector of module ids containing all available locales with respect to the target locale
+ // For example, assuming:
+ // * the root bundle indicates specific bundles for "fr" and "fr-ca",
+ // * bundlePath is "myPackage/nls"
+ // * bundleName is "myBundle"
+ // Then a locale argument of "fr-ca" would return
+ // ["myPackage/nls/myBundle", "myPackage/nls/fr/myBundle", "myPackage/nls/fr-ca/myBundle"]
+ // Notice that bundles are returned least-specific to most-specific, starting with the root.
+
+ for(var result= [bundlePath + bundleName], localeParts= locale.split("-"), current= "", i= 0; i<localeParts.length; i++){
+ current+= localeParts[i];
+ if(root[current]){
+ result.push(bundlePath + current + "/" + bundleName);
+ }
+ }
+ return result;
+ },
+
+ cache= {};
+
+ return {
+ load: function(id, require, load){
+ // note: id may be relative
+ var
+ match= nlsRe.exec(id),
+ bundlePath= (require.toAbsMid && require.toAbsMid(match[1])) || match[1],
+ bundleName= match[5] || match[4],
+ bundlePathAndName= bundlePath + bundleName,
+ locale= (match[5] && match[4]) || dojo.locale,
+ target= bundlePathAndName + "/" + locale;
+
+ // if we've already resolved this request, just return it
+ if (cache[target]) {
+ load(cache[target]);
+ return;
+ }
+
+ // get the root bundle which instructs which other bundles are required to contruct the localized bundle
+ require([bundlePathAndName], function(root){
+ var
+ current= cache[bundlePathAndName + "/"]= dojo.clone(root.root),
+ availableLocales= getAvailableLocales(root, locale, bundlePath, bundleName);
+ require(availableLocales, function(){
+ for (var i= 1; i<availableLocales.length; i++){
+ cache[bundlePathAndName + "/" + availableLocales[i]]= current= dojo.mixin(dojo.clone(current), arguments[i]);
+ }
+ // target may not have been resolve (e.g., maybe only "fr" exists when "fr-ca" was requested)
+ cache[target]= current;
+ load(current);
+ });
+ });
+ },
+
+ cache: function(mid, value){
+ cache[mid]= value;
+ }
+ };
+});
+
+}};});
diff --git a/js/dojo-1.6/dojo/lib/plugins/text.js b/js/dojo-1.6/dojo/lib/plugins/text.js new file mode 100644 index 0000000..fa87eaa --- /dev/null +++ b/js/dojo-1.6/dojo/lib/plugins/text.js @@ -0,0 +1,70 @@ +/*
+ 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
+*/
+
+
+//
+// dojo text! 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.
+
+// CAUTION, this module may return improper results if the AMD loader does not support toAbsMid and client
+// code passes relative plugin resource module ids. In that case, you should consider using the text! plugin
+// that comes with your loader.
+
+define(["dojo", "dojo/cache"], function(dojo){
+ var
+ cached= {},
+
+ cache= function(cacheId, url, value){
+ cached[cacheId]= value;
+ dojo.cache({toString:function(){return url;}}, value);
+ },
+
+ strip= function(text){
+ //note: this function courtesy of James Burke (https://github.com/jrburke/requirejs)
+ //Strips <?xml ...?> 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(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
+ if(matches){
+ text= matches[1];
+ }
+ }else{
+ text = "";
+ }
+ return text;
+ };
+
+ return {
+ load:function(id, require, load){
+ var match, cacheId, url, parts= id.split("!");
+ if(require.toAbsMid){
+ match= parts[0].match(/(.+)(\.[^\/]*)$/);
+ cacheId= match ? require.toAbsMid(match[1]) + match[2] : require.toAbsMid(parts[0]);
+ if(cacheId in cached){
+ load(parts[1]=="strip" ? strip(cached[cacheId]) : cached[cacheId]);
+ return;
+ }
+ }
+ url= require.toUrl(parts[0]);
+ dojo.xhrGet({
+ url:url,
+ load:function(text){
+ cacheId && cache(cacheId, url, text);
+ load(parts[1]=="strip" ? strip(text) : text);
+ }
+ });
+ },
+
+ cache:function(cacheId, mid, type, value) {
+ cache(cacheId, require.nameToUrl(mid) + type, value);
+ }
+ };
+});
diff --git a/js/dojo-1.6/dojo/lib/plugins/text.xd.js b/js/dojo-1.6/dojo/lib/plugins/text.xd.js new file mode 100644 index 0000000..fc83071 --- /dev/null +++ b/js/dojo-1.6/dojo/lib/plugins/text.xd.js @@ -0,0 +1,74 @@ +/*
+ 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
+*/
+
+
+dojo._xdResourceLoaded(function(dojo, dijit, dojox){
+return {
+defineResource: function(dojo, dijit, dojox){//
+// dojo text! 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.
+
+// CAUTION, this module may return improper results if the AMD loader does not support toAbsMid and client
+// code passes relative plugin resource module ids. In that case, you should consider using the text! plugin
+// that comes with your loader.
+
+define(["dojo", "dojo/cache"], function(dojo){
+ var
+ cached= {},
+
+ cache= function(cacheId, url, value){
+ cached[cacheId]= value;
+ dojo.cache({toString:function(){return url;}}, value);
+ },
+
+ strip= function(text){
+ //note: this function courtesy of James Burke (https://github.com/jrburke/requirejs)
+ //Strips <?xml ...?> 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(/<body[^>]*>\s*([\s\S]+)\s*<\/body>/im);
+ if(matches){
+ text= matches[1];
+ }
+ }else{
+ text = "";
+ }
+ return text;
+ };
+
+ return {
+ load:function(id, require, load){
+ var match, cacheId, url, parts= id.split("!");
+ if(require.toAbsMid){
+ match= parts[0].match(/(.+)(\.[^\/]*)$/);
+ cacheId= match ? require.toAbsMid(match[1]) + match[2] : require.toAbsMid(parts[0]);
+ if(cacheId in cached){
+ load(parts[1]=="strip" ? strip(cached[cacheId]) : cached[cacheId]);
+ return;
+ }
+ }
+ url= require.toUrl(parts[0]);
+ dojo.xhrGet({
+ url:url,
+ load:function(text){
+ cacheId && cache(cacheId, url, text);
+ load(parts[1]=="strip" ? strip(text) : text);
+ }
+ });
+ },
+
+ cache:function(cacheId, mid, type, value) {
+ cache(cacheId, require.nameToUrl(mid) + type, value);
+ }
+ };
+});
+
+}};});
|
