From 38c0269665153d60b66e0300b858cef22b4b539f Mon Sep 17 00:00:00 2001 From: bruno Date: Mon, 5 Feb 2024 21:23:21 +0100 Subject: [PATCH] run ajax after loaded --- assets/script.js | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/assets/script.js b/assets/script.js index 823fd8d..2f0e1fd 100644 --- a/assets/script.js +++ b/assets/script.js @@ -144,22 +144,24 @@ function logout() { }); } -let links = document.querySelectorAll('.navsite_link, .navpage_link'); +function initAjax() { + let links = document.querySelectorAll('.navsite_link, .navpage_link'); // Add click event listener to each link -links.forEach(function(link) { - link.addEventListener('click', function(e) { - e.preventDefault(); + links.forEach(function (link) { + link.addEventListener('click', function (e) { + e.preventDefault(); - // Get page and site information - let page = this.closest('.navpage_item').dataset.page; - let site = this.closest('.navsite_item').dataset.site; + // Get page and site information + let page = this.closest('.navpage_item').dataset.page; + let site = this.closest('.navsite_item').dataset.site; - if(site && page){ - navigateTo(site, page); - } + if (site && page) { + navigateTo(site, page); + } - // You can use this information to update the URL or perform other actions + // You can use this information to update the URL or perform other actions + }); }); -}); - +} +document.addEventListener('DOMContentLoaded', initAjax);