document.addEventListener('DOMContentLoaded', function () { const path = window.location.pathname; const setActiveLink = (linkSelector) => { // Remove active class from all links document.querySelectorAll(linkSelector).forEach(item => { item.classList.remove('active'); }); // Find and add active class to the link that matches the current path const activeLink = document.querySelector(`${linkSelector}[href="${path}"]`); if (activeLink) { activeLink.classList.add('active'); if (activeLink.closest('.submenu')) { activeLink.closest('.submenu').querySelector('.nav-link').classList.add('active'); } } }; // Set active link for the navbar setActiveLink('.navbar-nav a'); // Set active link for the sidebar setActiveLink('.col-lg-4 a'); // Add click event listener to all navbar links document.querySelectorAll('.navbar-nav a').forEach(link => { link.addEventListener('click', function () { setActiveLink('.navbar-nav a'); // Store the active link in localStorage localStorage.setItem('activeNavLink', this.getAttribute('href')); }); }); // Add click event listener to all sidebar links document.querySelectorAll('.col-lg-4 a').forEach(link => { link.addEventListener('click', function () { setActiveLink('.col-lg-4 a'); // Store the active link in localStorage localStorage.setItem('activeSidebarLink', this.getAttribute('href')); }); }); const removeActiveClasses = (linkSelector, storageKey) => { document.querySelectorAll(linkSelector).forEach(item => { item.classList.remove('active'); }); localStorage.removeItem(storageKey); }; // Add click event listener to the logo document.querySelector('.navbar-brand').addEventListener('click', function () { removeActiveClasses('.navbar-nav a', 'activeNavLink'); removeActiveClasses('.col-lg-4 a', 'activeSidebarLink'); }); // Check if there's a stored active link for the navbar const activeNavLink = localStorage.getItem('activeNavLink'); if (activeNavLink) { const navLink = document.querySelector('.navbar-nav a[href="' + activeNavLink + '"]'); if (navLink) { navLink.classList.add('active'); } } // Check if there's a stored active link for the sidebar const activeSidebarLink = localStorage.getItem('activeSidebarLink'); if (activeSidebarLink) { const sidebarLink = document.querySelector('.col-lg-4 a[href="' + activeSidebarLink + '"]'); if (sidebarLink) { sidebarLink.classList.add('active'); } } }); // Get the button scrolls up let mybutton = document.getElementById("myBtn"); // When the user scrolls down 20px from the top of the document, show the button window.onscroll = function () { scrollFunction() }; function scrollFunction() { if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) { mybutton.style.display = "block"; } else { mybutton.style.display = "none"; } } // When the user clicks on the button, scroll to the top of the document function topFunction() { document.body.scrollTop = 0; document.documentElement.scrollTop = 0; }