/[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 11 by dpavlin, Fri Sep 10 12:42:58 2004 UTC revision 28 by dpavlin, Thu Sep 23 18:22:50 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 = null;
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          } 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    
# Line 94  BFilter.prototype.debug = function (html Line 113  BFilter.prototype.debug = function (html
113          if (! html) { return 1; }          if (! html) { return 1; }
114    
115          var debug_div = this.element_id("debug",1);          var debug_div = this.element_id("debug",1);
116          if (! debug_div) { return; }          if (! debug_div) { return null; }
117    
118          if (debug_div.innerHTML) {          debug_div.innerHTML += html + "<br>\n";
119                  debug_div.innerHTML =+ html + "x<br>\n";  
120          } else {          return null;
                 debug_div.innerHTML = html + "y<br>\n";  
         }  
121  }  }
122    
123    
# Line 117  BFilter.prototype.binarySearch = functio Line 134  BFilter.prototype.binarySearch = functio
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+"<br>");                  this.debug("low="+low+" high="+high+" lastTry="+lastTry+" "+aTry+": "+curr);
139                  if (curr < find) {                  if (curr < find) {
140                          low = aTry + 1;                          low = aTry + 1;
141                          continue;                          continue;
# Line 134  BFilter.prototype.binarySearch = functio Line 151  BFilter.prototype.binarySearch = functio
151                  }                  }
152                  return aTry;                  return aTry;
153          }          }
154          this.debug("lastTry="+lastTry+"<br>");          this.debug("lastTry="+lastTry);
155    
156          if (typeof (lastTry) != "undefined") {          if (typeof (lastTry) != "undefined") {
157                  return lastTry;                  return lastTry;
# Line 153  BFilter.prototype.filter = function (doc Line 170  BFilter.prototype.filter = function (doc
170                  return;                  return;
171          }          }
172    
173          this.debug("filter: '"+find+"'<br>");          this.debug("filter: '"+find+"'");
174    
175          var find_lc = find.toLowerCase();          var find_lc = find.toLowerCase();
176    
# Line 169  BFilter.prototype.filter = function (doc Line 186  BFilter.prototype.filter = function (doc
186          // start anim icon          // start anim icon
187          //results("<img  src=\"pie.gif\">&nbsp;Please wait, filtering...\n",1);          //results("<img  src=\"pie.gif\">&nbsp;Please wait, filtering...\n",1);
188    
189            var i;
190    
191          // full part? (optimization)          // full part? (optimization)
192          if (find.length == this.min_len) {          if (find.length == this.min_len) {
193                  var html = '';                  for (i = 0; i < this.arr[part].length; i++) {
194                  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";  
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);
201    
202                  if (from != null) {                  if (from != null) {
203                                    
204                          this.debug("loop "+from+" ... "+this.arr[part].length)+"<br>\n";                          this.debug("loop "+from+" ... "+this.arr[part].length);
   
                         var html = '';  
205    
206                          for(var 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 ? '<span style="background: #e0e0e0">' : '');  
                                 //if (this.debug()) { html += i+": "; }  
                                 html += this.arr[part][i][1] +  
                                         (this.hits % 2 == 0 ? '</span>' : '') +  
                                         this.html_post + "\n";  
212                                  this.hits++;                                  this.hits++;
213                          }                          }
214    
215                          this.results(html);                          this.results();
216                  }                  }
217    
218          }          }
# Line 219  BFilter.prototype.filter = function (doc Line 221  BFilter.prototype.filter = function (doc
221    
222  }  }
223    
   

Legend:
Removed from v.11  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC 1.1.26