@@ -623,7 +623,7 @@ aria-label="Show hidden lines"></button>';
623623
624624( function chapterNavigation ( ) {
625625 document . addEventListener ( 'keydown' , function ( e ) {
626- if ( e . altKey || e . ctrlKey || e . metaKey || e . shiftKey ) {
626+ if ( e . altKey || e . ctrlKey || e . metaKey ) {
627627 return ;
628628 }
629629 if ( window . search && window . search . hasFocus ( ) ) {
@@ -643,6 +643,55 @@ aria-label="Show hidden lines"></button>';
643643 window . location . href = previousButton . href ;
644644 }
645645 }
646+ function showHelp ( ) {
647+ const container = document . getElementById ( 'mdbook-help-container' ) ;
648+ const overlay = document . getElementById ( 'mdbook-help-popup' ) ;
649+ container . style . display = 'flex' ;
650+
651+ // Clicking outside the popup will dismiss it.
652+ const mouseHandler = event => {
653+ if ( overlay . contains ( event . target ) ) {
654+ return ;
655+ }
656+ if ( event . button !== 0 ) {
657+ return ;
658+ }
659+ event . preventDefault ( ) ;
660+ event . stopPropagation ( ) ;
661+ document . removeEventListener ( 'mousedown' , mouseHandler ) ;
662+ hideHelp ( ) ;
663+ } ;
664+
665+ // Pressing esc will dismiss the popup.
666+ const escapeKeyHandler = event => {
667+ if ( event . key === 'Escape' ) {
668+ event . preventDefault ( ) ;
669+ event . stopPropagation ( ) ;
670+ document . removeEventListener ( 'keydown' , escapeKeyHandler , true ) ;
671+ hideHelp ( ) ;
672+ }
673+ } ;
674+ document . addEventListener ( 'keydown' , escapeKeyHandler , true ) ;
675+ document . getElementById ( 'mdbook-help-container' )
676+ . addEventListener ( 'mousedown' , mouseHandler ) ;
677+ }
678+ function hideHelp ( ) {
679+ document . getElementById ( 'mdbook-help-container' ) . style . display = 'none' ;
680+ }
681+
682+ // Usually needs the Shift key to be pressed
683+ switch ( e . key ) {
684+ case '?' :
685+ e . preventDefault ( ) ;
686+ showHelp ( ) ;
687+ break ;
688+ }
689+
690+ // Rest of the keys are only active when the Shift key is not pressed
691+ if ( e . shiftKey ) {
692+ return ;
693+ }
694+
646695 switch ( e . key ) {
647696 case 'ArrowRight' :
648697 e . preventDefault ( ) ;
0 commit comments