/[bfilter]/trunk/bfilter.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

Diff of /trunk/bfilter.js

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 12 by dpavlin, Sat Sep 11 08:21:57 2004 UTC revision 25 by dpavlin, Wed Sep 15 15:30:04 2004 UTC
# Line 9  function BFilter(arr) { Line 9  function BFilter(arr) {
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 function is called for each result
14          this.html_post = '</a><br/>';          this.result = function (arr) {
15          this.html_full_pre = '';                  return '<li><a href="'+arr[1]+'">'+
16          this.html_full_post = '';                          (this.hits % 2 == 0 ? '<span style="background: #e0e0e0;">' : '') +
17                            arr[0] +
18                            (this.hits % 2 == 0 ? '</span>' : '') +
19                            '</a></li>';
20            }
21    
22            // this function is called when updating innerHTML with results
23            this.display = function (html) {
24                    return '<ul>'+html+'</ul>';
25            }
26    
27    
28          if (! arr) {          if (! arr) {
29                  this.debug("ERROR: can't search empty array");                  this.debug("ERROR: can't search empty array");
# Line 53  BFilter.prototype.element_id = function Line 63  BFilter.prototype.element_id = function
63                          }                          }
64                  }                  }
65          }          }
66            return null;
67  }  }
68    
69    
# Line 79  BFilter.prototype.results = function (ht Line 90  BFilter.prototype.results = function (ht
90          // results_div.style.cursor = 'wait'; // 'auto'          // results_div.style.cursor = 'wait'; // 'auto'
91          var results_div = this.element_id("results");          var results_div = this.element_id("results");
92          if (clean) {          if (clean) {
93                  results_div.innerHTML = html + "\n";                  results_div.innerHTML = html;
94          } else {          } else {
95                  results_div.innerHTML += this.html_full_pre + html +"\n" + this.html_full_post;                  results_div.innerHTML += this.display(html);
96          }          }
97  }  }
98    
# Line 94  BFilter.prototype.debug = function (html Line 105  BFilter.prototype.debug = function (html
105          if (! html) { return 1; }          if (! html) { return 1; }
106    
107          var debug_div = this.element_id("debug",1);          var debug_div = this.element_id("debug",1);
108          if (! debug_div) { return; }          if (! debug_div) { return null; }
109    
110          debug_div.innerHTML += html + "<br>\n";          debug_div.innerHTML += html + "<br>\n";
111    
112            return null;
113  }  }
114    
115    
# Line 113  BFilter.prototype.binarySearch = functio Line 126  BFilter.prototype.binarySearch = functio
126                  var mid = (low + high) / 2;                  var mid = (low + high) / 2;
127                  var aTry = (mid < 1) ? 0 : parseInt(mid);                  var aTry = (mid < 1) ? 0 : parseInt(mid);
128                    
129                  var curr = arr[aTry][1].substr(0,find.length).toLowerCase();                  var curr = arr[aTry][0].substr(0,find.length).toLowerCase();
130                  this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr);                  this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr);
131                  if (curr < find) {                  if (curr < find) {
132                          low = aTry + 1;                          low = aTry + 1;
# Line 165  BFilter.prototype.filter = function (doc Line 178  BFilter.prototype.filter = function (doc
178          // start anim icon          // start anim icon
179          //results("<img  src=\"pie.gif\">&nbsp;Please wait, filtering...\n",1);          //results("<img  src=\"pie.gif\">&nbsp;Please wait, filtering...\n",1);
180    
181            var i;
182    
183          // full part? (optimization)          // full part? (optimization)
184          if (find.length == this.min_len) {          if (find.length == this.min_len) {
185                  var html = '';                  var html = '';
186                  for (var i = 0; i < this.arr[part].length; i++) {                  for (i = 0; i < this.arr[part].length; i++) {
187                          html += this.html_pre +                          html += 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";  
188                          this.hits++;                          this.hits++;
189                  }                  }
190                  this.results(html);                  this.results(html);
# Line 188  BFilter.prototype.filter = function (doc Line 196  BFilter.prototype.filter = function (doc
196                                    
197                          this.debug("loop "+from+" ... "+this.arr[part].length);                          this.debug("loop "+from+" ... "+this.arr[part].length);
198    
199                          var html = '';                          html = '';
200    
201                          for(var i = from ; i < this.arr[part].length ; i++) {                          for(i = from ; i < this.arr[part].length ; i++) {
202                                  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) {
203                                          this.debug("loop exit at "+i);                                          this.debug("loop exit at "+i);
204                                          break;                                          break;
205                                  }                                  }
206                                  html += this.html_pre +                                  html += 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";  
207                                  this.hits++;                                  this.hits++;
208                          }                          }
209    
# Line 215  BFilter.prototype.filter = function (doc Line 216  BFilter.prototype.filter = function (doc
216    
217  }  }
218    
   

Legend:
Removed from v.12  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.26