/[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 461 - (hide annotations)
Wed Sep 22 18:00:21 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: application/javascript
File size: 3614 byte(s)
don't die in IE5.5

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     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 dpavlin 451 m.getAttribute("id") &&
62 dpavlin 391 (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 dpavlin 451 var header;
90 dpavlin 391
91     // Null result output
92     if(result.length < 1)
93     {
94 dpavlin 451 header = (d.getElementsByTagName("h2"))[0].firstChild;
95 dpavlin 461 try {
96     header.replaceData(0, 14, "Nothing Found ");
97     } catch(e) {}
98 dpavlin 391
99     if(search_err != "")
100     {
101     e = document.createElement("font");
102     e.setAttribute("color","red");
103     e.setAttribute("size","+1");
104     e.appendChild(document.createTextNode(search_err));
105     d.appendChild(e);
106     d.appendChild(document.createElement("br"));
107     }
108    
109     return;
110     }
111    
112     // Add results to main document
113     for(var i=result.length-1; i>=0; i--)
114     {
115     var e = document.createElement("font");
116    
117     e = document.createElement("a");
118 dpavlin 397 e.setAttribute("href",result[i].link+location.search);
119     // e.setAttribute("target","_blank");
120 dpavlin 396 e.appendChild(document.createTextNode(result[i].title));
121 dpavlin 391 d.appendChild(e);
122     d.appendChild(document.createTextNode(" "));
123    
124     e = document.createElement("font");
125 dpavlin 396 e.setAttribute("color","gray");
126 dpavlin 391 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 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