Subversion Repositories Applications.papyrus

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2150 mathias 1
if(typeof window != 'undefined'){
2
	dojo.isBrowser = true;
3
	dojo._name = "browser";
4
 
5
 
6
	// attempt to figure out the path to dojo if it isn't set in the config
7
	(function(){
8
		var d = dojo;
9
		// this is a scope protection closure. We set browser versions and grab
10
		// the URL we were loaded from here.
11
 
12
		// grab the node we were loaded from
13
		if(document && document.getElementsByTagName){
14
			var scripts = document.getElementsByTagName("script");
15
			var rePkg = /dojo(\.xd)?\.js([\?\.]|$)/i;
16
			for(var i = 0; i < scripts.length; i++){
17
				var src = scripts[i].getAttribute("src");
18
				if(!src){ continue; }
19
				var m = src.match(rePkg);
20
				if(m){
21
					// find out where we came from
22
					if(!djConfig["baseUrl"]){
23
						djConfig["baseUrl"] = src.substring(0, m.index);
24
					}
25
					// and find out if we need to modify our behavior
26
					var cfg = scripts[i].getAttribute("djConfig");
27
					if(cfg){
28
						var cfgo = eval("({ "+cfg+" })");
29
						for(var x in cfgo){
30
							djConfig[x] = cfgo[x];
31
						}
32
					}
33
					break; // "first Dojo wins"
34
				}
35
			}
36
		}
37
		d.baseUrl = djConfig["baseUrl"];
38
 
39
		// fill in the rendering support information in dojo.render.*
40
		var n = navigator;
41
		var dua = n.userAgent;
42
		var dav = n.appVersion;
43
		var tv = parseFloat(dav);
44
 
45
		d.isOpera = (dua.indexOf("Opera") >= 0) ? tv : 0;
46
		d.isKhtml = (dav.indexOf("Konqueror") >= 0)||(dav.indexOf("Safari") >= 0) ? tv : 0;
47
		if(dav.indexOf("Safari") >= 0){
48
			d.isSafari = parseFloat(dav.split("Version/")[1]) || 2;
49
		}
50
		var geckoPos = dua.indexOf("Gecko");
51
		d.isMozilla = d.isMoz = ((geckoPos >= 0)&&(!d.isKhtml)) ? tv : 0;
52
		d.isFF = 0;
53
		d.isIE = 0;
54
		try{
55
			if(d.isMoz){
56
				d.isFF = parseFloat(dua.split("Firefox/")[1].split(" ")[0]);
57
			}
58
			if((document.all)&&(!d.isOpera)){
59
				d.isIE = parseFloat(dav.split("MSIE ")[1].split(";")[0]);
60
			}
61
		}catch(e){}
62
 
63
		//Workaround to get local file loads of dojo to work on IE 7
64
		//by forcing to not use native xhr.
65
		if(dojo.isIE && (window.location.protocol === "file:")){
66
			djConfig.ieForceActiveXXhr=true;
67
		}
68
 
69
		var cm = document["compatMode"];
70
		d.isQuirks = (cm == "BackCompat")||(cm == "QuirksMode")||(d.isIE < 6);
71
 
72
		// TODO: is the HTML LANG attribute relevant?
73
		d.locale = djConfig.locale || (d.isIE ? n.userLanguage : n.language).toLowerCase();
74
 
75
		d._println = console.debug;
76
 
77
		// These are in order of decreasing likelihood; this will change in time.
78
		d._XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
79
 
80
		d._xhrObj= function(){
81
			// summary:
82
			//		does the work of portably generating a new XMLHTTPRequest
83
			//		object.
84
			var http = null;
85
			var last_e = null;
86
			if(!dojo.isIE || !djConfig.ieForceActiveXXhr){
87
				try{ http = new XMLHttpRequest(); }catch(e){}
88
			}
89
			if(!http){
90
				for(var i=0; i<3; ++i){
91
					var progid = dojo._XMLHTTP_PROGIDS[i];
92
					try{
93
						http = new ActiveXObject(progid);
94
					}catch(e){
95
						last_e = e;
96
					}
97
 
98
					if(http){
99
						dojo._XMLHTTP_PROGIDS = [progid];  // so faster next time
100
						break;
101
					}
102
				}
103
			}
104
 
105
			if(!http){
106
				throw new Error("XMLHTTP not available: "+last_e);
107
			}
108
 
109
			return http; // XMLHTTPRequest instance
110
		}
111
 
112
		d._isDocumentOk = function(http){
113
			var stat = http.status || 0;
114
			return ( (stat>=200)&&(stat<300))|| 	// Boolean
115
				(stat==304)|| 						// allow any 2XX response code
116
				(stat==1223)|| 						// get it out of the cache
117
				(!stat && (location.protocol=="file:" || location.protocol=="chrome:") ); // Internet Explorer mangled the status code
118
		}
119
 
120
		//See if base tag is in use.
121
		//This is to fix http://trac.dojotoolkit.org/ticket/3973,
122
		//but really, we need to find out how to get rid of the dojo._Url reference
123
		//below and still have DOH work with the dojo.i18n test following some other
124
		//test that uses the test frame to load a document (trac #2757).
125
		//Opera still has problems, but perhaps a larger issue of base tag support
126
		//with XHR requests (hasBase is true, but the request is still made to document
127
		//path, not base path).
128
		var owloc = window.location+"";
129
		var base = document.getElementsByTagName("base");
130
		var hasBase = (base && base.length > 0);
131
 
132
		d._getText = function(/*URI*/ uri, /*Boolean*/ fail_ok){
133
			// summary: Read the contents of the specified uri and return those contents.
134
			// uri:
135
			//		A relative or absolute uri. If absolute, it still must be in
136
			//		the same "domain" as we are.
137
			// fail_ok:
138
			//		Default false. If fail_ok and loading fails, return null
139
			//		instead of throwing.
140
			// returns: The response text. null is returned when there is a
141
			//		failure and failure is okay (an exception otherwise)
142
 
143
			// alert("_getText: " + uri);
144
 
145
			// NOTE: must be declared before scope switches ie. this._xhrObj()
146
			var http = this._xhrObj();
147
 
148
			if(!hasBase && dojo._Url){
149
				uri = (new dojo._Url(owloc, uri)).toString();
150
			}
151
			/*
152
			console.debug("_getText:", uri);
153
			console.debug(window.location+"");
154
			alert(uri);
155
			*/
156
 
157
			http.open('GET', uri, false);
158
			try{
159
				http.send(null);
160
				// alert(http);
161
				if(!d._isDocumentOk(http)){
162
					var err = Error("Unable to load "+uri+" status:"+ http.status);
163
					err.status = http.status;
164
					err.responseText = http.responseText;
165
					throw err;
166
				}
167
			}catch(e){
168
				if(fail_ok){ return null; } // null
169
				// rethrow the exception
170
				throw e;
171
			}
172
			return http.responseText; // String
173
		}
174
	})();
175
 
176
	dojo._initFired = false;
177
	//	BEGIN DOMContentLoaded, from Dean Edwards (http://dean.edwards.name/weblog/2006/06/again/)
178
	dojo._loadInit = function(e){
179
		dojo._initFired = true;
180
		// allow multiple calls, only first one will take effect
181
		// A bug in khtml calls events callbacks for document for event which isnt supported
182
		// for example a created contextmenu event calls DOMContentLoaded, workaround
183
		var type = (e && e.type) ? e.type.toLowerCase() : "load";
184
		if(arguments.callee.initialized || (type!="domcontentloaded" && type!="load")){ return; }
185
		arguments.callee.initialized = true;
186
		if(typeof dojo["_khtmlTimer"] != 'undefined'){
187
			clearInterval(dojo._khtmlTimer);
188
			delete dojo._khtmlTimer;
189
		}
190
 
191
		if(dojo._inFlightCount == 0){
192
			dojo._modulesLoaded();
193
		}
194
	}
195
 
196
	//	START DOMContentLoaded
197
	// Mozilla and Opera 9 expose the event we could use
198
	if(document.addEventListener){
199
		// NOTE:
200
		//		due to a threading issue in Firefox 2.0, we can't enable
201
		//		DOMContentLoaded on that platform. For more information, see:
202
		//		http://trac.dojotoolkit.org/ticket/1704
203
		if(dojo.isOpera|| (dojo.isMoz && (djConfig["enableMozDomContentLoaded"] === true))){
204
			document.addEventListener("DOMContentLoaded", dojo._loadInit, null);
205
		}
206
 
207
		//	mainly for Opera 8.5, won't be fired if DOMContentLoaded fired already.
208
		//  also used for Mozilla because of trac #1640
209
		window.addEventListener("load", dojo._loadInit, null);
210
	}
211
 
212
	if(/(WebKit|khtml)/i.test(navigator.userAgent)){ // sniff
213
		dojo._khtmlTimer = setInterval(function(){
214
			if(/loaded|complete/.test(document.readyState)){
215
				dojo._loadInit(); // call the onload handler
216
			}
217
		}, 10);
218
	}
219
	//	END DOMContentLoaded
220
 
221
	(function(){
222
 
223
		var _w = window;
224
		var _handleNodeEvent = function(/*String*/evtName, /*Function*/fp){
225
			// summary:
226
			//		non-destructively adds the specified function to the node's
227
			//		evtName handler.
228
			// evtName: should be in the form "onclick" for "onclick" handlers.
229
			// Make sure you pass in the "on" part.
230
			var oldHandler = _w[evtName] || function(){};
231
			_w[evtName] = function(){
232
				fp.apply(_w, arguments);
233
				oldHandler.apply(_w, arguments);
234
			}
235
		}
236
 
237
		if(dojo.isIE){
238
			// 	for Internet Explorer. readyState will not be achieved on init
239
			// 	call, but dojo doesn't need it however, we'll include it
240
			// 	because we don't know if there are other functions added that
241
			// 	might.  Note that this has changed because the build process
242
			// 	strips all comments -- including conditional ones.
243
 
244
			document.write('<scr'+'ipt defer src="//:" '
245
				+ 'onreadystatechange="if(this.readyState==\'complete\'){dojo._loadInit();}">'
246
				+ '</scr'+'ipt>'
247
			);
248
 
249
			// IE WebControl hosted in an application can fire "beforeunload" and "unload"
250
			// events when control visibility changes, causing Dojo to unload too soon. The
251
			// following code fixes the problem
252
			// Reference: http://support.microsoft.com/default.aspx?scid=kb;en-us;199155
253
			var _unloading = true;
254
			_handleNodeEvent("onbeforeunload", function(){
255
				_w.setTimeout(function(){ _unloading = false; }, 0);
256
			});
257
			_handleNodeEvent("onunload", function(){
258
				if(_unloading){ dojo.unloaded(); }
259
			});
260
 
261
			try{
262
				document.namespaces.add("v","urn:schemas-microsoft-com:vml");
263
				document.createStyleSheet().addRule("v\\:*", "behavior:url(#default#VML)");
264
			}catch(e){}
265
		}else{
266
			// FIXME: dojo.unloaded requires dojo scope, so using anon function wrapper.
267
			_handleNodeEvent("onbeforeunload", function() { dojo.unloaded(); });
268
		}
269
 
270
	})();
271
 
272
	/*
273
	OpenAjax.subscribe("OpenAjax", "onload", function(){
274
		if(dojo._inFlightCount == 0){
275
			dojo._modulesLoaded();
276
		}
277
	});
278
 
279
	OpenAjax.subscribe("OpenAjax", "onunload", function(){
280
		dojo.unloaded();
281
	});
282
	*/
283
} //if (typeof window != 'undefined')
284
 
285
//Load debug code if necessary.
286
// dojo.requireIf((djConfig["isDebug"] || djConfig["debugAtAllCosts"]), "dojo.debug");
287
 
288
//window.widget is for Dashboard detection
289
//The full conditionals are spelled out to avoid issues during builds.
290
//Builds may be looking for require/requireIf statements and processing them.
291
// dojo.requireIf(djConfig["debugAtAllCosts"] && !window.widget && !djConfig["useXDomain"], "dojo.browser_debug");
292
// dojo.requireIf(djConfig["debugAtAllCosts"] && !window.widget && djConfig["useXDomain"], "dojo.browser_debug_xd");
293
 
294
if(djConfig.isDebug){
295
		dojo.require("dojo._firebug.firebug");
296
}
297
 
298
if(djConfig.debugAtAllCosts){
299
	djConfig.useXDomain = true;
300
	dojo.require("dojo._base._loader.loader_xd");
301
	dojo.require("dojo._base._loader.loader_debug");
302
	dojo.require("dojo.i18n");
303
}