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