-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MWPW-161779: SUSI Link scenario when open in new tab or window (#914)
* 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
1 parent
6b2c83e
commit 847d448
Showing
1 changed file
with
38 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
}); | ||
} |