generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 208
Expand file tree
/
Copy pathaside.js
More file actions
33 lines (28 loc) · 1.21 KB
/
aside.js
File metadata and controls
33 lines (28 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { loadBlock, decorateAutoBlock } from '../../../../utils/utils.js';
import { toFragment, lanaLog } from '../../utilities/utilities.js';
import { processTrackingLabels } from '../../../../martech/attributes.js';
export default async function decorateAside({ headerElem, fedsPromoWrapper, promoPath } = {}) {
const onError = () => {
fedsPromoWrapper?.remove();
headerElem?.classList.remove('has-promo');
lanaLog({
message: 'Gnav Promo fragment not replaced, potential CLS',
tags: 'aside',
severity: 'warning',
});
return '';
};
const fragLink = toFragment`<a href="${promoPath}">${promoPath}</a>`;
const fragTemplate = toFragment`<div>${fragLink}</div>`;
decorateAutoBlock(fragLink);
if (!fragLink.classList.contains('fragment')) return onError();
await loadBlock(fragLink).catch(() => onError());
const aside = fragTemplate.querySelector('.aside');
if (fragTemplate.contains(fragLink) || !aside) return onError();
aside.removeAttribute('data-block');
aside.setAttribute('daa-lh', 'Promo');
aside.querySelectorAll('a').forEach((link, index) => {
link.setAttribute('daa-ll', `${processTrackingLabels(link.textContent)}--${index + 1}`);
});
return aside;
}