From 1b3b10d2ae7e40a611727dc9f8affbd2aff6bf9a Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 17 May 2020 13:05:12 -0700 Subject: [PATCH] Do not allow the sidebar to be dragged outside the window. (#1229) --- src/theme/book.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/theme/book.js b/src/theme/book.js index a335324d..849f8cef 100644 --- a/src/theme/book.js +++ b/src/theme/book.js @@ -456,6 +456,11 @@ function playpen_text(playpen) { // Toggle sidebar sidebarToggleButton.addEventListener('click', function sidebarToggle() { if (html.classList.contains("sidebar-hidden")) { + var current_width = parseInt( + document.documentElement.style.getPropertyValue('--sidebar-width'), 10); + if (current_width < 150) { + document.documentElement.style.setProperty('--sidebar-width', '150px'); + } showSidebar(); } else if (html.classList.contains("sidebar-visible")) { hideSidebar(); @@ -476,7 +481,16 @@ function playpen_text(playpen) { html.classList.add('sidebar-resizing'); } function resize(e) { - document.documentElement.style.setProperty('--sidebar-width', (e.clientX - sidebar.offsetLeft) + 'px'); + var pos = (e.clientX - sidebar.offsetLeft); + if (pos < 20) { + hideSidebar(); + } else { + if (html.classList.contains("sidebar-hidden")) { + showSidebar(); + } + pos = Math.min(pos, window.innerWidth - 100); + document.documentElement.style.setProperty('--sidebar-width', pos + 'px'); + } } //on mouseup remove windows functions mousemove & mouseup function stopResize(e) {