diff --git a/src/theme/book.js b/src/theme/book.js index 489d994aaf..a89a73ec9d 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -415,8 +415,7 @@ function playpen_text(playpen) { try { localStorage.setItem('mdbook-sidebar', 'hidden'); } catch (e) { } } - // Toggle sidebar - sidebarToggleButton.addEventListener('click', function sidebarToggle() { + function toggleSidebar() { if (html.classList.contains("sidebar-hidden")) { showSidebar(); } else if (html.classList.contains("sidebar-visible")) { @@ -428,7 +427,10 @@ function playpen_text(playpen) { showSidebar(); } } - }); + } + + // Toggle sidebar + sidebarToggleButton.addEventListener('click', toggleSidebar); document.addEventListener('touchstart', function (e) { firstContact = { @@ -455,6 +457,17 @@ function playpen_text(playpen) { } }, { passive: true }); + document.addEventListener('keydown', function (e) { + if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { return; } + + switch (e.key) { + case 'F9': + console.log(window.location.href); + toggleSidebar(); + break; + } + }); + // Scroll sidebar to current active section var activeSection = sidebar.querySelector(".active"); if (activeSection) { @@ -468,18 +481,28 @@ function playpen_text(playpen) { switch (e.key) { case 'ArrowRight': + case 'j': + e.preventDefault(); + var previousButton = document.querySelector('.nav-chapters.previous'); + if (previousButton) { + window.location.href = previousButton.href; + } + break; + case 'ArrowLeft': + case 'k': e.preventDefault(); var nextButton = document.querySelector('.nav-chapters.next'); if (nextButton) { window.location.href = nextButton.href; } break; - case 'ArrowLeft': + case 'h': e.preventDefault(); - var previousButton = document.querySelector('.nav-chapters.previous'); - if (previousButton) { - window.location.href = previousButton.href; - } + // TODO: add code + break; + case 'l': + e.preventDefault(); + // TODO: add code break; } });