Skip to content

Fix sidebar animation and other behavior #2750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/front-end/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ h6:target::before {
box-sizing: border-box;
background-color: var(--bg);
}
.no-js .page-wrapper,
html:not(.js) .page-wrapper,
.js:not(.sidebar-resizing) .page-wrapper {
transition: margin-left 0.3s ease, transform 0.3s ease; /* Animation: slide away */
}
[dir=rtl] .js:not(.sidebar-resizing) .page-wrapper {
[dir=rtl]:not(.js) .page-wrapper,
[dir=rtl].js:not(.sidebar-resizing) .page-wrapper {
transition: margin-right 0.3s ease, transform 0.3s ease; /* Animation: slide away */
}

Expand Down
11 changes: 5 additions & 6 deletions src/front-end/js/book.js
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,6 @@ aria-label="Show hidden lines"></button>';
})();

(function sidebar() {
const body = document.querySelector('body');
const sidebar = document.getElementById('sidebar');
const sidebarLinks = document.querySelectorAll('#sidebar a');
const sidebarToggleButton = document.getElementById('sidebar-toggle');
Expand Down Expand Up @@ -548,7 +547,7 @@ aria-label="Show hidden lines"></button>';
});

function showSidebar() {
body.classList.add('sidebar-visible');
document.documentElement.classList.add('sidebar-visible');
Array.from(sidebarLinks).forEach(function(link) {
link.setAttribute('tabIndex', 0);
});
Expand All @@ -562,7 +561,7 @@ aria-label="Show hidden lines"></button>';
}

function hideSidebar() {
body.classList.remove('sidebar-visible');
document.documentElement.classList.remove('sidebar-visible');
Array.from(sidebarLinks).forEach(function(link) {
link.setAttribute('tabIndex', -1);
});
Expand Down Expand Up @@ -594,14 +593,14 @@ aria-label="Show hidden lines"></button>';
function initResize() {
window.addEventListener('mousemove', resize, false);
window.addEventListener('mouseup', stopResize, false);
body.classList.add('sidebar-resizing');
document.documentElement.classList.add('sidebar-resizing');
}
function resize(e) {
let pos = e.clientX - sidebar.offsetLeft;
if (pos < 20) {
hideSidebar();
} else {
if (!body.classList.contains('sidebar-visible')) {
if (!document.documentElement.classList.contains('sidebar-visible')) {
showSidebar();
}
pos = Math.min(pos, window.innerWidth - 100);
Expand All @@ -610,7 +609,7 @@ aria-label="Show hidden lines"></button>';
}
//on mouseup remove windows functions mousemove & mouseup
function stopResize() {
body.classList.remove('sidebar-resizing');
document.documentElement.classList.remove('sidebar-resizing');
window.removeEventListener('mousemove', resize, false);
window.removeEventListener('mouseup', stopResize, false);
}
Expand Down
Loading