diff --git a/app/static/css/scodoc97.css b/app/static/css/scodoc97.css index 02013ea8..3c22c11f 100644 --- a/app/static/css/scodoc97.css +++ b/app/static/css/scodoc97.css @@ -270,4 +270,10 @@ print { body { position: relative; +} + +.no-scroll { + overflow: hidden !important; + margin: 0 !important; + height: 100vh !important; } \ No newline at end of file diff --git a/app/templates/formsemestre/menu.j2 b/app/templates/formsemestre/menu.j2 index bc8d3e76..a21e923b 100644 --- a/app/templates/formsemestre/menu.j2 +++ b/app/templates/formsemestre/menu.j2 @@ -20,12 +20,6 @@ box-sizing: border-box; } - .no-scroll { - overflow: hidden !important; - margin: 0 !important; - height: 100vh !important; - } - /* CSS menu */ .sco-formsemestre-menu { background-color: var(--sco-formsemestre-color-primary); @@ -372,8 +366,6 @@ // Affichage du menu mobile au clic navbarToggle.addEventListener("click", () => { - document.body.classList.toggle("no-scroll"); - navbarMenu.classList.toggle("active"); navbarToggle.classList.toggle("active"); @@ -385,6 +377,10 @@ // Fermeture des dropdowns dropdownItems.forEach((item) => item.removeAttribute("open")); + + // Blockage du scroll + toggleScroll(); + }); // Fermeture du menu mobile au clic en dehors du menu @@ -393,6 +389,7 @@ navbarMenu.classList.remove("active"); navbarToggle.classList.remove("active"); navbarToggle.setAttribute("aria-expanded", "false"); + toggleScroll(); } }); diff --git a/app/templates/sidebar.j2 b/app/templates/sidebar.j2 index 0af58c95..428cd836 100755 --- a/app/templates/sidebar.j2 +++ b/app/templates/sidebar.j2 @@ -124,6 +124,29 @@ const sidebar = document.querySelector('#sidebar'); const expanded = sidebar.getAttribute('aria-expanded') === 'true'; sidebar.setAttribute('aria-expanded', !expanded); + toggleScroll(); + } + + function toggleScroll(){ + + const changeScroll = (b) => { + document.querySelectorAll("body, html").forEach(el => el.classList.toggle("no-scroll", b)); + } + + const sidebar = document.querySelector('#sidebar'); + const formSemestreMenu = document.querySelector('.sco-formsemestre-menu-menu'); + + const sidebarExpanded = sidebar ? sidebar.getAttribute('aria-expanded') === 'true' : false; + const formSemestreMenuExpanded = formSemestreMenu ? formSemestreMenu.classList.contains("active") : false; + + let isScrollToggled = document.body.classList.contains("no-scroll"); + + if (isScrollToggled && !sidebarExpanded && !formSemestreMenuExpanded) { + changeScroll(false); + } + else if (!isScrollToggled && (sidebarExpanded || formSemestreMenuExpanded)) { + changeScroll(true); + } } \ No newline at end of file