Skip to content

Commit 8c6e2dd

Browse files
authored
Do not allow the sidebar to be dragged outside the window. (rust-lang#1229)
1 parent ebc3c35 commit 8c6e2dd

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/theme/book.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,11 @@ function playpen_text(playpen) {
456456
// Toggle sidebar
457457
sidebarToggleButton.addEventListener('click', function sidebarToggle() {
458458
if (html.classList.contains("sidebar-hidden")) {
459+
var current_width = parseInt(
460+
document.documentElement.style.getPropertyValue('--sidebar-width'), 10);
461+
if (current_width < 150) {
462+
document.documentElement.style.setProperty('--sidebar-width', '150px');
463+
}
459464
showSidebar();
460465
} else if (html.classList.contains("sidebar-visible")) {
461466
hideSidebar();
@@ -476,7 +481,16 @@ function playpen_text(playpen) {
476481
html.classList.add('sidebar-resizing');
477482
}
478483
function resize(e) {
479-
document.documentElement.style.setProperty('--sidebar-width', (e.clientX - sidebar.offsetLeft) + 'px');
484+
var pos = (e.clientX - sidebar.offsetLeft);
485+
if (pos < 20) {
486+
hideSidebar();
487+
} else {
488+
if (html.classList.contains("sidebar-hidden")) {
489+
showSidebar();
490+
}
491+
pos = Math.min(pos, window.innerWidth - 100);
492+
document.documentElement.style.setProperty('--sidebar-width', pos + 'px');
493+
}
480494
}
481495
//on mouseup remove windows functions mousemove & mouseup
482496
function stopResize(e) {

0 commit comments

Comments
 (0)