79 |
From David Flanagan's, _Javascript:_The Definitive_Guide_, pg. 294-5, |
From David Flanagan's, _Javascript:_The Definitive_Guide_, pg. 294-5, |
80 |
published by O'Reilly, 4th edition, 2002 |
published by O'Reilly, 4th edition, 2002 |
81 |
*/ |
*/ |
82 |
|
|
83 |
|
var debug_div = null; |
84 |
|
|
85 |
function debug(msg) |
function debug(msg) |
86 |
{ |
{ |
87 |
return; // Disable debugging |
// return; // Disable debugging |
88 |
|
|
89 |
if(!debug.box) |
if (! debug_div) debug_div = document.getElementById('debug'); |
|
{ |
|
|
debug.box = document.createElement("div"); |
|
|
debug.box.setAttribute("style", |
|
|
"background-color:white" + |
|
|
"font-family: monospace; " + |
|
|
"border: solid black 3px; "+ |
|
|
"padding: 10px;"); |
|
|
|
|
|
document.body.appendChild(debug.box); |
|
|
debug.box.innerHTML = "<h1 style='test-align:cent'>Debugging Output</h1>"; |
|
|
} |
|
90 |
|
|
91 |
var p = document.createElement("p"); |
// this will create debug div if it doesn't exist. |
92 |
p.appendChild(document.createTextNode(msg)); |
if (! debug_div) { |
93 |
debug.box.appendChild(p); |
debug_div = document.createElement('div'); |
94 |
|
if (document.body) document.body.appendChild(debug_div); |
95 |
|
else debug_div = null; |
96 |
|
} |
97 |
|
if (debug_div) { |
98 |
|
debug_div.appendChild(document.createTextNode(msg)); |
99 |
|
debug_div.appendChild(document.createElement("br")); |
100 |
|
} |
101 |
} |
} |
102 |
|
|
|
// |
|
|
|
|
103 |
// Convert a number into a base 62 alphanumeric number string |
// Convert a number into a base 62 alphanumeric number string |
104 |
function convert(num) |
function convert(num) |
105 |
{ |
{ |
130 |
watchdog_callback(new Array()); |
watchdog_callback(new Array()); |
131 |
} |
} |
132 |
|
|
133 |
|
var xmldoc; |
134 |
|
|
135 |
// This function loads the XML document from the specified URL, and when |
// This function loads the XML document from the specified URL, and when |
136 |
// it is fully loaded, passes that document and the url to the specified |
// it is fully loaded, passes that document and the url to the specified |
137 |
// handler function. This function works with any XML document |
// handler function. This function works with any XML document |
151 |
if (document.implementation && document.implementation.createDocument) |
if (document.implementation && document.implementation.createDocument) |
152 |
{ |
{ |
153 |
// Create a new Document object |
// Create a new Document object |
154 |
var xmldoc = document.implementation.createDocument("", "", null); |
xmldoc = document.implementation.createDocument("", "", null); |
155 |
|
|
156 |
// Specify what should happen when it finishes loading |
// Specify what should happen when it finishes loading |
157 |
xmldoc.onload = function() { handler(xmldoc, url, data, result_handler); } |
xmldoc.onload = function() { handler(xmldoc, url, data, result_handler); } |
161 |
|
|
162 |
// And tell it what URL to load |
// And tell it what URL to load |
163 |
xmldoc.load(url); |
xmldoc.load(url); |
164 |
|
return true; |
165 |
} |
} |
166 |
// Otherwise use Microsoft's proprietary API for Internet Explorer |
// Otherwise use Microsoft's proprietary API for Internet Explorer |
167 |
// Something about not following standards once again |
// Something about not following standards once again |
168 |
else if (window.ActiveXObject) |
else if (window.ActiveXObject) |
169 |
{ |
{ |
170 |
//var xmldoc = new ActiveXObject("MSXML2.DOMDocument"); // Create doc. |
xmldoc = new ActiveXObject("Microsoft.XMLDOM"); // Create doc. |
171 |
var xmldoc = new ActiveXObject("Microsoft.XMLDOM"); // Create doc. |
if (! xmldoc) xmldoc = new ActiveXObject("MSXML2.DOMDocument"); // Create doc. |
172 |
// Specify onload |
// Specify onload |
173 |
xmldoc.onreadystatechange = function() |
xmldoc.onreadystatechange = function() |
174 |
{ |
{ |
175 |
if (xmldoc.readyState == 4) handler(xmldoc, url, data, result_handler); |
if (xmldoc.readyState == 4) handler(xmldoc, url, data, result_handler); |
176 |
} |
} |
177 |
xmldoc.load(url); // Start loading! |
xmldoc.load(url); // Start loading! |
178 |
|
return true; |
179 |
} |
} |
180 |
|
// else fallback on usage of iframes to load xml (Opera 7.53 without Java and maybe old Mac browsers) |
181 |
|
else { |
182 |
|
debug("using iframe xml loader - experimental and slow"); |
183 |
|
if (! window.xml_iframe) { |
184 |
|
debug("creating iframe"); |
185 |
|
window.xml_iframe = document.createElement('div'); |
186 |
|
window.xml_iframe.innerHTML = '<iframe src="'+url+'" name="xml_iframe" height="0" width="0" style="display: none;"></iframe>'; |
187 |
|
document.body.appendChild(window.xml_iframe); |
188 |
|
} else { |
189 |
|
debug("loading xml in existing iframe"); |
190 |
|
window.frames.xml_iframe.window.document.location.href = url; |
191 |
|
} |
192 |
|
|
193 |
|
// set timeout to re-check if iframe is loaded |
194 |
|
window.iframe_timeout = window.setInterval('iframe_xml_loaded();',100); |
195 |
|
|
196 |
|
// save some data for iframe_xml_loaded() |
197 |
|
window.xml_handler = handler; |
198 |
|
window.xml_url = url; |
199 |
|
window.xml_data = data; |
200 |
|
window.xml_result_handler = result_handler; |
201 |
|
return true; |
202 |
|
} |
203 |
|
clearTimeout(watchdog_id); |
204 |
|
debug("Browser incompatilibity: can't request XML document by one of supported methods"); |
205 |
|
return false; |
206 |
} |
} |
207 |
catch(ex) |
catch(ex) |
208 |
{ |
{ |
216 |
return true; |
return true; |
217 |
} |
} |
218 |
|
|
219 |
|
function iframe_xml_loaded() { |
220 |
|
debug("iframe_xmldoc_loaded"); |
221 |
|
if (! window.frames['xml_iframe']) return; |
222 |
|
var xml = eval('window.frames.xml_iframe.window.document'); |
223 |
|
if (xml) { |
224 |
|
clearTimeout(window.iframe_timeout); |
225 |
|
debug("calling handler with ("+window.xml_url+","+window.xml_data+",...)"); |
226 |
|
window.xml_handler(window.frames.xml_iframe.window.document, window.xml_url, window.xml_data, window.xml_result_handler); |
227 |
|
} else { |
228 |
|
debug("can't eval iframe with xml"); |
229 |
|
} |
230 |
|
} |
231 |
|
|
232 |
function loadData(xmldoc, url, pos, result_handler) |
function loadData(xmldoc, url, pos, result_handler) |
233 |
{ |
{ |
234 |
clearTimeout(watchdog_id); |
clearTimeout(watchdog_id); |