keyboard: move ?keys code and styling from common include
[sheet.git] / keyboard.plp
1 <(common.inc.plp)><:
2
3 my $mode = lc($Request || 'altgr');
4 my $include = "$mode.eng";
5
6 my $info = eval { Data($include) } || {};
7 warn "error in $include: ", @{$@} if ref $@;
8 $mode = $info->{title} // $mode;
9
10 my $showkeys //= !exists $get{keys} ? undef :
11         ($get{keys} ne '0' && ($get{keys} || 'always'));
12 my @keystyle = (
13         '<!--[if lte IE 6]><style> .help dl.legend dt {margin:0 0 1px} </style><![endif]-->',
14         '<!--[if lte IE 7]><style> .help dl.legend dd {float:none} </style><![endif]-->',
15         !$showkeys ? '<style> .no {visibility:hidden} </style>' :
16         $showkeys eq 'ghost' ? '<style> .no, .alias {opacity:.5} </style>' : (),
17         '<script type="text/javascript" src="/keys.js?1.6" async></script>',
18 );
19
20 Html({
21         title => "\L$mode\E keyboard cheat sheet",
22         version => $info->{version} || '0.1',
23         description => $info->{description} //
24                 ["Keyboard cheat sheet for the default controls of $mode."],
25         keywords => [@{ $info->{keywords} // [] }, qw'
26                 sheet cheat reference overview keyboard control commands shortkey
27         '],
28         stylesheet => [qw( light dark circus mono red )],
29         data => ["$include.inc.pl"],
30         raw => \@keystyle,
31 });
32
33 %{$info} or Abort(
34         "Requested keyboard <q>$mode</q> not available",
35         '404 request not found',
36 );
37
38 say "<h1>$mode cheat sheet</h1>";
39 say "<p>$_</p>" for $info->{intro} // ();
40 say "<h2>", $info->{mode}->{''}, " (default)</h2>"
41         if $info->{mode} and %{ $info->{mode} } > 1;
42
43 use Shiar_Sheet::Keyboard 2.08;
44 my $keys = Shiar_Sheet::Keyboard->new($info);
45 $keys->map($get{map}) or undef $get{map};
46 $keys->print_rows($get{rows} || $info->{moderows}, $info->{rows});
47
48 {
49         say "<hr/>\n";
50         say '<div class="help">';
51
52         use List::MoreUtils qw( part );
53         my @gflags = part {/^g\d/} sort keys %{ $keys->{flag} };
54
55         say "\t", '<div class="left">';
56         $keys->print_legend('legend-types', $gflags[1]);
57         say "\t</div>\n";
58
59         say "\t", '<div class="right">';
60         $keys->print_legend('legend-options', $gflags[0]);
61         say '';
62
63         say "\t\t", '<ul class="legend legend-set">';
64
65         say "\t\t<li>keyboard <strong>map</strong> is ",
66                 ($get{map} ? 'set to ' : ''), "<em>$keys->{map}</em>";
67         say "\t\t<li><strong>keys</strong> are ",
68                 "<em>", ($showkeys ? 'always shown' : 'hidden if unassigned'), "</em>",
69                 (!defined $showkeys && ' by default');
70         say "\t\t<li>default <strong>style</strong> is ",
71                 (defined $get{style} && 'set to '), "<em>$style</em>";
72
73         say "\t\t</ul>";
74         say "\t</div>\n";
75         say "</div>\n";
76 }