35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
export function setActiveNavItem(contentType, href) {
|
|
const staticNavItems = document.querySelectorAll('#menu > ul > li > a');
|
|
const etapeNavItems = document.querySelectorAll('#etapes-liste li a');
|
|
|
|
for (let item of staticNavItems) {
|
|
item.classList.remove('is-active');
|
|
}
|
|
|
|
for (let item of etapeNavItems) {
|
|
item.closest('li').classList.add('inactive');
|
|
}
|
|
|
|
if (href === '/' || href === '') {
|
|
staticNavItems[0].classList.add('is-active');
|
|
for (let item of etapeNavItems) {
|
|
item.closest('li').classList.remove('inactive');
|
|
}
|
|
|
|
} else {
|
|
if (contentType === 'static') {
|
|
for (let item of staticNavItems) {
|
|
if (item.getAttribute('href') === href) {
|
|
item.classList.add('is-active');
|
|
}
|
|
}
|
|
} else if (contentType === 'etape') {
|
|
for (let item of etapeNavItems) {
|
|
if (item.getAttribute('href') === href) {
|
|
item.closest('li').classList.remove('inactive');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
} |