Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decorate Links #406

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions solutions/blocks/quote-carousel/quote-carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function createSlide(item, index) {
const paragraphs = Array.from(item.querySelectorAll('p'));
const quote = paragraphs.find((paragraph) => {
const strongOrEm = paragraph.querySelector('strong, em');
return !strongOrEm && paragraph.textContent.trim() !== '';
return !strongOrEm && paragraph.innerHTML.trim() !== '';
});

const author = item.querySelector('p > strong');
Expand All @@ -30,7 +30,7 @@ function createSlide(item, index) {
<span class="icon icon-dark-blue-quote"/>
</div>
<div class="quote-content">
<h4>${quote?.textContent}</h4>
<h4>${quote?.innerHTML}</h4>
<h5>${author?.textContent}</h5>
<p>${description?.textContent}</p>
</div>`,
Expand Down
16 changes: 9 additions & 7 deletions solutions/scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,21 @@ export async function decorateIcons(element) {
}
}));

const symbols = Object
.keys(ICONS_CACHE).filter((k) => !svgSprite.querySelector(`#icons-sprite-${k}`))
.map((k) => ICONS_CACHE[k])
.filter((v) => !v.styled)
.map((v) => v.html)
.join('\n');
const symbols = Object.values(ICONS_CACHE).filter((v) => !v.styled).map((v) => v.html).join('\n');
svgSprite.innerHTML += symbols;

icons.forEach((span) => {
const iconName = Array.from(span.classList).find((c) => c.startsWith('icon-')).substring(5);
const parent = span.firstElementChild?.tagName === 'A' ? span.firstElementChild : span;

// Set aria-label if the parent is an anchor tag
const spanParent = span.parentElement;
if (spanParent.tagName === 'A' && !spanParent.hasAttribute('aria-label')) {
spanParent.setAttribute('aria-label', iconName);
}

// Styled icons need to be inlined as-is, while unstyled ones can leverage the sprite
if (ICONS_CACHE[iconName].styled) {
if (ICONS_CACHE[iconName] && ICONS_CACHE[iconName].styled) {
parent.innerHTML = ICONS_CACHE[iconName].html;
} else {
parent.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg"><use href="#icons-sprite-${iconName}"/></svg>`;
Expand Down
48 changes: 45 additions & 3 deletions solutions/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ export const DEFAULT_COUNTRY = 'au';

export const METADATA_ANAYTICS_TAGS = 'analytics-tags';

let checkInterval = null;

const hreflangMap = {
'en-ro': 'https://www.bitdefender.ro',
de: 'https://www.bitdefender.de',
Expand Down Expand Up @@ -295,15 +297,53 @@ export default function decorateLinkedPictures(main) {
});
}

/**
* Decorete links with adobe_mc parameter.
* @param {Element} selector
*/
function appendAdobeMcLinks(selector) {
try {
// eslint-disable-next-line no-undef
const visitor = Visitor.getInstance('0E920C0F53DA9E9B0A490D45@AdobeOrg', {
trackingServer: 'sstats.bitdefender.com',
trackingServerSecure: 'sstats.bitdefender.com',
marketingCloudServer: 'sstats.bitdefender.com',
marketingCloudServerSecure: 'sstats.bitdefender.com',
});
const wrapperSelector = document.querySelector(selector);
const hrefSelector = '[href*=".bitdefender."]';

wrapperSelector.querySelectorAll(hrefSelector).forEach((link) => {
const destinationURLWithVisitorIDs = visitor.appendVisitorIDsTo(link.href);

link.href = destinationURLWithVisitorIDs.replace(/MCAID%3D.*%7CMCORGID/, 'MCAID%3D%7CMCORGID');
});
} catch (e) {
// eslint-disable-next-line no-console
console.error(e);
}
}

function checkAEPDataCollection() {
// Check if Adobe Experience Platform Data Collection is loaded
if (window.adobe && window.adobe.target && window.adobe.target.getOffer) {
// Your custom code here
appendAdobeMcLinks('main');
// Stop checking, as AEP Data Collection is now loaded
// eslint-disable-next-line no-use-before-define
clearInterval(checkInterval);
}
}

/**
* Decorates the main element.
* @param {Element} main The main element
*/
// eslint-disable-next-line import/prefer-default-export
export function decorateMain(main) {
export async function decorateMain(main) {
// hopefully forward compatible button decoration
decorateButtons(main);
decorateIcons(main);
await decorateIcons(main);
decorateTags(main);
decorateLinkedPictures(main);
decorateSections(main);
Expand Down Expand Up @@ -468,7 +508,7 @@ async function loadEager(doc) {
}
const main = doc.querySelector('main');
if (main) {
decorateMain(main);
await decorateMain(main);
buildCtaSections(main);
buildTwoColumnsSection(main);
detectModalButtons(main);
Expand Down Expand Up @@ -507,6 +547,8 @@ async function loadLazy(doc) {
link.setAttribute('href', `${value}${window.location.pathname.replace(/\/us\/en/, '')}`);
document.head.appendChild(link);
});

checkInterval = setInterval(checkAEPDataCollection, 100);
}

/**
Expand Down