1 function filtercell(el, set, action) {
4 el.classList[set ? 'add' : 'remove'](action);
7 if (set) el.classList.toggle(action);
10 el.style.display = set ? '' : 'none';
11 if (!Element.prototype.hasOwnProperty('classList')) return;
14 el.classList.remove('focus');
15 el.classList.remove('target');
19 function filterrows(table, match, action) {
20 var rows = table.tBodies[0].rows;
21 for (var i = 0; i < rows.length; i++) {
22 filtercell(rows[i], match(rows[i]), action);
26 function filtertable(query, action) {
27 var table = document.getElementsByTagName('TABLE')[0];
29 if (/^[A-Z0-9 ]{2,}$/.test(query)) {
30 // category title if all uppercase
31 var match = function(row) {
32 return row.cells[0].title.match(query, 'i');
36 // title text (case-insensitive unless caps in input)
37 var match = function(row) {
38 return row.cells[1].textContent.match(query, /[A-Z]/.test(query) ? '' : 'i');
41 filterrows(table, match, action || 'filter');
44 function newelement(tagname, attrlist, childlist) {
45 if (!attrlist) return document.createTextNode(tagname);
46 var el = document.createElement(tagname);
47 for (var name in attrlist)
48 el.setAttribute(name, attrlist[name]);
49 if (childlist) for (var i = 0; i < childlist.length; i++)
50 el.appendChild(childlist[i]);
54 function prependsearch(target) {
55 target.parentNode.insertBefore(newelement(
59 onsubmit: "filtertable(this.q.value); this.q.value = ''; return false",
65 onkeyup: "filtertable(this.value, this.value.length > 1 ? 'focus' : 'reset')",
70 onclick: "filtertable(this.form.q.value, 'target')",
72 newelement('input', {type:'submit', value:'filter'}),