-
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.
Merge pull request #424 from adobecom/MWPW-132031
MWPW-132031
- Loading branch information
Showing
13 changed files
with
35 additions
and
59 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,39 +1,24 @@ | ||
import { createTag } from './miloUtils.js'; | ||
|
||
const cardImageMappings = [ | ||
{ name: 'AMEX_V_MC_D_DU_JCB_PP', filename: 'amex_v_mc_d_du_jcb_pp.jpg' }, | ||
{ name: 'AMEX_V_MC_JCB_JPBANK', filename: 'amex_v_mc_jcb_jpbank.png' }, | ||
{ name: 'AMEX_V_MC_PP', filename: 'amex_v_mc_pp.jpg' }, | ||
{ name: 'AMEX_VISA_MC_D_DU_ELC_PP_BOLETO', filename: 'amex_visa_mc_d_du_elc_pp_boleto.jpg' }, | ||
{ name: 'AMEX_VISA_MC_D_DU_JCB_PAYPAL', filename: 'amex_visa_mc_d_du_jcb_paypal.jpg' }, | ||
{ name: 'AMEX_VISA_MC_D_PAYPAL', filename: 'amex_visa_mc_d_paypal.jpg' }, | ||
{ name: 'AMEX_VISA_MC_JCB_JPBANK_JPSTORE', filename: 'amex_visa_mc_jcb_jpbank_jpstore.png' }, | ||
{ name: 'V_MC_DD_PP', filename: 'v_mc_dd_pp.jpg' }, | ||
{ name: 'V_MC', filename: 'v_mc.jpg' }, | ||
]; | ||
export default async function replacePlaceholdersWithImages(locale, miloLibs) { | ||
const country = (locale?.split('-').pop()?.toLowerCase()) ?? 'us'; | ||
const path = `${miloLibs}/icons/accepted-credit-cards/${country}.png?format=webply&optimize=medium`; | ||
const pattern = /{{credit-cards}}/g; | ||
|
||
export default async function replacePlaceholdersWithImages(documentElement) { | ||
const paragraphs = documentElement.querySelectorAll('p'); | ||
await createTag.then((tag) => { | ||
paragraphs.forEach((p) => { | ||
cardImageMappings.forEach((mapping) => { | ||
const cardName = p.innerHTML.trim(); | ||
const matchedImage = cardName === mapping.name; | ||
if (matchedImage) { | ||
const imagePath = `/acrobat/img/icons/credit-cards-${mapping.filename}`; | ||
const imgAttributes = { | ||
src: imagePath, | ||
loading: 'lazy', | ||
'data-local': 'credit-cards', | ||
}; | ||
const imgElement = tag('img', imgAttributes); | ||
imgElement.onerror = async () => { | ||
window.lana?.log(`Error loading image for credit-card placeholder: ${cardName}`); | ||
imgElement.remove(); | ||
}; | ||
p.replaceWith(imgElement); | ||
} | ||
}); | ||
document.querySelectorAll('p').forEach((p) => { | ||
const matched = pattern.exec(p.innerHTML); | ||
if (matched) { | ||
const img = tag('img', { | ||
src: path, | ||
loading: 'lazy', | ||
class: 'credit-cards-icon', | ||
style: 'min-height: 33px;', | ||
'data-country': `${country}`, | ||
onerror: `window.lana?.log('Failed to load credit-card icon ${country}'); this.remove()`, | ||
}); | ||
p.replaceWith(img); | ||
} | ||
}); | ||
}); | ||
} |
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
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