Skip to content

Commit

Permalink
new logic for catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
seanchoi-dev committed Jan 22, 2025
1 parent 02d1594 commit 8aff28b
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,21 @@ export default async function init(el) {
decorateMerchCardLinkAnalytics(merchCard);

// Adding aria-label for checkout-link using productFamily as placeholder key and card-heading
const ctaLink = ctas?.querySelector('a');
if (ctaLink && !ctaLink.getAttribute('aria-label')) {
const { replaceKey } = await import('../../features/placeholders.js');
ctaLink.addEventListener('mas:resolved', async () => {
const productName = ctaLink.value[0]?.productArrangement?.productFamily;
if (productName) {
await replaceKey(productName, getConfig()).then((label) => ctaLink.setAttribute('aria-label', `${ctaLink.textContent} - ${label} - ${merchCard.querySelector('.card-heading')?.textContent}`));
if (ctas) {
const ctaLinks = ctas.querySelectorAll('a');
ctaLinks.forEach(async (ctaLink) => {
if (!ctaLink.getAttribute('aria-label')) {
if (window.location.pathname.includes('/products/catalog')) {
ctaLink.setAttribute('aria-label', `${ctaLink.textContent} - ${merchCard.querySelector('.card-heading')?.textContent}`);
} else {
const { replaceKey } = await import('../../features/placeholders.js');
ctaLink.addEventListener('mas:resolved', async () => {
const productName = ctaLink.value[0]?.productArrangement?.productFamily;
if (productName) {
await replaceKey(productName, getConfig()).then((label) => ctaLink.setAttribute('aria-label', `${ctaLink.textContent} - ${label} - ${merchCard.querySelector('.card-heading')?.textContent}`));
}
});
}
}
});
}
Expand Down

0 comments on commit 8aff28b

Please sign in to comment.