Mark subpaths as active in the sidebar
All checks were successful
Tests / test (push) Successful in 24s
All checks were successful
Tests / test (push) Successful in 24s
This commit is contained in:
parent
b074a3413a
commit
d093d422ce
1 changed files with 22 additions and 13 deletions
|
@ -2,15 +2,7 @@
|
|||
* This script marks the current path as active in the sidebar.
|
||||
*/
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const currentPath = window.location.pathname;
|
||||
const sidebarLinks = document.querySelectorAll('.sidebar-link');
|
||||
|
||||
sidebarLinks.forEach(link => {
|
||||
// Skip links that are inside buttons (like logout)
|
||||
if (link.tagName === 'BUTTON') return;
|
||||
|
||||
if (link.getAttribute('href') === currentPath) {
|
||||
const markActive = (link) => {
|
||||
const parentItem = link.closest('.sidebar-item');
|
||||
if (parentItem) {
|
||||
parentItem.classList.add('active');
|
||||
|
@ -18,5 +10,22 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||
link.classList.add('active');
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const checkLink = (fuzzy) => {
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const currentPath = window.location.pathname;
|
||||
const sidebarLinks = [...document.querySelectorAll('a.sidebar-link')]
|
||||
|
||||
const exactMatches = sidebarLinks.filter(link => link.getAttribute('href') === currentPath)
|
||||
if (exactMatches.length > 0) {
|
||||
markActive(exactMatches[0])
|
||||
} else {
|
||||
fuzzyMatches = sidebarLinks.filter(link => currentPath.startsWith(link.getAttribute('href')))
|
||||
if (fuzzyMatches.length > 0) {
|
||||
const longestMatch = fuzzyMatches.sort((a, b) => b.href.length - a.href.length)[0]
|
||||
markActive(longestMatch)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue