--- trunk/bfilter.js 2004/09/14 22:42:55 22 +++ trunk/bfilter.js 2004/09/15 15:30:04 25 @@ -9,21 +9,21 @@ this.id_cache = Array(); // total number of hits this.hits = 0; - // before all results - this.html_full_pre = ''; - // highlight for every second row in results - //this.html_hl_start = ''; - //this.html_hl_end = ''; - this.html_hl_start = ''; - this.html_hl_end = ''; + + // this function is called for each result + this.result = function (arr) { + return '
  • '+ + (this.hits % 2 == 0 ? '' : '') + + arr[0] + + (this.hits % 2 == 0 ? '' : '') + + '
  • '; + } + + // this function is called when updating innerHTML with results + this.display = function (html) { + return ''; + } + if (! arr) { this.debug("ERROR: can't search empty array"); @@ -90,9 +90,9 @@ // results_div.style.cursor = 'wait'; // 'auto' var results_div = this.element_id("results"); if (clean) { - results_div.innerHTML = html + "\n"; + results_div.innerHTML = html; } else { - results_div.innerHTML += this.html_full_pre + html +"\n" + this.html_full_post; + results_div.innerHTML += this.display(html); } } @@ -126,7 +126,7 @@ var mid = (low + high) / 2; var aTry = (mid < 1) ? 0 : parseInt(mid); - var curr = arr[aTry][1].substr(0,find.length).toLowerCase(); + var curr = arr[aTry][0].substr(0,find.length).toLowerCase(); this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr); if (curr < find) { low = aTry + 1; @@ -184,14 +184,7 @@ if (find.length == this.min_len) { var html = ''; for (i = 0; i < this.arr[part].length; i++) { - html += this.html_pre + - 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"; + html += this.result(this.arr[part][i]); this.hits++; } this.results(html); @@ -206,18 +199,11 @@ html = ''; for(i = from ; i < this.arr[part].length ; i++) { - 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) { this.debug("loop exit at "+i); break; } - html += this.html_pre + - 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"; + html += this.result(this.arr[part][i]); this.hits++; } @@ -230,4 +216,3 @@ } -