Skip to content

Commit

Permalink
Merge pull request #53 from hlxsites/feature/header-bugs
Browse files Browse the repository at this point in the history
fixed the header issues
  • Loading branch information
pardeepgera23 authored Oct 26, 2023
2 parents c1e98b3 + d55ea15 commit d58a41d
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions blocks/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,14 +116,19 @@ function addClassesToMenuItems(element, depth) {
const item = childItems[i];
// Add class to the immediate child element
item.classList.add('hs-menu-item', `hs-menu-depth-${depth}`);
const strong = item.querySelector('strong');
const link = item.querySelector('a');
if (strong) {
link.setAttribute('href', '#');
link.addEventListener('click', (event) => {
event.preventDefault();
});
}

const em = item.querySelector('em');

// Check if the href matches the current domain
const link = item.querySelector('a');
if (em) {
link.setAttribute('target', '_blank');
item.appendChild(link);
}
if (link && link.href === window.location.href) {
item.classList.add('active');
Expand All @@ -146,6 +151,8 @@ function addClassesToMenuItems(element, depth) {
});
}
item.prepend(spanElement);
item.appendChild(link);
item.appendChild(childElement);
const nextDepth = depth + 1;
addClassesToMenuItems(childElement, nextDepth);
}
Expand Down

0 comments on commit d58a41d

Please sign in to comment.