33 |
var query_left = ""; |
var query_left = ""; |
34 |
var search_err = ""; |
var search_err = ""; |
35 |
var results = null; |
var results = null; |
36 |
|
var index_path = ""; |
37 |
|
|
38 |
var watchdog_id = 0; |
var watchdog_id = 0; |
39 |
var watchdog_callback = null; |
var watchdog_callback = null; |
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'); |
90 |
{ |
|
91 |
debug.box = document.createElement("div"); |
if (debug_div) { |
92 |
debug.box.setAttribute("style", |
debug_div.appendChild(document.createTextNode(msg)); |
93 |
"background-color:white" + |
debug_div.appendChild(document.createElement("br")); |
94 |
"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>"; |
|
|
} |
|
|
|
|
|
var p = document.createElement("p"); |
|
|
p.appendChild(document.createTextNode(msg)); |
|
|
debug.box.appendChild(p); |
|
95 |
} |
} |
96 |
|
|
97 |
// |
// |
126 |
watchdog_callback(new Array()); |
watchdog_callback(new Array()); |
127 |
} |
} |
128 |
|
|
129 |
|
var xmldoc; |
130 |
|
|
131 |
// This function loads the XML document from the specified URL, and when |
// This function loads the XML document from the specified URL, and when |
132 |
// 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 |
133 |
// handler function. This function works with any XML document |
// handler function. This function works with any XML document |
147 |
if (document.implementation && document.implementation.createDocument) |
if (document.implementation && document.implementation.createDocument) |
148 |
{ |
{ |
149 |
// Create a new Document object |
// Create a new Document object |
150 |
var xmldoc = document.implementation.createDocument("", "", null); |
xmldoc = document.implementation.createDocument("", "", null); |
151 |
|
|
152 |
// Specify what should happen when it finishes loading |
// Specify what should happen when it finishes loading |
153 |
xmldoc.onload = function() { handler(xmldoc, url, data, result_handler); } |
xmldoc.onload = function() { handler(xmldoc, url, data, result_handler); } |
162 |
// Something about not following standards once again |
// Something about not following standards once again |
163 |
else if (window.ActiveXObject) |
else if (window.ActiveXObject) |
164 |
{ |
{ |
165 |
//var xmldoc = new ActiveXObject("MSXML2.DOMDocument"); // Create doc. |
xmldoc = new ActiveXObject("Microsoft.XMLDOM"); // Create doc. |
166 |
var xmldoc = new ActiveXObject("Microsoft.XMLDOM"); // Create doc. |
if (! xmldoc) xmldoc = new ActiveXObject("MSXML2.DOMDocument"); // Create doc. |
167 |
// Specify onload |
// Specify onload |
168 |
xmldoc.onreadystatechange = function() |
xmldoc.onreadystatechange = function() |
169 |
{ |
{ |
213 |
|
|
214 |
if(query_left.length > 0) |
if(query_left.length > 0) |
215 |
{ |
{ |
216 |
doSearch(query_left, result_handler); |
doSearch(index_path, query_left, result_handler); |
217 |
} |
} |
218 |
else |
else |
219 |
{ |
{ |
258 |
traverseTree,query,result_handler)) |
traverseTree,query,result_handler)) |
259 |
{ |
{ |
260 |
debug("Unable to locate key "+query); |
debug("Unable to locate key "+query); |
261 |
|
result_handler(new Array()); |
262 |
} |
} |
263 |
// make sure of garbage collection |
// make sure of garbage collection |
264 |
xmldoc=null; |
xmldoc=null; |
272 |
loadData, i, result_handler)) |
loadData, i, result_handler)) |
273 |
{ |
{ |
274 |
debug("ERROR: Unable to locate data "+query); |
debug("ERROR: Unable to locate data "+query); |
275 |
|
result_handler(new Array()); |
276 |
} |
} |
277 |
// make sure of garbage collection |
// make sure of garbage collection |
278 |
xmldoc=null; |
xmldoc=null; |
281 |
} |
} |
282 |
} |
} |
283 |
// Look past the end... |
// Look past the end... |
284 |
if(!loadXML(url.replace(".xml","/"+convert(i)+".xml"), |
if(keys.length == 0 || !loadXML(url.replace(".xml","/"+convert(i)+".xml"), |
285 |
traverseTree,query,result_handler)) |
traverseTree,query,result_handler)) |
286 |
{ |
{ |
287 |
debug("Unable to locate key "+query); |
debug("Unable to locate key "+query); |
288 |
|
result_handler(new Array()); |
289 |
} |
} |
290 |
// make sure of garbage collection |
// make sure of garbage collection |
291 |
xmldoc=null; |
xmldoc=null; |
292 |
return; |
return; |
293 |
} |
} |
294 |
|
|
295 |
function doSearch(query, result_func) |
function doSearch(index_name,query, result_func) |
296 |
{ |
{ |
297 |
//alert("doSearch("+query+")"); |
//alert("doSearch("+index_name+","+query+")"); |
298 |
var pos=query.search(/[\s\+]/); |
var pos=query.search(/[\s\+]/); |
299 |
|
if (index_name) index_path = index_name+'/'; |
300 |
|
|
301 |
if(pos < 0) |
if(pos < 0) |
302 |
{ |
{ |
308 |
query = query.slice(0,pos); |
query = query.slice(0,pos); |
309 |
} |
} |
310 |
|
|
311 |
if(!loadXML("0.xml", traverseTree, query.toLowerCase(), result_func)) |
if(!loadXML(index_path+"0.xml", traverseTree, query.toLowerCase(), result_func)) |
312 |
{ |
{ |
313 |
debug("ERROR: Couldn't find main index 0.xml"); |
debug("ERROR: Couldn't find main index 0.xml"); |
314 |
search_err = "INTERNAL ERROR: Unable to load main index 0.xml"; |
search_err = "INTERNAL ERROR: Unable to load main index 0.xml"; |