document.addEventListener("DOMContentLoaded", function () { let sidebar = document.getElementById("sidebar"); let mainContent = document.getElementById("main-content"); let sidebarIndicator = document.getElementById("sidebar-indicator"); let collapseButton = document.getElementById("collapse-button"); let isSidebarOpen = false; sidebarIndicator.addEventListener("click", function () { sidebar.style.left = "0px"; mainContent.style.marginLeft = "250px"; sidebarIndicator.style.display = "none"; isSidebarOpen = true; }); collapseButton.addEventListener("click", function () { sidebar.style.left = "-250px"; mainContent.style.marginLeft = "0"; sidebarIndicator.style.display = "block"; isSidebarOpen = false; }); document.querySelectorAll('a[href^="#"]').forEach(anchor => { anchor.addEventListener("click", function (event) { event.preventDefault(); const targetId = this.getAttribute("href").substring(1); const targetSection = document.getElementById(targetId); if (targetSection) { window.scrollTo({ top: targetSection.offsetTop - 50, behavior: "smooth" }); } }); }); // Sidebar Keyboard Navigation function handleKeyAction(event, action) { if (event.key === "Enter" || event.key === " ") { event.preventDefault(); action(); } } sidebarIndicator.addEventListener("keydown", function (event) { handleKeyAction(event, () => { sidebar.style.left = "0px"; mainContent.style.marginLeft = "250px"; sidebarIndicator.style.display = "none"; isSidebarOpen = true; }); }); collapseButton.addEventListener("keydown", function (event) { handleKeyAction(event, () => { sidebar.style.left = "-250px"; mainContent.style.marginLeft = "0"; sidebarIndicator.style.display = "block"; isSidebarOpen = false; }); }); });