/[webpac]/trunk2/out/js/usage.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

Annotation of /trunk2/out/js/usage.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 465 - (hide annotations)
Thu Sep 23 18:23:13 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: application/javascript
File size: 3654 byte(s)
generate results using createElement

1 dpavlin 391 /**
2     usage.js an example usage of the search engine
3    
4     A part of the jsfind project (http://projects.elucidsoft.net/jsfind)
5     Copyright (C) 2003 Shawn Garbett
6    
7     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License
9     as published by the Free Software Foundation; either version 2
10     of the License, or (at your option) any later version.
11    
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License
18     along with this program; if not, write to the Free Software
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20    
21     Contact Info:
22     Shawn Garbett <Shawn@eLucidSoft.net>
23     http://www.elucidsoft.net
24     4037 General Bate Drive
25     Nashville, TN 37204
26     */
27    
28     function go(f)
29     {
30 dpavlin 462 var form = document.getElementById('search');
31     var query = form.elements['query'].value;
32     var index_name = form.elements['index_name'].options[form.elements['index_name'].selectedIndex].value;
33    
34     if(!query)
35 dpavlin 391 {
36     return false;
37     }
38    
39     if(query == null || query == "")
40     {
41     alert("No search terms entered!");
42     return false;
43     }
44    
45     var parsed_string = query.replace(/\s/gi,"+");
46     //var url=location.host+location.pathname+"?search="+parsed_string;
47     var url=location.pathname+"?";
48     if (index_name) url += "index_name="+index_name+"&";
49     url += "query="+parsed_string;
50     location = url;
51    
52     return false;
53     }
54    
55     // Function to help find a "DIV" element
56     function findDivHelper(n, id)
57     {
58     for(var m=n.firstChild; m != null; m=m.nextSibling)
59     {
60     if((m.nodeType == 1) &&
61     (m.tagName.toLowerCase() == "div") &&
62 dpavlin 451 m.getAttribute("id") &&
63 dpavlin 391 (m.getAttribute("id").toLowerCase() == id.toLowerCase() ))
64     {
65     return m;
66     }
67     else
68     {
69     var r=findDivHelper(m, id);
70     if(r) return r;
71     }
72     }
73     return null;
74     }
75    
76     // Function to find a specified "DIV" element by id
77     function findDiv(id)
78     {
79     return findDivHelper(document.body,id);
80     }
81    
82     // Print results to page
83     function printResults(result)
84     {
85     //clearTimeout(watchdog_id);
86     //debug("clearTimeout = "+watchdog_id);
87     debug("printResults("+result.length+")");
88    
89     var d = findDiv("results");
90 dpavlin 451 var header;
91 dpavlin 391
92     // Null result output
93     if(result.length < 1)
94     {
95 dpavlin 451 header = (d.getElementsByTagName("h2"))[0].firstChild;
96 dpavlin 461 try {
97     header.replaceData(0, 14, "Nothing Found ");
98     } catch(e) {}
99 dpavlin 391
100     if(search_err != "")
101     {
102     e = document.createElement("font");
103     e.setAttribute("color","red");
104     e.setAttribute("size","+1");
105     e.appendChild(document.createTextNode(search_err));
106     d.appendChild(e);
107     d.appendChild(document.createElement("br"));
108     }
109    
110     return;
111     }
112    
113     // Add results to main document
114     for(var i=result.length-1; i>=0; i--)
115     {
116     var e = document.createElement("font");
117    
118     e = document.createElement("a");
119 dpavlin 397 e.setAttribute("href",result[i].link+location.search);
120     // e.setAttribute("target","_blank");
121 dpavlin 396 e.appendChild(document.createTextNode(result[i].title));
122 dpavlin 391 d.appendChild(e);
123     d.appendChild(document.createTextNode(" "));
124    
125     e = document.createElement("font");
126 dpavlin 396 e.setAttribute("color","gray");
127 dpavlin 391 e.appendChild(document.createTextNode("["+result[i].frequency+"]"));
128     d.appendChild(e);
129     d.appendChild(document.createElement("br"));
130     }
131    
132     // Change header
133 dpavlin 451 header = (d.getElementsByTagName("h2"))[0].firstChild;
134 dpavlin 391
135 dpavlin 461 try {
136     header.replaceData(0, 14, "Search Results");
137     } catch(e) {}
138 dpavlin 391
139     }

  ViewVC Help
Powered by ViewVC 1.1.26