Skip to content

Commit

Permalink
Do not allow the sidebar to be dragged outside the window. (rust-lang…
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed May 17, 2020
1 parent ebc3c35 commit 8c6e2dd
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/theme/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {
Expand Down

0 comments on commit 8c6e2dd

Please sign in to comment.