]>
git.wh0rd.org - tt-rss.git/blob - lib/dojo/lib/backCompat.js
2 Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
3 Available via Academic Free License >= 2.1 OR the modified BSD license.
4 see: http://dojotoolkit.org/license for details
8 // AMD module id = dojo/lib/backCompat
10 // This module defines those dojo properties/methods that are defined by
11 // dojo/_base/_loader/loader and are still needed when loading with and
12 // AMD loader (when loading with an AMD loader, dojo/_base/_loader/loader
15 // note: this module is relevant only when loading dojo with an AMD loader;
16 // it is never evaluated otherwise.
18 define(["require", "dojo/_base/_loader/bootstrap"], function(require
, dojo
){
19 // the following dojo properties do not exist in the AMD-loaded version of dojo 1.x:
36 for(i
= 0; i
<names
.length
;){
38 dojo
[name
] = (function(name
) {
40 console
.warn("dojo." + name
+ " not available when using an AMD loader.");
45 // define dojo.addOnLoad in terms of the DOMContentLoaded detection available from the AMD loaders
46 // (requirejs and bdBuild). Note that the behavior of this feature is slightly different compared to the dojo
47 // v1.x sync loader. There, the onload queue is fired upon detecting both DOMContentLoaded *and* all
48 // demanded modules have arrived. It is impossible to simulate this behavior with requirejs since it does
49 // not publish its internal status (it is possible with bdLoad).
50 // TODO: consider taking ownership of this API back from the loader.
51 // TODO: consider requesting requirejs publish more enough internal state to determine if all demanded
52 // modules have been defined.
54 argsToArray = function(args
) {
56 for(i
= 0; i
<args
.length
;){
57 result
.push(args
[i
++]);
62 simpleHitch = function(context
, callback
){
64 return (typeof callback
=="string") ?
65 function(){context
[callback
]();} :
66 function(){callback
.call(context
);};
71 dojo
.ready
= dojo
.addOnLoad = function(context
, callback
){
72 require
.ready(callback
? simpleHitch(context
, callback
) : context
);
74 dojo
.addOnLoad(function() {
75 dojo
.postLoad
= dojo
.config
.afterOnLoad
= true;
77 var dca
= dojo
.config
.addOnLoad
;
79 dojo
.addOnLoad
[(dca
instanceof Array
? "apply" : "call")](dojo
, dca
);
82 // TODO: in the dojo 1.x sync loader the array dojo._loaders holds the queue of callbacks to be executed
83 // upon DOMContentLoaded. This queue is manipulated directly by dojo/uacss, dojo/parser, dijit/_base/wia
84 // and others (at least in dojox). This is also impossible to simulate universally across all AMD loaders.
85 // The following will at least accept client code accessing dojo._loaders , dojo._loaders.unshift, and
86 // dojo._loaders.splice--which is all that exists in the current dojo/dijit code stacks.
88 loaders
= dojo
._loaders
= [],
89 runLoaders = function(){
90 var temp
= loaders
.slice(0);
91 Array
.prototype.splice
.apply(loaders
, [0, loaders
.length
]);
96 loaders
.unshift = function() {
97 Array
.prototype.unshift
.apply(loaders
, argsToArray(arguments
));
98 require
.ready(runLoaders
);
100 loaders
.splice = function() {
101 Array
.prototype.splice
.apply(loaders
, argsToArray(arguments
));
102 require
.ready(runLoaders
);
105 //TODO: put unload handling in a separate module
106 var unloaders
= dojo
._unloaders
= [];
107 dojo
.unloaded = function(){
108 while(unloaders
.length
){
109 unloaders
.pop().call();
113 //TODO: kill this low-value function when it is exorcised from dojo
114 dojo
._onto = function(arr
, obj
, fn
){
115 arr
.push(fn
? simpleHitch(obj
, fn
) : obj
);
118 //TODO: kill this when the bootstrap is rewritten to not include DOMContentLoaded detection
119 // (it should probably be just a module) for now, just sink the detection; leverage the
120 // AMD loaders to handle DOMContentLoaded detection
121 dojo
._modulesLoaded = function(){};
123 //TODO: kill this when we understand its purpose relative to AMD
124 dojo
.loadInit = function(init
){
128 var amdModuleName= function(moduleName
){
129 return moduleName
.replace(/\./g, "/");
132 dojo
.getL10nName = function(moduleName
, bundleName
, locale
){
133 locale
= locale
? locale
.toLowerCase() : dojo
.locale
;
134 moduleName
= "i18n!" + amdModuleName(moduleName
);
135 return (/root/i.test(locale
)) ?
136 (moduleName
+ "/nls/" + bundleName
) :
137 (moduleName
+ "/nls/" + locale
+ "/" + bundleName
);
140 dojo
.requireLocalization = function(moduleName
, bundleName
, locale
){
141 // NOTE: locales other than the locale specified in dojo.locale need to be specifically
142 // declared as a module dependency when using AMD.
143 if(require
.vendor
!="altoviso.com"){
144 locale
= !locale
|| locale
.toLowerCase() === dojo
.locale
? "root" : locale
;
146 return require(dojo
.getL10nName(moduleName
, bundleName
, locale
));
150 getLocalization
: dojo
.requireLocalization
,
151 normalizeLocale: function(locale
){
152 var result
= locale
? locale
.toLowerCase() : dojo
.locale
;
153 if(result
== "root"){
160 //TODO: dojo._Url seems rarely used and long to be part of the boostrap; consider moving
161 //note: this routine cut and paste from dojo/_base/_loader/loader
163 ore
= new RegExp("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?$"),
164 ire
= new RegExp("^((([^\\[:]+):)?([^@]+)@)?(\\[([^\\]]+)\\]|([^\\[:]*))(:([0-9]+))?$");
165 dojo
._Url = function(){
169 // resolve uri components relative to each other
170 for(var i
= 1; i
<_a
.length
; i
++){
171 if(!_a
[i
]){ continue; }
173 // Safari doesn't support this.constructor so we have to be explicit
174 // FIXME: Tracked (and fixed) in Webkit bug 3537.
175 // http://bugs.webkit.org/show_bug.cgi?id=3537
176 var relobj
= new dojo
._Url(_a
[i
]+""),
177 uriobj
= new dojo
._Url(uri
[0]+"");
185 if(relobj
.fragment
!= n
){
186 uriobj
.fragment
= relobj
.fragment
;
189 }else if(!relobj
.scheme
){
190 relobj
.scheme
= uriobj
.scheme
;
192 if(!relobj
.authority
){
193 relobj
.authority
= uriobj
.authority
;
195 if(relobj
.path
.charAt(0) != "/"){
196 var path
= uriobj
.path
.substring(0,
197 uriobj
.path
.lastIndexOf("/") + 1) + relobj
.path
;
199 var segs
= path
.split("/");
200 for(var j
= 0; j
< segs
.length
; j
++){
202 // flatten "./" references
203 if(j
== segs
.length
- 1){
209 }else if(j
> 0 && !(j
== 1 && segs
[0] == "") &&
210 segs
[j
] == ".." && segs
[j
-1] != ".."){
211 // flatten "../" references
212 if(j
== (segs
.length
- 1)){
216 segs
.splice(j
- 1, 2);
221 relobj
.path
= segs
.join("/");
228 uri
.push(relobj
.scheme
, ":");
230 if(relobj
.authority
){
231 uri
.push("//", relobj
.authority
);
233 uri
.push(relobj
.path
);
235 uri
.push("?", relobj
.query
);
238 uri
.push("#", relobj
.fragment
);
242 this.uri
= uri
.join("");
244 // break the uri into its main components
245 var r
= this.uri
.match(ore
);
247 this.scheme
= r
[2] || (r
[1] ? "" : n
);
248 this.authority
= r
[4] || (r
[3] ? "" : n
);
249 this.path
= r
[5]; // can never be undefined
250 this.query
= r
[7] || (r
[6] ? "" : n
);
251 this.fragment
= r
[9] || (r
[8] ? "" : n
);
253 if(this.authority
!= n
){
254 // server based naming authority
255 r
= this.authority
.match(ire
);
257 this.user
= r
[3] || n
;
258 this.password
= r
[4] || n
;
259 this.host
= r
[6] || r
[7]; // ipv6 || ipv4
260 this.port
= r
[9] || n
;
264 dojo
._Url
.prototype.toString = function(){ return this.uri
; };
266 dojo
.moduleUrl = function(module
, url
){
268 //TODO: don't understand why this would ever be so, but that's the logic in loader
271 module
= amdModuleName(module
) + (url
? ("/" + url
) : "");
274 match
= module
.match(/(.+)(\.[^\/]*)$/);
279 return new dojo
._Url(require
.nameToUrl(module
, type
)); // dojo._Url