From 2298dfc20ea61575507532f8c5cbe8102eb1ad08 Mon Sep 17 00:00:00 2001 From: Bulat Musin Date: Mon, 5 Feb 2018 15:31:01 +0300 Subject: [PATCH] extract toggling code into toggleSidebar() --- src/theme/book.js | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/src/theme/book.js b/src/theme/book.js index f797e679..a89a73ec 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 = { @@ -460,17 +462,8 @@ function playpen_text(playpen) { switch (e.key) { case 'F9': - if (html.classList.contains("sidebar-hidden")) { - showSidebar(); - } else if (html.classList.contains("sidebar-visible")) { - hideSidebar(); - } else { - if (getComputedStyle(sidebar)['transform'] === 'none') { - hideSidebar(); - } else { - showSidebar(); - } - } + console.log(window.location.href); + toggleSidebar(); break; } }); @@ -490,19 +483,27 @@ function playpen_text(playpen) { case 'ArrowRight': case 'j': e.preventDefault(); - var nextButton = document.querySelector('.nav-chapters.next'); - if (nextButton) { - window.location.href = nextButton.href; + var previousButton = document.querySelector('.nav-chapters.previous'); + if (previousButton) { + window.location.href = previousButton.href; } break; case 'ArrowLeft': case 'k': e.preventDefault(); - var previousButton = document.querySelector('.nav-chapters.previous'); - if (previousButton) { - window.location.href = previousButton.href; + var nextButton = document.querySelector('.nav-chapters.next'); + if (nextButton) { + window.location.href = nextButton.href; } break; + case 'h': + e.preventDefault(); + // TODO: add code + break; + case 'l': + e.preventDefault(); + // TODO: add code + break; } }); })();