browser: search toggles matching agent columns
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 7 Dec 2010 19:29:31 +0000 (20:29 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Wed, 15 Dec 2010 21:40:44 +0000 (22:40 +0100)
browser.plp
searchlocal.js

index ef260e118401dd5b81649c397d4b7646801348fe..9a865d4f0ff8a577b20c191af9604b08030c9fa3 100644 (file)
@@ -116,8 +116,11 @@ my $header = join('',
        '<th colspan="3">feature',
        (map {
                my $name = $caniuse->{agents}->{$_}->{browser};
        '<th colspan="3">feature',
        (map {
                my $name = $caniuse->{agents}->{$_}->{browser};
-               sprintf('<th colspan="%d" title="%s">%s',
+               sprintf('<th colspan="%d" class="%s" title="%s">%s',
                        scalar @{ $versions{$_} },
                        scalar @{ $versions{$_} },
+                       join(' ', map {"b-a-$_"} grep {$_}
+                               $_, $caniuse->{agents}->{$_}->{prefix},
+                       ),
                        join(' ',
                                sprintf('%.1f%%', sum(values %{ $canihas->{$_} })),
                                $name,
                        join(' ',
                                sprintf('%.1f%%', sum(values %{ $canihas->{$_} })),
                                $name,
index 8741044c4afce0b92cf9f876bcfc520e6ff8cfb4..eb284b7a53d3ffe53736e5b84079672364d9f2d8 100644 (file)
@@ -26,6 +26,26 @@ function filtercell(el, set, action) {
        }
 }
 
        }
 }
 
+function filtercols(table, match, action) {
+       var matchloc;
+       for (var y = 0; y < table.rows.length; y++) {
+               var loc = 0;
+               for (var x = 0; x < table.rows[y].cells.length; x++) {
+                       var cell = table.rows[y].cells[x];
+                       if (y == 0) {
+                               if (match(cell)) {
+                                       if (!matchloc) matchloc = [loc];
+                                       matchloc[1] = loc + cell.colSpan;
+                                       filtercell(table.children.item(x+2), true, action); // colgroup
+                               }
+                       }
+                       var keep = matchloc && loc >= matchloc[0] && loc < matchloc[1];
+                       filtercell(cell, keep, action);
+                       loc += cell.colSpan;
+               }
+       }
+}
+
 function filterrows(table, match, action) {
        var rows = table.tBodies[0].rows;
        for (var i = 0; i < rows.length; i++) {
 function filterrows(table, match, action) {
        var rows = table.tBodies[0].rows;
        for (var i = 0; i < rows.length; i++) {
@@ -47,6 +67,14 @@ function filtertable(query, action) {
                query = match[2];
        }
 
                query = match[2];
        }
 
+       if (document.querySelector('.b-a-'+query)) {
+               // column if class b-a-* exists
+               var match = function(th) {
+                       return new RegExp('-'+query+'\\b').test(th.className);
+               }
+               return filtercols(table, match, action || 'toggle');
+       }
+
        if (/^[A-Z0-9 ]{2,}$/.test(query)) {
                // category title if all uppercase
                var match = function(row) {
        if (/^[A-Z0-9 ]{2,}$/.test(query)) {
                // category title if all uppercase
                var match = function(row) {