browser: fix link and hover styling
[sheet.git] / browser.plp
index 2de845858d4db807566c8270fde517c0fb5e346a..d9da9820f577f23e28bf87164b72e1af9ac4cde1 100644 (file)
@@ -16,18 +16,27 @@ Html({
 :>
 <h1>Browser compatibility</h1>
 
-<p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page
-<:
-my $canihas = do 'browser-usage.inc.pl'
-       or printf "<p>Browser usage data not found: <em>%s</em>.</p>\n", $! || $@;
-
-print "with $_ browser usage statistics." for map {
-       my $ref = $_->{-source} || 'unknown';
-       $ref = sprintf '<a href="%s">%s</a>', $_, $ref for $_->{-url} || ();
-       $ref .= " $_" for $_->{-date} || ();
-       $ref
-} $canihas || ();
-:>
+<p>Alternate view of Fyrd's <a href="http://caniuse.com/">when can I use...</a> page<:
+my ($canihas, $usage);
+given ($get{usage} // 'wm') {
+       when (!$_) {
+               # none
+       }
+       when (!/^\w+$/) {
+               printf "<p>Invalid browser usage data request: <em>%s</em>",
+                       'identifier must be alphanumeric name or <q>0</q>';
+       }
+       $canihas = do "browser-usage-$_.inc.pl" or do {
+               printf "<p>Browser usage data not found: <em>%s</em>", $! || $@;
+               break;
+       };
+       $usage = $_;
+       my $ref = $canihas->{-source} || 'unknown';
+       $ref = sprintf '<a href="%s">%s</a>', $_, $ref for $canihas->{-url} || ();
+       $ref .= " $_" for $canihas->{-date} || ();
+       print "\nwith $ref browser usage statistics";
+}
+:>.
 </p>
 
 <div id="browser">
@@ -35,23 +44,24 @@ print "with $_ browser usage statistics." for map {
 my $caniuse = do 'browser-support.inc.pl' or die $! || $@;
 
 my %CSTATS = (
-       'n'   => 'l0',
-       'y'   => 'l6',
-       'y x' => 'l5',
-       'a'   => 'l4',
-       'a x' => 'l4',
+       'n'   => 'l1',
+       'y'   => 'l5',
+       'y x' => 'l4',
+       'a'   => 'l3',
+       'a x' => 'l3',
        'p j' => 'l2',
        'j'   => 'l2',
        'p'   => 'l2',
-       'u'   => 'l9',
+       'u'   => 'l0',
 );
 my %CSTATUS = (
-       unoff => 'l0', # unofficial
-       wd    => 'l4', # draft
-       cr    => 'l5', # candidate
-       pr    => 'l5', # proposed
-       rec   => 'l6', # recommendation
-       ietf  => 'l6', # standard
+       unoff => 'l1', # unofficial
+       wd    => 'l3', # draft
+       cr    => 'l4', # candidate
+       pr    => 'l4', # proposed
+       rec   => 'l5', # recommendation
+       other => 'l5', # non-w3
+       ietf  => 'l5', # standard
 );
 my %versions;
 if (my ($somerow) = values %{ $caniuse->{data} }) {
@@ -66,11 +76,12 @@ $canihas ||= {
        map {
                $_ => +{
                        map {
-                               ($_->[4] =>  0 ), # future
-                               ($_->[3] =>  .5), # next
-                               ($_->[0] =>  5 ), # past
-                               ($_->[1] => 10 ), # previous
-                               ($_->[2] => 30 ), # current
+                               my $zero = $#$_ - 2;  # baseline index
+                               ($_->[$zero - 2] =>  .5), # past
+                               ($_->[$zero - 1] => 10 ), # previous
+                               ($_->[$zero + 2] =>  0 ), # future
+                               ($_->[$zero + 1] =>  .5), # next
+                               ($_->[$zero    ] => 30 ), # current
                        } $caniuse->{agents}->{$_}->{versions}
                }
        } @browsers
@@ -172,7 +183,7 @@ for my $id (sort {
        for ($row->{status}) {
                my $cell = $_ // '-';
                $cell = sprintf '<a href="%s">%s</a>', $_, $cell for $row->{spec} // ();
-               printf '<td title="%s" class="%s">%s',
+               printf '<td title="%s" class="%s">%s',
                        $caniuse->{statuses}->{$_}, $CSTATUS{$_} // '', $cell;
        }
        for my $browser (@browsers) {
@@ -233,15 +244,15 @@ sub showversions {
 
 <div class="legend">
        <table class="glyphs"><tr>
-       <td class="X l6">supported
-       <td class="X l5">prefixed
-       <td class="X l4">partial
+       <td class="X l5">supported
+       <td class="X l4">prefixed
+       <td class="X l3">partial
        <td class="X l2">external (js/plugin)
-       <td class="X l0">missing
-       <td class="X l9">unknown
+       <td class="X l1">missing
+       <td class="X l0">unknown
        </table>
 
-       <div>
+       <p><: if ($usage) { :>
                Usage percentage:
                <span class="  p0">0</span> -
                <span class="p p0 p00">.01</span> -
@@ -249,12 +260,21 @@ sub showversions {
                <span class="p p1">10</span> -
                <span class="p p2">20</span> -
                <span class="p p5">majority</span>
-       </div>
+<: } else { :>
+               <table class="glyphs"><tr>
+                       <td class="p p1">previous version</td>
+                       <td class="p p3">current</td>
+                       <td class="p p0 p00">upcoming (within months)</td>
+                       <td class="  p0">future (within a year)</td>
+               </table>
+<: } :>        </p>
 
        <div class="right">
                <ul class="legend legend-set">
                <li>default <strong>style</strong> is
                        <:= defined $get{style} && 'set to ' :><em><:= $style :></em>
+               <li><strong>usage</strong> source is
+                       <:= !defined $get{usage} && 'default ' :><:= defined $usage ? "<em>$usage</em>" : 'not included (<em>0</em>)' :>
                </ul>
        </div>
 </div>