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 |
this.html_pre = '<a href="'; |
|
13 |
this.html_mid = '">'; |
this.results_html = ''; |
14 |
this.html_post = '</a><br/>'; |
|
15 |
this.html_full_pre = ''; |
// this function is called for each result |
16 |
this.html_full_post = ''; |
this.result = function (arr) { |
17 |
|
this.results_html += '<li><a href="'+arr[1]+'">'+ |
18 |
|
(this.hits % 2 == 0 ? '<span style="background: #e0e0e0;">' : '') + |
19 |
|
arr[0] + |
20 |
|
(this.hits % 2 == 0 ? '</span>' : '') + |
21 |
|
'</a></li>'; |
22 |
|
return true; |
23 |
|
} |
24 |
|
|
25 |
|
// this function is called when updating innerHTML with results |
26 |
|
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"); |
70 |
} |
} |
71 |
} |
} |
72 |
} |
} |
73 |
|
return null; |
74 |
} |
} |
75 |
|
|
76 |
|
|
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 |
|
this.results_html = ''; |
102 |
} else { |
} else { |
103 |
results_div.innerHTML += this.html_full_pre + html +"\n" + this.html_full_post; |
html = this.display(); |
104 |
|
if (html) results_div.innerHTML += html; |
105 |
} |
} |
106 |
} |
} |
107 |
|
|
114 |
if (! html) { return 1; } |
if (! html) { return 1; } |
115 |
|
|
116 |
var debug_div = this.element_id("debug",1); |
var debug_div = this.element_id("debug",1); |
117 |
if (! debug_div) { return; } |
if (! debug_div) { return null; } |
118 |
|
|
119 |
if (debug_div.innerHTML) { |
debug_div.innerHTML += html + "<br>\n"; |
120 |
debug_div.innerHTML =+ html + "x<br>\n"; |
|
121 |
} else { |
return null; |
|
debug_div.innerHTML = html + "y<br>\n"; |
|
|
} |
|
122 |
} |
} |
123 |
|
|
124 |
|
|
135 |
var mid = (low + high) / 2; |
var mid = (low + high) / 2; |
136 |
var aTry = (mid < 1) ? 0 : parseInt(mid); |
var aTry = (mid < 1) ? 0 : parseInt(mid); |
137 |
|
|
138 |
var curr = arr[aTry][1].substr(0,find.length).toLowerCase(); |
var curr = arr[aTry][0].substr(0,find.length).toLowerCase(); |
139 |
this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr+"<br>"); |
this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr); |
140 |
if (curr < find) { |
if (curr < find) { |
141 |
low = aTry + 1; |
low = aTry + 1; |
142 |
continue; |
continue; |
152 |
} |
} |
153 |
return aTry; |
return aTry; |
154 |
} |
} |
155 |
this.debug("lastTry="+lastTry+"<br>"); |
this.debug("lastTry="+lastTry); |
156 |
|
|
157 |
if (typeof (lastTry) != "undefined") { |
if (typeof (lastTry) != "undefined") { |
158 |
return lastTry; |
return lastTry; |
171 |
return; |
return; |
172 |
} |
} |
173 |
|
|
174 |
this.debug("filter: '"+find+"'<br>"); |
this.debug("filter: '"+find+"'"); |
175 |
|
|
176 |
var find_lc = find.toLowerCase(); |
var find_lc = find.toLowerCase(); |
177 |
|
|
187 |
// start anim icon |
// start anim icon |
188 |
//results("<img src=\"pie.gif\"> Please wait, filtering...\n",1); |
//results("<img src=\"pie.gif\"> Please wait, filtering...\n",1); |
189 |
|
|
190 |
|
var i; |
191 |
|
|
192 |
// full part? (optimization) |
// full part? (optimization) |
193 |
if (find.length == this.min_len) { |
if (find.length == this.min_len) { |
194 |
var html = ''; |
for (i = 0; i < this.arr[part].length; i++) { |
195 |
for (var i = 0; i < this.arr[part].length; i++) { |
this.result(this.arr[part][i]); |
|
html += this.html_pre + |
|
|
this.arr[part][i][0] + |
|
|
this.html_mid + |
|
|
(this.hits % 2 == 0 ? '<span style="background: #e0e0e0">' : ''); |
|
|
if (this.debug()) { html += i+": "; } |
|
|
html += this.arr[part][i][1] + |
|
|
(this.hits % 2 == 0 ? '</span>' : '') + |
|
|
this.html_post + "\n"; |
|
196 |
this.hits++; |
this.hits++; |
197 |
} |
} |
198 |
this.results(html); |
this.results(); |
199 |
} else { |
} else { |
200 |
|
|
201 |
var from = this.binarySearch(this.arr[part], find_lc); |
var from = this.binarySearch(this.arr[part], find_lc); |
202 |
|
|
203 |
if (from != null) { |
if (from != null) { |
204 |
|
|
205 |
this.debug("loop "+from+" ... "+this.arr[part].length)+"<br>\n"; |
this.debug("loop "+from+" ... "+this.arr[part].length); |
|
|
|
|
var html = ''; |
|
206 |
|
|
207 |
for(var i = from ; i < this.arr[part].length ; i++) { |
for(i = from ; i < this.arr[part].length ; i++) { |
208 |
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) { |
209 |
this.debug("loop exit at "+i); |
this.debug("loop exit at "+i); |
210 |
break; |
break; |
211 |
} |
} |
212 |
html += this.html_pre + |
this.result(this.arr[part][i]); |
|
this.arr[part][i][0] + |
|
|
this.html_mid + |
|
|
(this.hits % 2 == 0 ? '<span style="background: #e0e0e0">' : ''); |
|
|
if (this.debug()) { html += i+": "; } |
|
|
html += this.arr[part][i][1] + |
|
|
(this.hits % 2 == 0 ? '</span>' : '') + |
|
|
this.html_post + "\n"; |
|
213 |
this.hits++; |
this.hits++; |
214 |
} |
} |
215 |
|
|
216 |
this.results(html); |
this.results(); |
217 |
} |
} |
218 |
|
|
219 |
} |
} |
222 |
|
|
223 |
} |
} |
224 |
|
|
|
|
|