hostenv_browser_wev8.js
10.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
/*
Copyright (c) 2004-2005, The Dojo Foundation
All Rights Reserved.
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
http://dojotoolkit.org/community/licensing.shtml
*/
/**
* @file hostenv_browser.js
*
* Implements the hostenv interface for a browser environment.
*
* Perhaps it could be called a "dom" or "useragent" environment.
*
* @author Copyright 2004 Mark D. Anderson (mda@discerning.com)
* @author Licensed under the Academic Free License 2.1 http://www.opensource.org/licenses/afl-2.1.php
*/
// make jsc shut up (so we can use jsc to sanity check the code even if it will never run it).
/*@cc_on
@if (@_jscript_version >= 7)
var window; var XMLHttpRequest;
@end
@*/
if(typeof window == 'undefined'){
dojo.raise("no window object");
}
// attempt to figure out the path to dojo if it isn't set in the config
(function() {
// before we get any further with the config options, try to pick them out
// of the URL. Most of this code is from NW
if(djConfig.allowQueryConfig){
var baseUrl = document.location.toString(); // FIXME: use location.query instead?
var params = baseUrl.split("?", 2);
if(params.length > 1){
var paramStr = params[1];
var pairs = paramStr.split("&");
for(var x in pairs){
var sp = pairs[x].split("=");
// FIXME: is this eval dangerous?
if((sp[0].length > 9)&&(sp[0].substr(0, 9) == "djConfig.")){
var opt = sp[0].substr(9);
try{
djConfig[opt]=eval(sp[1]);
}catch(e){
djConfig[opt]=sp[1];
}
}
}
}
}
if(((djConfig["baseScriptUri"] == "")||(djConfig["baseRelativePath"] == "")) &&(document && document.getElementsByTagName)){
var scripts = document.getElementsByTagName("script");
var rePkg = /(__package__|dojo)\.js(\?|$)/i;
for(var i = 0; i < scripts.length; i++) {
var src = scripts[i].getAttribute("src");
if(!src) { continue; }
var m = src.match(rePkg);
if(m) {
root = src.substring(0, m.index);
if(!this["djConfig"]) { djConfig = {}; }
if(djConfig["baseScriptUri"] == "") { djConfig["baseScriptUri"] = root; }
if(djConfig["baseRelativePath"] == "") { djConfig["baseRelativePath"] = root; }
break;
}
}
}
var dr = dojo.render;
var drh = dojo.render.html;
var dua = drh.UA = navigator.userAgent;
var dav = drh.AV = navigator.appVersion;
var t = true;
var f = false;
drh.capable = t;
drh.support.builtin = t;
dr.ver = parseFloat(drh.AV);
dr.os.mac = dav.indexOf("Macintosh") >= 0;
dr.os.win = dav.indexOf("Windows") >= 0;
// could also be Solaris or something, but it's the same browser
dr.os.linux = dav.indexOf("X11") >= 0;
drh.opera = dua.indexOf("Opera") >= 0;
drh.khtml = (dav.indexOf("Konqueror") >= 0)||(dav.indexOf("Safari") >= 0);
drh.safari = dav.indexOf("Safari") >= 0;
var geckoPos = dua.indexOf("Gecko");
drh.mozilla = drh.moz = (geckoPos >= 0)&&(!drh.khtml);
if (drh.mozilla) {
// gecko version is YYYYMMDD
drh.geckoVersion = dua.substring(geckoPos + 6, geckoPos + 14);
}
drh.ie = (document.all)&&(!drh.opera);
drh.ie50 = drh.ie && dav.indexOf("MSIE 5.0")>=0;
drh.ie55 = drh.ie && dav.indexOf("MSIE 5.5")>=0;
drh.ie60 = drh.ie && dav.indexOf("MSIE 6.0")>=0;
dr.vml.capable=drh.ie;
dr.svg.capable = f;
dr.svg.support.plugin = f;
dr.svg.support.builtin = f;
dr.svg.adobe = f;
if (document.implementation
&& document.implementation.hasFeature
&& document.implementation.hasFeature("org.w3c.dom.svg", "1.0")
){
dr.svg.capable = t;
dr.svg.support.builtin = t;
dr.svg.support.plugin = f;
dr.svg.adobe = f;
}else{
// check for ASVG
if(navigator.mimeTypes && navigator.mimeTypes.length > 0){
var result = navigator.mimeTypes["image/svg+xml"] ||
navigator.mimeTypes["image/svg"] ||
navigator.mimeTypes["image/svg-xml"];
if (result){
dr.svg.adobe = result && result.enabledPlugin &&
result.enabledPlugin.description &&
(result.enabledPlugin.description.indexOf("Adobe") > -1);
if(dr.svg.adobe) {
dr.svg.capable = t;
dr.svg.support.plugin = t;
}
}
}else if(drh.ie && dr.os.win){
var result = f;
try {
var test = new ActiveXObject("Adobe.SVGCtl");
result = t;
} catch(e){}
if (result){
dr.svg.capable = t;
dr.svg.support.plugin = t;
dr.svg.adobe = t;
}
}else{
dr.svg.capable = f;
dr.svg.support.plugin = f;
dr.svg.adobe = f;
}
}
})();
dojo.hostenv.startPackage("dojo.hostenv");
dojo.hostenv.name_ = 'browser';
dojo.hostenv.searchIds = [];
// These are in order of decreasing likelihood; this will change in time.
var DJ_XMLHTTP_PROGIDS = ['Msxml2.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.4.0'];
dojo.hostenv.getXmlhttpObject = function(){
var http = null;
var last_e = null;
try{ http = new XMLHttpRequest(); }catch(e){}
if(!http){
for(var i=0; i<3; ++i){
var progid = DJ_XMLHTTP_PROGIDS[i];
try{
http = new ActiveXObject(progid);
}catch(e){
last_e = e;
}
if(http){
DJ_XMLHTTP_PROGIDS = [progid]; // so faster next time
break;
}
}
/*if(http && !http.toString) {
http.toString = function() { "[object XMLHttpRequest]"; }
}*/
}
if(!http){
return dojo.raise("XMLHTTP not available", last_e);
}
return http;
}
/**
* Read the contents of the specified uri and return those contents.
*
* @param uri A relative or absolute uri. If absolute, it still must be in the
* same "domain" as we are.
*
* @param async_cb If not specified, load synchronously. If specified, load
* asynchronously, and use async_cb as the progress handler which takes the
* xmlhttp object as its argument. If async_cb, this function returns null.
*
* @param fail_ok Default false. If fail_ok and !async_cb and loading fails,
* return null instead of throwing.
*/
dojo.hostenv.getText = function(uri, async_cb, fail_ok){
var http = this.getXmlhttpObject();
if(async_cb){
http.onreadystatechange = function(){
if((4==http.readyState)&&(http["status"])){
if(http.status==200){
dojo.debug("LOADED URI: "+uri);
async_cb(http.responseText);
}
}
}
}
http.open('GET', uri, async_cb ? true : false);
http.send(null);
if(async_cb){
return null;
}
return http.responseText;
}
/*
* It turns out that if we check *right now*, as this script file is being loaded,
* then the last script element in the window DOM is ourselves.
* That is because any subsequent script elements haven't shown up in the document
* object yet.
*/
/*
function dj_last_script_src() {
var scripts = window.document.getElementsByTagName('script');
if(scripts.length < 1){
dojo.raise("No script elements in window.document, so can't figure out my script src");
}
var script = scripts[scripts.length - 1];
var src = script.src;
if(!src){
dojo.raise("Last script element (out of " + scripts.length + ") has no src");
}
return src;
}
if(!dojo.hostenv["library_script_uri_"]){
dojo.hostenv.library_script_uri_ = dj_last_script_src();
}
*/
dojo.hostenv.defaultDebugContainerId = 'dojoDebug';
dojo.hostenv._println_buffer = [];
dojo.hostenv._println_safe = false;
dojo.hostenv.println = function (line){
if(!dojo.hostenv._println_safe){
dojo.hostenv._println_buffer.push(line);
}else{
try {
var console = document.getElementById(djConfig.debugContainerId ?
djConfig.debugContainerId : dojo.hostenv.defaultDebugContainerId);
if(!console) { console = document.getElementsByTagName("body")[0] || document.body; }
var div = document.createElement("div");
div.appendChild(document.createTextNode(line));
console.appendChild(div);
} catch (e) {
try{
// safari needs the output wrapped in an element for some reason
document.write("<div>" + line + "</div>");
}catch(e2){
window.status = line;
}
}
}
}
dojo.addOnLoad(function(){
dojo.hostenv._println_safe = true;
while(dojo.hostenv._println_buffer.length > 0){
dojo.hostenv.println(dojo.hostenv._println_buffer.shift());
}
});
function dj_addNodeEvtHdlr (node, evtName, fp, capture){
var oldHandler = node["on"+evtName] || function(){};
node["on"+evtName] = function(){
fp.apply(node, arguments);
oldHandler.apply(node, arguments);
}
return true;
}
dj_addNodeEvtHdlr(window, "load", function(){
if(dojo.render.html.ie){
dojo.hostenv.makeWidgets();
}
dojo.hostenv.modulesLoaded();
});
dojo.hostenv.makeWidgets = function(){
// you can put searchIds in djConfig and dojo.hostenv at the moment
// we should probably eventually move to one or the other
var sids = [];
if(djConfig.searchIds && djConfig.searchIds.length > 0) {
sids = sids.concat(djConfig.searchIds);
}
if(dojo.hostenv.searchIds && dojo.hostenv.searchIds.length > 0) {
sids = sids.concat(dojo.hostenv.searchIds);
}
if((djConfig.parseWidgets)||(sids.length > 0)){
if(dojo.evalObjPath("dojo.widget.Parse")){
// we must do this on a delay to avoid:
// http://www.shaftek.org/blog/archives/000212.html
// IE is such a tremendous peice of shit.
try{
var parser = new dojo.xml.Parse();
if(sids.length > 0){
for(var x=0; x<sids.length; x++){
var tmpNode = document.getElementById(sids[x]);
if(!tmpNode){ continue; }
var frag = parser.parseElement(tmpNode, null, true);
dojo.widget.getParser().createComponents(frag);
}
}else if(djConfig.parseWidgets){
var frag = parser.parseElement(document.getElementsByTagName("body")[0] || document.body, null, true);
dojo.widget.getParser().createComponents(frag);
}
}catch(e){
dojo.debug("auto-build-widgets error:", e);
}
}
}
}
dojo.hostenv.modulesLoadedListeners.push(function(){
if(!dojo.render.html.ie) {
dojo.hostenv.makeWidgets();
}
});
// we assume that we haven't hit onload yet. Lord help us.
try {
if (!window["djConfig"] || !window.djConfig["preventBackButtonFix"]){
document.write("<iframe style='border: 0px; width: 1px; height: 1px; position: absolute; bottom: 0px; right: 0px; visibility: visible;' name='djhistory' id='djhistory' src='"+(dojo.hostenv.getBaseScriptUri()+'iframe_history.html')+"'></iframe>");
}
if (dojo.render.html.ie) {
document.write('<style>v\:*{ behavior:url(#default#VML); }</style>');
document.write('<xml:namespace ns="urn:schemas-microsoft-com:vml" prefix="v"/>');
}
} catch (e) { }
// stub, over-ridden by debugging code. This will at least keep us from
// breaking when it's not included
dojo.hostenv.writeIncludes = function(){}
dojo.hostenv.byId = dojo.byId = function(id, doc){
if(typeof id == "string" || id instanceof String){
if(!doc){ doc = document; }
return doc.getElementById(id);
}
return id; // assume it's a node
}
dojo.hostenv.byIdArray = dojo.byIdArray = function(){
var ids = [];
for(var i = 0; i < arguments.length; i++){
if((arguments[i] instanceof Array)||(typeof arguments[i] == "array")){
for(var j = 0; j < arguments[i].length; j++){
ids = ids.concat(dojo.hostenv.byIdArray(arguments[i][j]));
}
}else{
ids.push(dojo.hostenv.byId(arguments[i]));
}
}
return ids;
}