/[webpac]/trunk2/out/js/filter.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

Annotation of /trunk2/out/js/filter.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 411 - (hide annotations)
Sun Sep 5 22:22:37 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: application/javascript
File size: 1235 byte(s)
implemented filtered sorted indexes

1 dpavlin 411 /*
2     Very slow filtering function for unordered lists
3     Dobrica Pavlinusic, dpavlin@rot13.org 2004-09-06
4     */
5    
6     function filter(document, id, regex) {
7    
8     var min_len = 1;
9     var debug = 0;
10    
11     // get UL element by ID
12     var ul = document.getElementById(id);
13     if (! ul) { return; }
14    
15     // get all LI elements
16     var li = ul.getElementsByTagName("li");
17    
18     // get out if too few characters in search
19     if (regex && regex.length < min_len) {
20     return;
21     }
22    
23     var status = "";
24    
25     if (debug) { status += "filter: "+regex+"<br>"; }
26    
27     var total = 0;
28     var visible = 0;
29    
30     if (debug) { status += "elements = "+li.length+"<br>"; }
31    
32     if (regex) { var reg = new RegExp(regex, 'i'); }
33    
34     for (var i = 0; i < li.length; i++) {
35    
36     var text = li[i].innerHTML.replace(/<[^>]+>/g,"");
37     if (debug) { status += i+": "+text; }
38    
39     total++;
40    
41     if (reg && reg.test(text)) {
42     li[i].style.display = '';
43     visible++;
44     if (debug) { status += " visible " };
45     } else {
46     li[i].style.display = 'none';
47     if (debug) { status += " hidden " };
48     }
49     if (debug) { status += "<br>"; }
50    
51     }
52    
53     status += "shown "+visible+" of "+total+" entries for <em>"+regex+"</em><br>";
54    
55     var status_div = document.getElementById("status");
56     if (status_div) {
57     status_div.innerHTML = status;
58     }
59     }

  ViewVC Help
Powered by ViewVC 1.1.26