From 5624637f30e18ba74c28a3d542fc17cf2eb961db Mon Sep 17 00:00:00 2001 From: Iziram Date: Mon, 19 Aug 2024 18:22:40 +0200 Subject: [PATCH] =?UTF-8?q?fix=20blocage=20d=C3=A9filement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/static/css/scodoc97.css | 6 ++++++ app/templates/formsemestre/menu.j2 | 13 +++++-------- app/templates/sidebar.j2 | 23 +++++++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/app/static/css/scodoc97.css b/app/static/css/scodoc97.css index 02013ea85..3c22c11f0 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 bc8d3e76a..a21e923bb 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 0af58c954..428cd8361 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