/[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 397 - (show annotations)
Thu Jul 22 19:07:16 2004 UTC (19 years, 9 months ago) by dpavlin
File MIME type: application/javascript
File size: 3521 byte(s)
results now preserver query arguments and that is used if page is not
accessed through web server (because referer isn't used if you don't access
pages via web server)

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").toLowerCase() == id.toLowerCase() ))
62 {
63 return m;
64 }
65 else
66 {
67 var r=findDivHelper(m, id);
68 if(r) return r;
69 }
70 }
71 return null;
72 }
73
74 // Function to find a specified "DIV" element by id
75 function findDiv(id)
76 {
77 return findDivHelper(document.body,id);
78 }
79
80 // Print results to page
81 function printResults(result)
82 {
83 //clearTimeout(watchdog_id);
84 //debug("clearTimeout = "+watchdog_id);
85 debug("printResults("+result.length+")");
86
87 var d = findDiv("results");
88
89 // Null result output
90 if(result.length < 1)
91 {
92 var header = (d.getElementsByTagName("h2"))[0].firstChild;
93 header.replaceData(0, 14, "Nothing Found ");
94
95 if(search_err != "")
96 {
97 e = document.createElement("font");
98 e.setAttribute("color","red");
99 e.setAttribute("size","+1");
100 e.appendChild(document.createTextNode(search_err));
101 d.appendChild(e);
102 d.appendChild(document.createElement("br"));
103 }
104
105 return;
106 }
107
108 // Add results to main document
109 for(var i=result.length-1; i>=0; i--)
110 {
111 var e = document.createElement("font");
112
113 e = document.createElement("a");
114 e.setAttribute("href",result[i].link+location.search);
115 // e.setAttribute("target","_blank");
116 e.appendChild(document.createTextNode(result[i].title));
117 d.appendChild(e);
118 d.appendChild(document.createTextNode(" "));
119
120 e = document.createElement("font");
121 e.setAttribute("color","gray");
122 e.appendChild(document.createTextNode("["+result[i].frequency+"]"));
123 d.appendChild(e);
124 d.appendChild(document.createElement("br"));
125 d.appendChild(document.createElement("br"));
126 }
127
128 // Change header
129 var header = (d.getElementsByTagName("h2"))[0].firstChild;
130
131 header.replaceData(0, 14, "Search Results");
132
133 }

  ViewVC Help
Powered by ViewVC 1.1.26