From fbea31a26592086ccfc88039592aaa7e00684338 Mon Sep 17 00:00:00 2001 From: Narcis Radu Date: Thu, 16 May 2024 16:49:19 +0300 Subject: [PATCH] [MWPW-141785] Implement custom link actions --- libs/blocks/card/cardUtils.js | 19 +++++++++---------- libs/utils/utils.js | 9 +++++++++ 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/libs/blocks/card/cardUtils.js b/libs/blocks/card/cardUtils.js index 3ca7a6da71b..b9355939775 100644 --- a/libs/blocks/card/cardUtils.js +++ b/libs/blocks/card/cardUtils.js @@ -32,19 +32,18 @@ export const addFooter = (links, container, merch) => { const linksArr = Array.from(links); const linksLeng = linksArr.length; const hrTag = merch ? '
' : ''; - let footer = `
${hrTag}
`; - footer = linksArr.reduce( - (combined, link, index) => ( - `${combined}
${link.outerHTML}
`), - footer, - ); - footer += '
'; - - container.insertAdjacentHTML('beforeend', footer); - links.forEach((link) => { + const footer = createTag('div', { class: 'consonant-CardFooter' }, hrTag); + const row = createTag('div', { class: 'consonant-CardFooter-row', 'data-cells': '1' }); + linksArr.forEach((link, index) => { const { parentElement } = link; if (parentElement && document.body.contains(parentElement)) parentElement.remove(); + const holder = createTag('div', { class: `consonant-CardFooter-cell consonant-CardFooter-cell--${(linksLeng === 2 && index === 0) ? 'left' : 'right'}` }); + holder.append(link); + row.append(holder); }); + + footer.append(row); + container.insertAdjacentElement('beforeend', footer); }; export const addWrapper = (el, section, cardType) => { diff --git a/libs/utils/utils.js b/libs/utils/utils.js index 86dc6c3dc52..b6cbab15032 100644 --- a/libs/utils/utils.js +++ b/libs/utils/utils.js @@ -626,6 +626,15 @@ export function decorateLinks(el) { rdx.push(a); } } + // Custom action links + const loginEvent = '#_evt-login'; + if (a.href.includes(loginEvent)) { + a.href = a.href.replace(loginEvent, ''); + a.addEventListener('click', (e) => { + e.preventDefault(); + window.adobeIMS?.signIn(); + }); + } return rdx; }, []); }