File tree 3 files changed +61
-1
lines changed
3 files changed +61
-1
lines changed Original file line number Diff line number Diff line change @@ -543,7 +543,7 @@ function playground_text(playground, hidden = true) {
543
543
544
544
( function chapterNavigation ( ) {
545
545
document . addEventListener ( 'keydown' , function ( e ) {
546
- if ( e . altKey || e . ctrlKey || e . metaKey || e . shiftKey ) { return ; }
546
+ if ( e . altKey || e . ctrlKey || e . metaKey ) { return ; }
547
547
if ( window . search && window . search . hasFocus ( ) ) { return ; }
548
548
var html = document . querySelector ( 'html' ) ;
549
549
@@ -559,6 +559,42 @@ function playground_text(playground, hidden = true) {
559
559
window . location . href = previousButton . href ;
560
560
}
561
561
}
562
+ function showHelp ( ) {
563
+ document . getElementById ( "help-overlay" ) . style . display = "block" ;
564
+ let help = `<h2 id="help-title">Keyboard shortcuts</h2>` ;
565
+ help += "<p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p>" ;
566
+ help += "<p>Press <kbd>s</kbd> to search in the book</p>" ;
567
+ help += "<p>Press <kbd>?</kbd> to show this help</p>" ;
568
+ help += "<p>Press <kbd>Esc</kbd> to hide this help</p>" ;
569
+
570
+ document . getElementById ( "help-overlay" ) . innerHTML = help ;
571
+
572
+ document . addEventListener ( 'keydown' , function ( e ) {
573
+ if ( e . altKey || e . ctrlKey || e . metaKey || e . shiftKey ) { return ; }
574
+
575
+ switch ( e . key ) {
576
+ case 'Escape' :
577
+ e . preventDefault ( ) ;
578
+ hideHelp ( ) ;
579
+ break ;
580
+ }
581
+ } ) ;
582
+ }
583
+ function hideHelp ( ) {
584
+ document . getElementById ( "help-overlay" ) . style . display = "none" ;
585
+ }
586
+
587
+ if ( e . shiftKey ) {
588
+ switch ( e . key ) {
589
+ case '?' :
590
+ e . preventDefault ( ) ;
591
+ showHelp ( ) ;
592
+ break ;
593
+ }
594
+
595
+ return ;
596
+ }
597
+
562
598
switch ( e . key ) {
563
599
case 'ArrowRight' :
564
600
e . preventDefault ( ) ;
Original file line number Diff line number Diff line change @@ -242,3 +242,26 @@ sup {
242
242
.result-no-output {
243
243
font-style : italic;
244
244
}
245
+
246
+ # help-overlay {
247
+ position : fixed;
248
+ display : none;
249
+ width : 20% ;
250
+ height : 60% ;
251
+ top : 10% ;
252
+ left : 40% ;
253
+ right : 0 ;
254
+ bottom : 0 ;
255
+ background-color : rgba (225 , 225 , 225 , 1 );
256
+ z-index : 2 ;
257
+ cursor : pointer;
258
+ border-width : 3px ;
259
+ border-color : black;
260
+ border-style : solid;
261
+ border-radius : 25px ;
262
+
263
+ padding : 10px ;
264
+ }
265
+ # help-title {
266
+ text-align : center;
267
+ }
Original file line number Diff line number Diff line change 62
62
<script src =" {{ resource " toc.js" }} " ></script >
63
63
</head >
64
64
<body >
65
+ <div id =" help-overlay" ></div >
65
66
<div id =" body-container" >
66
67
<!-- Work around some values being stored in localStorage wrapped in quotes -->
67
68
<script >
You can’t perform that action at this time.
0 commit comments