|
53 | 53 | const currentPath = window.location.pathname; |
54 | 54 | const navLinks = document.querySelectorAll('nav a'); |
55 | 55 | const navLabels = document.querySelectorAll('nav label.nav-link'); |
56 | | - |
| 56 | + let normalizedCurrentPath = currentPath.replace(/\/$/, '') || '/'; |
57 | 57 | navLinks.forEach(link => { |
58 | 58 | const linkPath = link.getAttribute('href'); |
59 | | - if (linkPath && (linkPath === currentPath || |
60 | | - (linkPath !== '/' && currentPath.startsWith(linkPath)))) { |
61 | | - link.classList.add('active'); |
| 59 | + if (linkPath) { |
| 60 | + let normalizedLinkPath = linkPath.replace(/\/$/, '') || '/'; |
| 61 | + if (normalizedCurrentPath === '/' || normalizedCurrentPath === '') { |
| 62 | + if (normalizedLinkPath === '/' || normalizedLinkPath === '') { |
| 63 | + link.classList.add('active'); |
| 64 | + } |
| 65 | + } else { |
| 66 | + if (normalizedLinkPath === normalizedCurrentPath || |
| 67 | + (normalizedLinkPath !== '/' && normalizedCurrentPath.startsWith(normalizedLinkPath + '/'))) { |
| 68 | + link.classList.add('active'); |
| 69 | + } |
| 70 | + } |
62 | 71 | } |
63 | 72 | }); |
64 | 73 | |
65 | 74 | navLabels.forEach(label => { |
66 | 75 | const parent = label.closest('li'); |
67 | 76 | const submenuLinks = parent.querySelectorAll('.dropdown-glass a'); |
| 77 | + let hasActiveSubmenu = false; |
68 | 78 | submenuLinks.forEach(submenuLink => { |
69 | 79 | const submenuPath = submenuLink.getAttribute('href'); |
70 | | - if (submenuPath && (submenuPath === currentPath || |
71 | | - (submenuPath !== '/' && currentPath.startsWith(submenuPath)))) { |
72 | | - label.classList.add('active'); |
| 80 | + if (submenuPath) { |
| 81 | + let normalizedSubmenuPath = submenuPath.replace(/\/$/, '') || '/'; |
| 82 | + console.log('Checking submenu path:', normalizedSubmenuPath, 'against current:', normalizedCurrentPath); |
| 83 | + if (normalizedCurrentPath === '/' || normalizedCurrentPath === '') { |
| 84 | + return; |
| 85 | + } |
| 86 | + const isExactMatch = normalizedSubmenuPath === normalizedCurrentPath; |
| 87 | + const isPathMatch = normalizedSubmenuPath !== '/' && |
| 88 | + normalizedSubmenuPath !== '' && |
| 89 | + normalizedCurrentPath.startsWith(normalizedSubmenuPath + '/'); |
| 90 | + |
| 91 | + if (isExactMatch || isPathMatch) { |
| 92 | + hasActiveSubmenu = true; |
| 93 | + console.log('Found active submenu:', normalizedSubmenuPath); |
| 94 | + } |
73 | 95 | } |
74 | 96 | }); |
| 97 | + if (hasActiveSubmenu) { |
| 98 | + label.classList.add('active'); |
| 99 | + console.log('Activating dropdown label:', label.textContent.trim()); |
| 100 | + } |
75 | 101 | }); |
76 | 102 | |
77 | 103 | // Mobile menu functionality |
|
0 commit comments