/[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 10 by dpavlin, Fri Sep 10 12:16:21 2004 UTC revision 29 by dpavlin, Fri Sep 24 15:44:27 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.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");
# Line 53  BFilter.prototype.element_id = function Line 70  BFilter.prototype.element_id = function
70                          }                          }
71                  }                  }
72          }          }
73            return null;
74  }  }
75    
76    
# Line 79  BFilter.prototype.results = function (ht Line 97  BFilter.prototype.results = function (ht
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    
# Line 94  BFilter.prototype.debug = function (html Line 114  BFilter.prototype.debug = function (html
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    
# Line 117  BFilter.prototype.binarySearch = functio Line 135  BFilter.prototype.binarySearch = functio
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;
# Line 134  BFilter.prototype.binarySearch = functio Line 152  BFilter.prototype.binarySearch = functio
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;
# Line 153  BFilter.prototype.filter = function (doc Line 171  BFilter.prototype.filter = function (doc
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    
# Line 169  BFilter.prototype.filter = function (doc Line 187  BFilter.prototype.filter = function (doc
187          // start anim icon          // start anim icon
188          //results("<img  src=\"pie.gif\">&nbsp;Please wait, filtering...\n",1);          //results("<img  src=\"pie.gif\">&nbsp;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          }          }
# Line 219  BFilter.prototype.filter = function (doc Line 222  BFilter.prototype.filter = function (doc
222    
223  }  }
224    
   

Legend:
Removed from v.10  
changed lines
  Added in v.29

  ViewVC Help
Powered by ViewVC 1.1.26