/[jsFind]/trunk/html/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 /trunk/html/js/usage.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 42 - (hide annotations)
Wed Oct 19 23:54:21 2005 UTC (18 years, 7 months ago) by dpavlin
File MIME type: application/javascript
File size: 4004 byte(s)
cludge for Opera (no header update, ugly, should have own id)

1 dpavlin 1 /**
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 19 var form = document.getElementById('search');
31 dpavlin 31 if (! form && document.all) form = eval('document.all.search');
32 dpavlin 19 var query = form.elements['query'].value;
33     var index_name = form.elements['index_name'].options[form.elements['index_name'].selectedIndex].value;
34    
35     if(!query)
36 dpavlin 1 {
37     return false;
38     }
39    
40     if(query == null || query == "")
41     {
42     alert("No search terms entered!");
43     return false;
44     }
45    
46     var parsed_string = query.replace(/\s/gi,"+");
47     //var url=location.host+location.pathname+"?search="+parsed_string;
48 dpavlin 4 var url=location.pathname+"?";
49 dpavlin 6 if (index_name) url += "index_name="+index_name+"&";
50     url += "query="+parsed_string;
51 dpavlin 1 location = url;
52    
53     return false;
54     }
55    
56     // Function to help find a "DIV" element
57     function findDivHelper(n, id)
58     {
59     for(var m=n.firstChild; m != null; m=m.nextSibling)
60     {
61     if((m.nodeType == 1) &&
62     (m.tagName.toLowerCase() == "div") &&
63 dpavlin 19 m.getAttribute("id") &&
64 dpavlin 1 (m.getAttribute("id").toLowerCase() == id.toLowerCase() ))
65     {
66     return m;
67     }
68     else
69     {
70     var r=findDivHelper(m, id);
71     if(r) return r;
72     }
73     }
74     return null;
75     }
76    
77     // Function to find a specified "DIV" element by id
78     function findDiv(id)
79     {
80     return findDivHelper(document.body,id);
81     }
82    
83     // Print results to page
84     function printResults(result)
85     {
86     //clearTimeout(watchdog_id);
87     //debug("clearTimeout = "+watchdog_id);
88     debug("printResults("+result.length+")");
89    
90     var d = findDiv("results");
91 dpavlin 19 var header;
92 dpavlin 1
93     // Null result output
94     if(result.length < 1)
95     {
96 dpavlin 19 try {
97 dpavlin 42 header = (d.getElementsByTagName("h2"))[0].firstChild;
98 dpavlin 19 header.replaceData(0, 14, "Nothing Found ");
99     } catch(e) {}
100 dpavlin 1
101     if(search_err != "")
102     {
103     e = document.createElement("font");
104     e.setAttribute("color","red");
105     e.setAttribute("size","+1");
106     e.appendChild(document.createTextNode(search_err));
107     d.appendChild(e);
108     d.appendChild(document.createElement("br"));
109     }
110    
111     return;
112     }
113    
114     // Add results to main document
115     for(var i=result.length-1; i>=0; i--)
116     {
117     var e = document.createElement("font");
118    
119     e.setAttribute("color","blue");
120     e.setAttribute("size","+1");
121     e.appendChild(document.createTextNode(result[i].title));
122     d.appendChild(e);
123     d.appendChild(document.createTextNode(" "));
124     d.appendChild(document.createElement("br"));
125    
126     e = document.createElement("a");
127     e.setAttribute("href",result[i].link);
128     e.setAttribute("target","_blank");
129     e.appendChild(document.createTextNode(result[i].link));
130     d.appendChild(e);
131     d.appendChild(document.createTextNode(" "));
132    
133     e = document.createElement("font");
134     e.setAttribute("color","green");
135     e.appendChild(document.createTextNode("["+result[i].frequency+"]"));
136     d.appendChild(e);
137     d.appendChild(document.createElement("br"));
138     d.appendChild(document.createElement("br"));
139     }
140    
141     // Change header
142 dpavlin 19 header = (d.getElementsByTagName("h2"))[0].firstChild;
143 dpavlin 1
144 dpavlin 19 try {
145     header.replaceData(0, 14, "Search Results");
146     } catch(e) {}
147 dpavlin 1
148     }

  ViewVC Help
Powered by ViewVC 1.1.26