From c4c9e021e4fa2cf956bb499a294b71314f801b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Ryb=C3=A1rsky?= Date: Wed, 7 Feb 2024 18:17:38 +0100 Subject: [PATCH] Test JS --- assets/script.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/assets/script.js b/assets/script.js index f9929d4..1f9e0f5 100644 --- a/assets/script.js +++ b/assets/script.js @@ -134,10 +134,17 @@ async function doPageAction(requestData, wantsReturn = false) { } } -async function initAjax() { - const links = document.querySelectorAll('.navsite_link, .navpage_link'); +async function initAjaxNavigationEvents(){ + const allLinks = document.querySelectorAll('.navsite_link, .navpage_link'); + const pageLinks = document.querySelectorAll('.navpage_link'); - links.forEach(function (link) { + pageLinks.forEach(function (link) { + link.addEventListener('click', function () { + navLinks.classList.remove("active"); + }); + }); + + allLinks.forEach(function (link) { link.addEventListener('click', function (e) { e.preventDefault(); let site = this.dataset.site; @@ -153,6 +160,11 @@ async function initAjax() { toggleButton.addEventListener('click', () => { navLinks.classList.toggle("active") }) +} + +async function initAjax() { + + await initAjaxNavigationEvents(); await onPageLoad(); }