source: trunk/Packages/synapse/docs/help/tip_search.js

Last change on this file was 2, checked in by chronos, 12 years ago
  • Přidáno: Základní kostra projektu.
  • Přidáno: Knihovna synapse.
File size: 7.4 KB
Line 
1// Tipue 1.63 (modified for pasdoc)
2
3
4// ---------- script properties ----------
5
6
7var results_location = "_tipue_results.html";
8var return_results = 10;
9var include_num = 1;
10var bold_query = 0;
11var include_url = 0;
12
13
14// ---------- end of script properties ----------
15
16
17var cookies = document.cookie;
18var tp = cookies.indexOf('tid=');
19var pn = cookies.indexOf('tin=');
20
21var lnf = 'Your search did not match any documents.<p>Make sure all keywords are spelled correctly.<br>Try different or more general keywords.';
22var lp = 'Previous ';
23var ln = 'Next ';
24
25if (tp != -1) {
26 var st = tp + 4;
27 var en = cookies.indexOf(';', st);
28 if (en == -1) {
29 en = cookies.length;
30 }
31 var dit = cookies.substring(st, en);
32 dit = unescape(dit);
33}
34if (pn != -1) {
35 var st = pn + 4;
36 var en = cookies.indexOf(';', st);
37 if (en == -1) {
38 en = cookies.length;
39 }
40 var tn = cookies.substring(st, en);
41}
42
43var od = dit;
44var nr = return_results;
45tn = parseInt(tn);
46var nb = tn + nr;
47var nc = 0;
48var nd = 0;
49var tr = new Array();
50var rt = new Array();
51var co = 0;
52var tm = 0;
53
54if (dit.charAt(0) == '"' && dit.charAt(dit.length - 1) == '"') {
55 tm = 1;
56}
57var rn = dit.search(/ or /i);
58if (rn >= 0) {
59 tm = 2;
60}
61rn = dit.search(/-/i);
62if (rn >= 0 && tm != 1) {
63 rn = dit.search(/ /i);
64 if (rn != 0) {
65 dit = dit.replace(/-/gi, ' -');
66 }
67}
68rn = dit.search(/ not /i);
69if (rn >= 0 && tm != 1) {
70 dit = dit.replace(/ not /gi, ' -');
71}
72rn = dit.search(/\+/i);
73if (rn >= 0) {
74 rn = dit.search(/ /i);
75 if (rn != 0) {
76 dit = dit.replace(/\+/gi, ' +');
77 }
78}
79
80if (tm == 0) {
81 var woin = new Array();
82 dit = dit.replace(/ and /gi, ' ');
83 var wt = dit.split(' ');
84 for (var a = 0; a < wt.length; a++) {
85 woin[a] = 0;
86 if (wt[a].charAt(0) == '-') {
87 woin[a] = 1;
88 }
89 }
90 for (var a = 0; a < wt.length; a++) {
91 wt[a] = wt[a].replace(/^\-|^\+/gi, '');
92 }
93 a = 0;
94 for (var c = 0; c < s.length; c++) {
95 var es = s[c].split('^');
96 var rk = 100;
97 if (es[5] == null) {
98 es[5] = '0';
99 }
100 if (parseInt(es[5]) > 10) {
101 es[5] = '10';
102 }
103 var pa = 0;
104 var nh = 0;
105 for (var i = 0; i < woin.length; i++) {
106 if (woin[i] == 0) {
107 nh++;
108 var nt = 0;
109 var pat = new RegExp(wt[i], 'i');
110 rn = es[0].search(pat);
111 if (rn >= 0) {
112 rk = rk - 11;
113 rk = rk - parseInt(es[5]);
114 nt = 1;
115 }
116 rn = es[2].search(pat);
117 if (rn >= 0) {
118 rk = rk - 11;
119 rk = rk - parseInt(es[5]);
120 nt = 1;
121 }
122 rn = es[3].search(pat);
123 if (rn >= 0) {
124 rk = rk - 11;
125 rk = rk - parseInt(es[5]);
126 nt = 1;
127 }
128 if (nt == 1) {
129 pa++;
130 }
131 }
132 if (woin[i] == 1) {
133 var pat = new RegExp(wt[i], 'i');
134 rn = es[0].search(pat);
135 if (rn >= 0) {
136 pa = 0;
137 }
138 rn = es[2].search(pat);
139 if (rn >= 0) {
140 pa = 0;
141 }
142 rn = es[3].search(pat);
143 if (rn >= 0) {
144 pa = 0;
145 }
146 }
147 }
148 if (pa == nh) {
149 tr[a] = rk + '^' + s[c];
150 a++;
151 }
152 }
153 tr.sort();
154 co = a;
155}
156
157if (tm == 1) {
158 dit = dit.replace(/"/gi, '');
159 var a = 0;
160 var pat = new RegExp(dit, 'i');
161 for (var c = 0; c < s.length; c++) {
162 var es = s[c].split('^');
163 var rk = 100;
164 if (es[5] == null) {
165 es[5] = '0';
166 }
167 if (parseInt(es[5]) > 10) {
168 es[5] = '10';
169 }
170 rn = es[0].search(pat);
171 if (rn >= 0) {
172 rk = rk - 11;
173 rk = rk - parseInt(es[5]);
174 }
175 rn = es[2].search(pat);
176 if (rn >= 0) {
177 rk = rk - 11;
178 rk = rk - parseInt(es[5]);
179 }
180 rn = es[3].search(pat);
181 if (rn >= 0) {
182 rk = rk - 11;
183 rk = rk - parseInt(es[5]);
184 }
185 if (rk < 100) {
186 tr[a] = rk + '^' + s[c];
187 a++;
188 }
189 }
190 tr.sort();
191 co = a;
192}
193
194if (tm == 2) {
195 dit = dit.replace(/ or /gi, ' ');
196 var wt = dit.split(' ');
197 var a = 0;
198 for (var i = 0; i < wt.length; i++) {
199 var pat = new RegExp(wt[i], 'i');
200 for (var c = 0; c < s.length; c++) {
201 var es = s[c].split('^');
202 var rk = 100;
203 if (es[5] == null) {
204 es[5] = '0';
205 }
206 if (parseInt(es[5]) > 10) {
207 es[5] = '10';
208 }
209 var pa = 0;
210 var rn = es[0].search(pat);
211 if (rn >= 0) {
212 rk = rk - 11;
213 rk = rk - parseInt(es[5]);
214 if (rn >= 0) {
215 for (var e = 0; e < rt.length; e++) {
216 if (s[c] == rt[e]) {
217 pa = 1;
218 }
219 }
220 }
221 }
222 rn = es[2].search(pat);
223 if (rn >= 0) {
224 rk = rk - 11;
225 rk = rk - parseInt(es[5]);
226 if (rn >= 0) {
227 for (var e = 0; e < rt.length; e++) {
228 if (s[c] == rt[e]) {
229 pa = 1;
230 }
231 }
232 }
233 }
234 var rn = es[3].search(pat);
235 if (rn >= 0) {
236 rk = rk - 11;
237 rk = rk - parseInt(es[5]);
238 if (rn >= 0) {
239 for (var e = 0; e < rt.length; e++) {
240 if (s[c] == rt[e]) {
241 pa = 1;
242 }
243 }
244 }
245 }
246 if (rk < 100 && pa == 0) {
247 rt[a] = s[c];
248 tr[a] = rk + '^' + s[c];
249 a++;
250 co++;
251 }
252 }
253 }
254 tr.sort();
255}
256
257function write_cookie(nw) {
258 document.cookie = 'tid=' + escape(od) + '; path=/';
259 document.cookie = 'tin=' + nw + '; path=/';
260}
261
262
263// ---------- External references ----------
264
265
266var tip_Num = co;
267
268function tip_query() {
269 if (od != 'undefined' && od != null) document.tip_Form.d.value = od;
270}
271
272function tip_num() {
273 document.write(co);
274}
275
276function tip_out() {
277 if (co == 0) {
278 document.write(lnf);
279 return;
280 }
281 if (tn + nr > co) {
282 nd = co;
283 } else {
284 nd = tn + nr;
285 }
286 for (var a = tn; a < nd; a++) {
287 var os = tr[a].split('^');
288 if (os[5] == null) {
289 os[5] = '0';
290 }
291 if (bold_query == 1 && tm == 0) {
292 for (var i = 0; i < wt.length; i++) {
293 var lw = wt[i].length;
294 var tw = new RegExp(wt[i], 'i');
295 rn = os[3].search(tw);
296 if (rn >= 0) {
297 var o1 = os[3].slice(0, rn);
298 var o2 = os[3].slice(rn, rn + lw);
299 var o3 = os[3].slice(rn + lw);
300 os[3] = o1 + '<b>' + o2 + '</b>' + o3;
301 }
302 }
303 }
304 if (bold_query == 1 && tm == 1) {
305 var lw = dit.length;
306 var tw = new RegExp(dit, 'i');
307 rn = os[3].search(tw);
308 if (rn >= 0) {
309 var o1 = os[3].slice(0, rn);
310 var o2 = os[3].slice(rn, rn + lw);
311 var o3 = os[3].slice(rn + lw);
312 os[3] = o1 + '<b>' + o2 + '</b>' + o3;
313 }
314 }
315 if (include_num == 1) {
316 document.write(a + 1, '. ');
317 }
318 if (os[5] == '0') {
319 document.write('<a href="', os[2], '">', os[1], '</a>');
320 }
321 if (os[5] == '1') {
322 document.write('<a href="', os[2], '" target="_blank">', os[1], '</a>');
323 }
324 if (os[5] != '0' && os[5] != '1') {
325 document.write('<a href="', os[2], '" target="', os[5], '">', os[1], '</a>');
326 }
327 if (os[3].length > 1) {
328 document.write('<br>', os[3]);
329 }
330 if (include_url == 1) {
331 if (os[5] == '0') {
332 document.write('<br><a href="', os[2], '">', os[2], '</a><p>');
333 }
334 if (os[5] == '1') {
335 document.write('<br><a href="', os[2], '" target="_blank">', os[2], '</a><p>');
336 }
337 if (os[5] != '0' && os[5] != '1') {
338 document.write('<br><a href="', os[2], '" target="', os[5], '">', os[2], '</a><p>');
339 }
340 } else {
341 document.write('<p>');
342 }
343 }
344 if (co > nr) {
345 nc = co - nb;
346 if (nc > nr) {
347 nc = nr;
348 }
349 document.write('<p>');
350 }
351 if (tn > 1) {
352 document.write('<a href="', results_location, '" onclick="write_cookie(', tn - nr, ')">', lp, nr, '</a> &nbsp;');
353 }
354 if (nc > 0) {
355 document.write('<a href="', results_location, '" onclick="write_cookie(', tn + nr, ')">', ln, nc, '</a>');
356 }
357}
Note: See TracBrowser for help on using the repository browser.