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

Contents of /trunk/html/js/usage.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (show annotations)
Sun Jul 11 20:18:25 2004 UTC (19 years, 9 months ago) by dpavlin
File MIME type: application/javascript
File size: 3636 byte(s)
initial import into subversion of version 0.1

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

  ViewVC Help
Powered by ViewVC 1.1.26