From 0d894414d9b33dea570b316003f16d44a18fc37e Mon Sep 17 00:00:00 2001 From: Caen De Silva Date: Mon, 28 Mar 2022 13:36:11 +0200 Subject: [PATCH] Move scripts into app.js --- _media/app.js | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 _media/app.js diff --git a/_media/app.js b/_media/app.js new file mode 100644 index 0000000..9763ec5 --- /dev/null +++ b/_media/app.js @@ -0,0 +1,73 @@ +// Handle the main navigation menu + +const mainNavigation = document.getElementById("main-navigation"); +const mobileNavigation = document.getElementById("mobile-navigation"); +var navigationOpen = false; + +function toggleNavigation() { + if (navigationOpen) { + hideNavigation(); + } else { + showNavigation(); + } +} + +function showNavigation() { + mobileNavigation.classList.add("flex"); + mobileNavigation.classList.remove("hidden"); + + navigationOpen = true; +} + +function hideNavigation() { + mobileNavigation.classList.remove("flex"); + mobileNavigation.classList.add("hidden"); + + navigationOpen = false; +} + +// Handle the documentation page sidebar + +var sidebarOpen = screen.width >= 768; + +const sidebar = document.getElementById("documentation-sidebar"); +const main = document.getElementById("documentation-content"); +const backdrop = document.getElementById("sidebar-backdrop"); + +const toggleButtons = document.querySelectorAll(".sidebar-button-wrapper"); + +function toggleSidebar() { + if (sidebarOpen) { + hideSidebar(); + } else { + showSidebar(); + } +} + +function showSidebar() { + sidebar.classList.remove("hidden"); + sidebar.classList.add("flex"); + backdrop.classList.remove("hidden"); + document.getElementById("app").style.overflow = "hidden"; + + toggleButtons.forEach((button) => { + button.classList.remove("open"); + button.classList.add("closed"); + }); + + sidebarOpen = true; +} + +function hideSidebar() { + sidebar.classList.add("hidden"); + sidebar.classList.remove("flex"); + backdrop.classList.add("hidden"); + document.getElementById("app").style.overflow = null; + + toggleButtons.forEach((button) => { + button.classList.add("open"); + button.classList.remove("closed"); + }); + + sidebarOpen = false; +} \ No newline at end of file