Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1318 alexandre_ 1
/*
2
	Copyright (c) 2004-2006, The Dojo Foundation
3
	All Rights Reserved.
4
 
5
	Licensed under the Academic Free License version 2.1 or above OR the
6
	modified BSD license. For more information on Dojo licensing, see:
7
 
8
		http://dojotoolkit.org/community/licensing.shtml
9
*/
10
 
1422 alexandre_ 11
 
12
 
1318 alexandre_ 13
if (typeof window == "undefined") {
14
	dojo.raise("attempt to use adobe svg hostenv when no window object");
15
}
16
with (dojo.render) {
17
	name = navigator.appName;
18
	ver = parseFloat(navigator.appVersion, 10);
19
	switch (navigator.platform) {
20
	  case "MacOS":
21
		os.osx = true;
22
		break;
23
	  case "Linux":
24
		os.linux = true;
25
		break;
26
	  case "Windows":
27
		os.win = true;
28
		break;
29
	  default:
30
		os.linux = true;
31
		break;
32
	}
33
	svg.capable = true;
34
	svg.support.builtin = true;
35
	svg.adobe = true;
36
}
37
dojo.hostenv.println = function (s) {
38
	try {
39
		var ti = document.createElement("text");
40
		ti.setAttribute("x", "50");
41
		var yPos = 25 + 15 * document.getElementsByTagName("text").length;
42
		ti.setAttribute("y", yPos);
43
		var tn = document.createTextNode(s);
44
		ti.appendChild(tn);
45
		document.documentElement.appendChild(ti);
46
	}
47
	catch (e) {
48
	}
49
};
50
dojo.debug = function () {
51
	if (!djConfig.isDebug) {
52
		return;
53
	}
54
	var args = arguments;
55
	if (typeof dojo.hostenv.println != "function") {
56
		dojo.raise("attempt to call dojo.debug when there is no dojo.hostenv println implementation (yet?)");
57
	}
58
	var isJUM = dj_global["jum"];
59
	var s = isJUM ? "" : "DEBUG: ";
60
	for (var i = 0; i < args.length; ++i) {
61
		s += args[i];
62
	}
63
	if (isJUM) {
64
		jum.debug(s);
65
	} else {
66
		dojo.hostenv.println(s);
67
	}
68
};
69
dojo.hostenv.startPackage("dojo.hostenv");
70
dojo.hostenv.name_ = "adobesvg";
71
dojo.hostenv.anonCtr = 0;
72
dojo.hostenv.anon = {};
73
dojo.hostenv.nameAnonFunc = function (anonFuncPtr, namespaceObj) {
74
	var ret = "_" + this.anonCtr++;
75
	var nso = (namespaceObj || this.anon);
76
	while (typeof nso[ret] != "undefined") {
77
		ret = "_" + this.anonCtr++;
78
	}
79
	nso[ret] = anonFuncPtr;
80
	return ret;
81
};
82
dojo.hostenv.modulesLoadedFired = false;
83
dojo.hostenv.modulesLoadedListeners = [];
84
dojo.hostenv.getTextStack = [];
85
dojo.hostenv.loadUriStack = [];
86
dojo.hostenv.loadedUris = [];
87
dojo.hostenv.modulesLoaded = function () {
88
	if (this.modulesLoadedFired) {
89
		return;
90
	}
91
	if ((this.loadUriStack.length == 0) && (this.getTextStack.length == 0)) {
92
		if (this.inFlightCount > 0) {
93
			dojo.debug("couldn't initialize, there are files still in flight");
94
			return;
95
		}
96
		this.modulesLoadedFired = true;
97
		var mll = this.modulesLoadedListeners;
98
		for (var x = 0; x < mll.length; x++) {
99
			mll[x]();
100
		}
101
	}
102
};
103
dojo.hostenv.getNewAnonFunc = function () {
104
	var ret = "_" + this.anonCtr++;
105
	while (typeof this.anon[ret] != "undefined") {
106
		ret = "_" + this.anonCtr++;
107
	}
108
	eval("dojo.nostenv.anon." + ret + " = function(){};");
109
	return [ret, this.anon[ret]];
110
};
111
dojo.hostenv.displayStack = function () {
112
	var oa = [];
113
	var stack = this.loadUriStack;
114
	for (var x = 0; x < stack.length; x++) {
115
		oa.unshift([stack[x][0], (typeof stack[x][2])]);
116
	}
117
	dojo.debug("<pre>" + oa.join("\n") + "</pre>");
118
};
119
dojo.hostenv.unwindUriStack = function () {
120
	var stack = this.loadUriStack;
121
	for (var x in dojo.hostenv.loadedUris) {
122
		for (var y = stack.length - 1; y >= 0; y--) {
123
			if (stack[y][0] == x) {
124
				stack.splice(y, 1);
125
			}
126
		}
127
	}
128
	var next = stack.pop();
129
	if ((!next) && (stack.length == 0)) {
130
		return;
131
	}
132
	for (var x = 0; x < stack.length; x++) {
133
		if ((stack[x][0] == next[0]) && (stack[x][2])) {
134
			next[2] == stack[x][2];
135
		}
136
	}
137
	var last = next;
138
	while (dojo.hostenv.loadedUris[next[0]]) {
139
		last = next;
140
		next = stack.pop();
141
	}
142
	while (typeof next[2] == "string") {
143
		try {
144
			dj_eval(next[2]);
145
			next[1](true);
146
		}
147
		catch (e) {
148
			dojo.debug("we got an error when loading " + next[0]);
149
			dojo.debug("error: " + e);
150
		}
151
		dojo.hostenv.loadedUris[next[0]] = true;
152
		dojo.hostenv.loadedUris.push(next[0]);
153
		last = next;
154
		next = stack.pop();
155
		if ((!next) && (stack.length == 0)) {
156
			break;
157
		}
158
		while (dojo.hostenv.loadedUris[next[0]]) {
159
			last = next;
160
			next = stack.pop();
161
		}
162
	}
163
	if (next) {
164
		stack.push(next);
165
		dojo.debug("### CHOKED ON: " + next[0]);
166
	}
167
};
168
dojo.hostenv.loadUri = function (uri, cb) {
169
	if (dojo.hostenv.loadedUris[uri]) {
170
		return;
171
	}
172
	var stack = this.loadUriStack;
173
	stack.push([uri, cb, null]);
174
	var tcb = function (contents) {
175
		if (contents.content) {
176
			contents = contents.content;
177
		}
178
		var next = stack.pop();
179
		if ((!next) && (stack.length == 0)) {
180
			dojo.hostenv.modulesLoaded();
181
			return;
182
		}
183
		if (typeof contents == "string") {
184
			stack.push(next);
185
			for (var x = 0; x < stack.length; x++) {
186
				if (stack[x][0] == uri) {
187
					stack[x][2] = contents;
188
				}
189
			}
190
			next = stack.pop();
191
		}
192
		if (dojo.hostenv.loadedUris[next[0]]) {
193
			dojo.hostenv.unwindUriStack();
194
			return;
195
		}
196
		stack.push(next);
197
		if (next[0] != uri) {
198
			if (typeof next[2] == "string") {
199
				dojo.hostenv.unwindUriStack();
200
			}
201
		} else {
202
			if (!contents) {
203
				next[1](false);
204
			} else {
205
				var deps = dojo.hostenv.getDepsForEval(next[2]);
206
				if (deps.length > 0) {
207
					eval(deps.join(";"));
208
				} else {
209
					dojo.hostenv.unwindUriStack();
210
				}
211
			}
212
		}
213
	};
214
	this.getText(uri, tcb, true);
215
};
216
dojo.hostenv.loadModule = function (modulename, exact_only, omit_module_check) {
217
	var module = this.findModule(modulename, 0);
218
	if (module) {
219
		return module;
220
	}
221
	if (typeof this.loading_modules_[modulename] !== "undefined") {
222
		dojo.debug("recursive attempt to load module '" + modulename + "'");
223
	} else {
224
		this.addedToLoadingCount.push(modulename);
225
	}
226
	this.loading_modules_[modulename] = 1;
227
	var relpath = modulename.replace(/\./g, "/") + ".js";
228
	var syms = modulename.split(".");
229
	var nsyms = modulename.split(".");
230
	if (syms[0] == "dojo") {
231
		syms[0] = "src";
232
	}
233
	var last = syms.pop();
234
	syms.push(last);
235
	var _this = this;
236
	var pfn = this.pkgFileName;
237
	if (last == "*") {
238
		modulename = (nsyms.slice(0, -1)).join(".");
239
		var module = this.findModule(modulename, 0);
240
		if (module) {
241
			_this.removedFromLoadingCount.push(modulename);
242
			return module;
243
		}
244
		var nextTry = function (lastStatus) {
245
			if (lastStatus) {
246
				module = _this.findModule(modulename, false);
247
				if ((!module) && (syms[syms.length - 1] != pfn)) {
248
					dojo.raise("Module symbol '" + modulename + "' is not defined after loading '" + relpath + "'");
249
				}
250
				if (module) {
251
					_this.removedFromLoadingCount.push(modulename);
252
					dojo.hostenv.modulesLoaded();
253
					return;
254
				}
255
			}
256
			syms.pop();
257
			syms.push(pfn);
258
			relpath = syms.join("/") + ".js";
259
			if (relpath.charAt(0) == "/") {
260
				relpath = relpath.slice(1);
261
			}
262
			_this.loadPath(relpath, ((!omit_module_check) ? modulename : null), nextTry);
263
		};
264
		nextTry();
265
	} else {
266
		relpath = syms.join("/") + ".js";
267
		modulename = nsyms.join(".");
268
		var nextTry = function (lastStatus) {
269
			if (lastStatus) {
270
				module = _this.findModule(modulename, false);
271
				if ((!module) && (syms[syms.length - 1] != pfn)) {
272
					dojo.raise("Module symbol '" + modulename + "' is not defined after loading '" + relpath + "'");
273
				}
274
				if (module) {
275
					_this.removedFromLoadingCount.push(modulename);
276
					dojo.hostenv.modulesLoaded();
277
					return;
278
				}
279
			}
280
			var setPKG = (syms[syms.length - 1] == pfn) ? false : true;
281
			syms.pop();
282
			if (setPKG) {
283
				syms.push(pfn);
284
			}
285
			relpath = syms.join("/") + ".js";
286
			if (relpath.charAt(0) == "/") {
287
				relpath = relpath.slice(1);
288
			}
289
			_this.loadPath(relpath, ((!omit_module_check) ? modulename : null), nextTry);
290
		};
291
		this.loadPath(relpath, ((!omit_module_check) ? modulename : null), nextTry);
292
	}
293
	return;
294
};
295
dojo.hostenv.async_cb = null;
296
dojo.hostenv.unWindGetTextStack = function () {
297
	if (dojo.hostenv.inFlightCount > 0) {
298
		setTimeout("dojo.hostenv.unWindGetTextStack()", 100);
299
		return;
300
	}
301
	dojo.hostenv.inFlightCount++;
302
	var next = dojo.hostenv.getTextStack.pop();
303
	if ((!next) && (dojo.hostenv.getTextStack.length == 0)) {
304
		dojo.hostenv.inFlightCount--;
305
		dojo.hostenv.async_cb = function () {
306
		};
307
		return;
308
	}
309
	dojo.hostenv.async_cb = next[1];
310
	window.getURL(next[0], function (result) {
311
		dojo.hostenv.inFlightCount--;
312
		dojo.hostenv.async_cb(result.content);
313
		dojo.hostenv.unWindGetTextStack();
314
	});
315
};
316
dojo.hostenv.getText = function (uri, async_cb, fail_ok) {
317
	try {
318
		if (async_cb) {
319
			dojo.hostenv.getTextStack.push([uri, async_cb, fail_ok]);
320
			dojo.hostenv.unWindGetTextStack();
321
		} else {
322
			return dojo.raise("No synchronous XMLHTTP implementation available, for uri " + uri);
323
		}
324
	}
325
	catch (e) {
326
		return dojo.raise("No XMLHTTP implementation available, for uri " + uri);
327
	}
328
};
329
dojo.hostenv.postText = function (uri, async_cb, text, fail_ok, mime_type, encoding) {
330
	var http = null;
331
	var async_callback = function (httpResponse) {
332
		if (!httpResponse.success) {
333
			dojo.raise("Request for uri '" + uri + "' resulted in " + httpResponse.status);
334
		}
335
		if (!httpResponse.content) {
336
			if (!fail_ok) {
337
				dojo.raise("Request for uri '" + uri + "' resulted in no content");
338
			}
339
			return null;
340
		}
341
		async_cb(httpResponse.content);
342
	};
343
	try {
344
		if (async_cb) {
345
			http = window.postURL(uri, text, async_callback, mimeType, encoding);
346
		} else {
347
			return dojo.raise("No synchronous XMLHTTP post implementation available, for uri " + uri);
348
		}
349
	}
350
	catch (e) {
351
		return dojo.raise("No XMLHTTP post implementation available, for uri " + uri);
352
	}
353
};
354
function dj_last_script_src() {
355
	var scripts = window.document.getElementsByTagName("script");
356
	if (scripts.length < 1) {
357
		dojo.raise("No script elements in window.document, so can't figure out my script src");
358
	}
359
	var li = scripts.length - 1;
360
	var xlinkNS = "http://www.w3.org/1999/xlink";
361
	var src = null;
362
	var script = null;
363
	while (!src) {
364
		script = scripts.item(li);
365
		src = script.getAttributeNS(xlinkNS, "href");
366
		li--;
367
		if (li < 0) {
368
			break;
369
		}
370
	}
371
	if (!src) {
372
		dojo.raise("Last script element (out of " + scripts.length + ") has no src");
373
	}
374
	return src;
375
}
376
if (!dojo.hostenv["library_script_uri_"]) {
377
	dojo.hostenv.library_script_uri_ = dj_last_script_src();
378
}
379
dojo.requireIf((djConfig["isDebug"] || djConfig["debugAtAllCosts"]), "dojo.debug");
380