Skip to content

Commit

Permalink
MWPW-161779: SUSI Link scenario when open in new tab or window (#914)
Browse files Browse the repository at this point in the history
* SUSI default using placeholders link for scenario when users use open in new (tab, window)

* Refactoring  SUSI Handler

---------

Co-authored-by: James Tsay <65299136+TsayAdobe@users.noreply.github.com>
  • Loading branch information
joaquinrivero and TsayAdobe authored Dec 9, 2024
1 parent 6b2c83e commit 847d448
Showing 1 changed file with 38 additions and 15 deletions.
53 changes: 38 additions & 15 deletions acrobat/scripts/susiAuthHandler.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
import susiAnalytics from './alloy/susi-auth-handler.js';

export default function handleImsSusi(susiElems) {
function handleButton(link, action) {
link.classList.add('susi-cta');
link.href = window.mph['susi-default-redirect'] || 'https://acrobat.adobe.com/link/home/';
link.addEventListener('click', (e) => {
e.preventDefault();
susiAnalytics(link.text, action, window.browser.isMobile ? 'mobile' : 'desktop');
if (action === 'sign-up') {
window.adobeIMS.signUp();
} else if (action === 'sign-in') {
window.adobeIMS.signIn();
}
});
}

export default async function handleImsSusi(susiElems) {
const { setLibs } = await import('./utils.js');
const miloLibs = setLibs('/libs');
const { getConfig } = await import(`${miloLibs}/utils/utils.js`);
const config = getConfig();

if (!Object.keys(window.mph || {}).length) {
const placeholdersPath = `${config.locale.contentRoot}/placeholders.json`;
try {
const response = await fetch(placeholdersPath);
if (response.ok) {
const placeholderData = await response.json();
placeholderData.data.forEach(({ key, value }) => {
window.mph[key] = value.replace(/\u00A0/g, ' ');
});
}
} catch (error) {
window.lana?.log(`Failed to load placeholders: ${error?.message}`);
}
}

susiElems.forEach((link) => {
if (link.href.includes('-sign-up')) {
link.addEventListener('click', (e) => {
e.preventDefault();
susiAnalytics(link.text, 'sign-up', window.browser.isMobile ? 'mobile' : 'desktop');
window.adobeIMS.signUp();
});
} else if (link.href.includes('-sign-in')) {
link.addEventListener('click', (e) => {
e.preventDefault();
susiAnalytics(link.text, 'sign-in', window.browser.isMobile ? 'mobile' : 'desktop');
window.adobeIMS.signIn();
});
const match = link.href.match(/-(sign-up|sign-in)/);
if (match) {
handleButton(link, match[1]);
}
link.style.pointerEvents = 'auto';
link.style.cursor = 'pointer';
});
}

0 comments on commit 847d448

Please sign in to comment.