4 // | if(dojo.isBrowser){ ... }
9 // | if(dojo.isFF > 1){ ... }
14 // | if(dojo.isIE > 6){
21 // | if(dojo.isSafari){ ... }
24 // | if(dojo.isSafari && (navigator.userAgent.indexOf("iPhone") < 0)){
25 // | // we are iPhone. iPod touch reports "iPod" above
31 // True if the client is a web-browser
34 // Greater than zero if client is FireFox. 0 otherwise. Corresponds to
35 // major detected FireFox version (1.5, 2, 3, etc.)
38 // Greater than zero if client is MSIE(PC). 0 otherwise. Corresponds to
39 // major detected IE version (6, 7, 8, etc.)
42 // Greater than zero if client is a KTHML-derived browser (Konqueror,
43 // Safari, etc.). 0 otherwise. Corresponds to major detected version.
46 // Greater than zero if client is a Mozilla-based browser (Firefox,
47 // SeaMonkey). 0 otherwise. Corresponds to major detected version.
50 // Greater than zero if client is Opera. 0 otherwise. Corresponds to
51 // major detected version.
54 // Greater than zero if client is Safari or iPhone. 0 otherwise.
59 if(typeof window != 'undefined'){
60 dojo.isBrowser = true;
61 dojo._name = "browser";
64 // attempt to figure out the path to dojo if it isn't set in the config
67 // this is a scope protection closure. We set browser versions and grab
68 // the URL we were loaded from here.
70 // grab the node we were loaded from
71 if(document && document.getElementsByTagName){
72 var scripts = document.getElementsByTagName("script");
73 var rePkg = /dojo(\.xd)?\.js(\W|$)/i;
74 for(var i = 0; i < scripts.length; i++){
75 var src = scripts[i].getAttribute("src");
77 var m = src.match(rePkg);
79 // find out where we came from
80 if(!d.config.baseUrl){
81 d.config.baseUrl = src.substring(0, m.index);
83 // and find out if we need to modify our behavior
84 var cfg = scripts[i].getAttribute("djConfig");
86 var cfgo = eval("({ "+cfg+" })");
88 dojo.config[x] = cfgo[x];
91 break; // "first Dojo wins"
95 d.baseUrl = d.config.baseUrl;
97 // fill in the rendering support information in dojo.render.*
99 var dua = n.userAgent;
100 var dav = n.appVersion;
101 var tv = parseFloat(dav);
103 d.isOpera = (dua.indexOf("Opera") >= 0) ? tv : 0;
104 // safari detection derived from:
105 // http://developer.apple.com/internet/safari/faq.html#anchor2
106 // http://developer.apple.com/internet/safari/uamatrix.html
107 var idx = Math.max(dav.indexOf("WebKit"), dav.indexOf("Safari"), 0);
109 // try to grab the explicit Safari version first. If we don't get
110 // one, look for 419.3+ as the indication that we're on something
111 // "Safari 3-ish". Lastly, default to "Safari 2" handling.
112 d.isSafari = parseFloat(dav.split("Version/")[1]) || ( ( parseFloat(dav.substr(idx+7)) >= 419.3 ) ? 3 : 2 ) || 2;
114 d.isAIR = (dua.indexOf("AdobeAIR") >= 0) ? 1 : 0;
115 d.isKhtml = (dav.indexOf("Konqueror") >= 0 || d.isSafari) ? tv : 0;
116 d.isMozilla = d.isMoz = (dua.indexOf("Gecko") >= 0 && !d.isKhtml) ? tv : 0;
119 d.isFF = parseFloat(dua.split("Firefox/")[1]) || 0;
121 if(document.all && !d.isOpera){
122 d.isIE = parseFloat(dav.split("MSIE ")[1]) || 0;
125 //Workaround to get local file loads of dojo to work on IE 7
126 //by forcing to not use native xhr.
127 if(dojo.isIE && window.location.protocol === "file:"){
128 dojo.config.ieForceActiveXXhr=true;
131 var cm = document.compatMode;
132 d.isQuirks = cm == "BackCompat" || cm == "QuirksMode" || d.isIE < 6;
134 // TODO: is the HTML LANG attribute relevant?
135 d.locale = dojo.config.locale || (d.isIE ? n.userLanguage : n.language).toLowerCase();
137 // These are in order of decreasing likelihood; this will change in time.
138 d._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
140 d._xhrObj = function(){
142 // does the work of portably generating a new XMLHTTPRequest
146 if(!dojo.isIE || !dojo.config.ieForceActiveXXhr){
147 try{ http = new XMLHttpRequest(); }catch(e){}
150 for(var i=0; i<3; ++i){
151 var progid = d._XMLHTTP_PROGIDS[i];
153 http = new ActiveXObject(progid);
159 d._XMLHTTP_PROGIDS = [progid]; // so faster next time
166 throw new Error("XMLHTTP not available: "+last_e);
169 return http; // XMLHTTPRequest instance
172 d._isDocumentOk = function(http){
173 var stat = http.status || 0;
174 return (stat >= 200 && stat < 300) || // Boolean
175 stat == 304 || // allow any 2XX response code
176 stat == 1223 || // get it out of the cache
177 (!stat && (location.protocol=="file:" || location.protocol=="chrome:") ); // Internet Explorer mangled the status code
180 //See if base tag is in use.
181 //This is to fix http://trac.dojotoolkit.org/ticket/3973,
182 //but really, we need to find out how to get rid of the dojo._Url reference
183 //below and still have DOH work with the dojo.i18n test following some other
184 //test that uses the test frame to load a document (trac #2757).
185 //Opera still has problems, but perhaps a larger issue of base tag support
186 //with XHR requests (hasBase is true, but the request is still made to document
187 //path, not base path).
188 var owloc = window.location+"";
189 var base = document.getElementsByTagName("base");
190 var hasBase = (base && base.length > 0);
192 d._getText = function(/*URI*/ uri, /*Boolean*/ fail_ok){
193 // summary: Read the contents of the specified uri and return those contents.
195 // A relative or absolute uri. If absolute, it still must be in
196 // the same "domain" as we are.
198 // Default false. If fail_ok and loading fails, return null
199 // instead of throwing.
200 // returns: The response text. null is returned when there is a
201 // failure and failure is okay (an exception otherwise)
203 // alert("_getText: " + uri);
205 // NOTE: must be declared before scope switches ie. this._xhrObj()
206 var http = this._xhrObj();
208 if(!hasBase && dojo._Url){
209 uri = (new dojo._Url(owloc, uri)).toString();
212 console.debug("_getText:", uri);
213 console.debug(window.location+"");
217 if(d.config.cacheBust){
218 uri += (uri.indexOf("?") == -1 ? "?" : "&") + String(d.config.cacheBust).replace(/\W+/g,"");
221 http.open('GET', uri, false);
225 if(!d._isDocumentOk(http)){
226 var err = Error("Unable to load "+uri+" status:"+ http.status);
227 err.status = http.status;
228 err.responseText = http.responseText;
232 if(fail_ok){ return null; } // null
233 // rethrow the exception
236 return http.responseText; // String
240 dojo._initFired = false;
241 // BEGIN DOMContentLoaded, from Dean Edwards (http://dean.edwards.name/weblog/2006/06/again/)
242 dojo._loadInit = function(e){
243 dojo._initFired = true;
244 // allow multiple calls, only first one will take effect
245 // A bug in khtml calls events callbacks for document for event which isnt supported
246 // for example a created contextmenu event calls DOMContentLoaded, workaround
247 var type = (e && e.type) ? e.type.toLowerCase() : "load";
248 if(arguments.callee.initialized || (type != "domcontentloaded" && type != "load")){ return; }
249 arguments.callee.initialized = true;
250 if("_khtmlTimer" in dojo){
251 clearInterval(dojo._khtmlTimer);
252 delete dojo._khtmlTimer;
255 if(dojo._inFlightCount == 0){
256 dojo._modulesLoaded();
260 dojo._fakeLoadInit = function(){
261 dojo._loadInit({type: "load"});
264 if(!dojo.config.afterOnLoad){
265 // START DOMContentLoaded
266 // Mozilla and Opera 9 expose the event we could use
267 if(document.addEventListener){
269 // due to a threading issue in Firefox 2.0, we can't enable
270 // DOMContentLoaded on that platform. For more information, see:
271 // http://trac.dojotoolkit.org/ticket/1704
272 if(dojo.isOpera || dojo.isFF >= 3 || (dojo.isMoz && dojo.config.enableMozDomContentLoaded === true)){
273 document.addEventListener("DOMContentLoaded", dojo._loadInit, null);
276 // mainly for Opera 8.5, won't be fired if DOMContentLoaded fired already.
277 // also used for Mozilla because of trac #1640
278 window.addEventListener("load", dojo._loadInit, null);
282 window.addEventListener("load", dojo._loadInit, null);
283 }else if(/(WebKit|khtml)/i.test(navigator.userAgent)){ // sniff
284 dojo._khtmlTimer = setInterval(function(){
285 if(/loaded|complete/.test(document.readyState)){
286 dojo._loadInit(); // call the onload handler
290 // END DOMContentLoaded
295 var _handleNodeEvent = function(/*String*/evtName, /*Function*/fp){
297 // non-destructively adds the specified function to the node's
299 // evtName: should be in the form "onclick" for "onclick" handlers.
300 // Make sure you pass in the "on" part.
301 var oldHandler = _w[evtName] || function(){};
302 _w[evtName] = function(){
303 fp.apply(_w, arguments);
304 oldHandler.apply(_w, arguments);
309 // for Internet Explorer. readyState will not be achieved on init
310 // call, but dojo doesn't need it however, we'll include it
311 // because we don't know if there are other functions added that
312 // might. Note that this has changed because the build process
313 // strips all comments -- including conditional ones.
314 if(!dojo.config.afterOnLoad){
315 document.write('<scr'+'ipt defer src="//:" '
316 + 'onreadystatechange="if(this.readyState==\'complete\'){' + dojo._scopeName + '._loadInit();}">'
321 // IE WebControl hosted in an application can fire "beforeunload" and "unload"
322 // events when control visibility changes, causing Dojo to unload too soon. The
323 // following code fixes the problem
324 // Reference: http://support.microsoft.com/default.aspx?scid=kb;en-us;199155
325 var _unloading = true;
326 _handleNodeEvent("onbeforeunload", function(){
327 _w.setTimeout(function(){ _unloading = false; }, 0);
329 _handleNodeEvent("onunload", function(){
330 if(_unloading){ dojo.unloaded(); }
334 document.namespaces.add("v","urn:schemas-microsoft-com:vml");
335 document.createStyleSheet().addRule("v\\:*", "behavior:url(#default#VML)");
338 // FIXME: dojo.unloaded requires dojo scope, so using anon function wrapper.
339 _handleNodeEvent("onbeforeunload", function() { dojo.unloaded(); });
345 OpenAjax.subscribe("OpenAjax", "onload", function(){
346 if(dojo._inFlightCount == 0){
347 dojo._modulesLoaded();
351 OpenAjax.subscribe("OpenAjax", "onunload", function(){
355 } //if (typeof window != 'undefined')
357 //Register any module paths set up in djConfig. Need to do this
358 //in the hostenvs since hostenv_browser can read djConfig from a
359 //script tag's attribute.
361 var mp = dojo.config["modulePaths"];
363 for(var param in mp){
364 dojo.registerModulePath(param, mp[param]);
369 //Load debug code if necessary.
370 if(dojo.config.isDebug){
371 dojo.require("dojo._firebug.firebug");
374 if(dojo.config.debugAtAllCosts){
375 dojo.config.useXDomain = true;
376 dojo.require("dojo._base._loader.loader_xd");
377 dojo.require("dojo._base._loader.loader_debug");
378 dojo.require("dojo.i18n");