/[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

Contents of /trunk2/out/js/usage.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 451 - (show annotations)
Wed Sep 15 21:15:50 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: application/javascript
File size: 3558 byte(s)
jsFind: fix warnings

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

  ViewVC Help
Powered by ViewVC 1.1.26