Skip to content

Commit

Permalink
DDBPRO-41
Browse files Browse the repository at this point in the history
  • Loading branch information
mbuechner committed Feb 12, 2024
1 parent 029e5b6 commit a257190
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions web/themes/custom/ddbp/src/js/elements/departments.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,35 @@ const addHover = () => {
});
};

const addFocus = () => {
// Add focus event to departmentLinks
departmentLinks.forEach(link => {
link.addEventListener('focus', ({ target }) => {
// remove active image styles
[...departmentImages, ...departmentLinks]
.forEach((item) => item.classList.remove(departmentShowClass));

// get hovered element
const activeLinkId = target.getAttribute('data-id')
? target.dataset.id
: target.closest('[data-id]').dataset.id;

// select active image and add styles to it
const activeImage =
document.querySelector(`.departments__images .department-teaser-mini__image[data-id="${activeLinkId}"]`);
const activeLink =
document.querySelector(`.departments__departments a[data-id="${activeLinkId}"]`);

activeImage.classList.add(departmentShowClass);
activeLink.classList.add(departmentShowClass);
});
});
}

(() => {
if (departments && !isMobile()) {
setActive();
addHover();
addFocus();
}
})();

0 comments on commit a257190

Please sign in to comment.