/[jsFind]/trunk/html/js/search.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/html/js/search.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Sun Jul 11 20:18:25 2004 UTC revision 26 by dpavlin, Thu Oct 7 22:41:16 2004 UTC
# Line 33  var conversion = new String Line 33  var conversion = new String
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;
# Line 78  function intersect_results(data) Line 79  function intersect_results(data)
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  //  //
# Line 132  function watchdog() Line 126  function watchdog()
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
# Line 151  function loadXML(url, handler, data, res Line 147  function loadXML(url, handler, data, res
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); }
# Line 166  function loadXML(url, handler, data, res Line 162  function loadXML(url, handler, data, res
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        {                      {              
# Line 217  function loadData(xmldoc, url, pos, resu Line 213  function loadData(xmldoc, url, pos, resu
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      {      {
# Line 262  function traverseTree(xmldoc, url, query Line 258  function traverseTree(xmldoc, url, query
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;
# Line 275  function traverseTree(xmldoc, url, query Line 272  function traverseTree(xmldoc, url, query
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;
# Line 283  function traverseTree(xmldoc, url, query Line 281  function traverseTree(xmldoc, url, query
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    {    {
# Line 308  function doSearch(query, result_func) Line 308  function doSearch(query, result_func)
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";

Legend:
Removed from v.1  
changed lines
  Added in v.26

  ViewVC Help
Powered by ViewVC 1.1.26