9 |
this.id_cache = Array(); |
this.id_cache = Array(); |
10 |
// total number of hits |
// total number of hits |
11 |
this.hits = 0; |
this.hits = 0; |
12 |
// before all results |
|
13 |
this.html_full_pre = '<ul>'; |
this.results_html = null; |
14 |
// before result |
|
15 |
this.html_pre = '<li><a href="'; |
// this function is called for each result |
16 |
// id from result |
this.result = function (arr) { |
17 |
this.html_mid = '">'; |
this.results_html += '<li><a href="'+arr[1]+'">'+ |
18 |
// title from result (which was searched also) |
(this.hits % 2 == 0 ? '<span style="background: #e0e0e0;">' : '') + |
19 |
this.html_post = '</a></li>'; |
arr[0] + |
20 |
// after all results |
(this.hits % 2 == 0 ? '</span>' : '') + |
21 |
this.html_full_post = '</ul>'; |
'</a></li>'; |
22 |
// highlight for every second row in results |
return true; |
23 |
//this.html_hl_start = '<span style="background: #e0e0e0;">'; |
} |
24 |
//this.html_hl_end = '</span>'; |
|
25 |
this.html_hl_start = ''; |
// this function is called when updating innerHTML with results |
26 |
this.html_hl_end = ''; |
this.display = function () { |
27 |
|
if (this.results_html) { |
28 |
|
return '<ul>'+this.results_html+'</ul>'; |
29 |
|
} else { |
30 |
|
return null; |
31 |
|
} |
32 |
|
} |
33 |
|
|
34 |
|
|
35 |
if (! arr) { |
if (! arr) { |
36 |
this.debug("ERROR: can't search empty array"); |
this.debug("ERROR: can't search empty array"); |
97 |
// results_div.style.cursor = 'wait'; // 'auto' |
// results_div.style.cursor = 'wait'; // 'auto' |
98 |
var results_div = this.element_id("results"); |
var results_div = this.element_id("results"); |
99 |
if (clean) { |
if (clean) { |
100 |
results_div.innerHTML = html + "\n"; |
results_div.innerHTML = html; |
101 |
} else { |
} else { |
102 |
results_div.innerHTML += this.html_full_pre + html +"\n" + this.html_full_post; |
html = this.display(); |
103 |
|
if (html) results_div.innerHTML += html; |
104 |
} |
} |
105 |
} |
} |
106 |
|
|
134 |
var mid = (low + high) / 2; |
var mid = (low + high) / 2; |
135 |
var aTry = (mid < 1) ? 0 : parseInt(mid); |
var aTry = (mid < 1) ? 0 : parseInt(mid); |
136 |
|
|
137 |
var curr = arr[aTry][1].substr(0,find.length).toLowerCase(); |
var curr = arr[aTry][0].substr(0,find.length).toLowerCase(); |
138 |
this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr); |
this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr); |
139 |
if (curr < find) { |
if (curr < find) { |
140 |
low = aTry + 1; |
low = aTry + 1; |
190 |
|
|
191 |
// full part? (optimization) |
// full part? (optimization) |
192 |
if (find.length == this.min_len) { |
if (find.length == this.min_len) { |
|
var html = ''; |
|
193 |
for (i = 0; i < this.arr[part].length; i++) { |
for (i = 0; i < this.arr[part].length; i++) { |
194 |
html += this.html_pre + |
this.result(this.arr[part][i]); |
|
this.arr[part][i][0] + |
|
|
this.html_mid + |
|
|
(this.hits % 2 == 0 ? this.html_hl_start : ''); |
|
|
//if (this.debug()) { html += i+": "; } |
|
|
html += this.arr[part][i][1] + |
|
|
(this.hits % 2 == 0 ? this.html_hl_end : '') + |
|
|
this.html_post + "\n"; |
|
195 |
this.hits++; |
this.hits++; |
196 |
} |
} |
197 |
this.results(html); |
this.results(); |
198 |
} else { |
} else { |
199 |
|
|
200 |
var from = this.binarySearch(this.arr[part], find_lc); |
var from = this.binarySearch(this.arr[part], find_lc); |
203 |
|
|
204 |
this.debug("loop "+from+" ... "+this.arr[part].length); |
this.debug("loop "+from+" ... "+this.arr[part].length); |
205 |
|
|
|
html = ''; |
|
|
|
|
206 |
for(i = from ; i < this.arr[part].length ; i++) { |
for(i = from ; i < this.arr[part].length ; i++) { |
207 |
if (this.arr[part][i][1].substring(0,find.length).toLowerCase() != find_lc) { |
if (this.arr[part][i][0].substring(0,find.length).toLowerCase() != find_lc) { |
208 |
this.debug("loop exit at "+i); |
this.debug("loop exit at "+i); |
209 |
break; |
break; |
210 |
} |
} |
211 |
html += this.html_pre + |
this.result(this.arr[part][i]); |
|
this.arr[part][i][0] + |
|
|
this.html_mid + |
|
|
(this.hits % 2 == 0 ? this.html_hl_start : ''); |
|
|
//if (this.debug()) { html += i+": "; } |
|
|
html += this.arr[part][i][1] + |
|
|
(this.hits % 2 == 0 ? this.html_hl_end : '') + |
|
|
this.html_post + "\n"; |
|
212 |
this.hits++; |
this.hits++; |
213 |
} |
} |
214 |
|
|
215 |
this.results(html); |
this.results(); |
216 |
} |
} |
217 |
|
|
218 |
} |
} |
221 |
|
|
222 |
} |
} |
223 |
|
|
|
|
|