generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdelayed.js
More file actions
40 lines (31 loc) · 1.01 KB
/
delayed.js
File metadata and controls
40 lines (31 loc) · 1.01 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
34
35
36
37
38
39
40
// Delayed functionality – martech, social share (injected on every page)
import {
buildBlock, decorateBlock, loadBlock, loadScript,
} from './aem.js';
import { createTag } from './shared.js';
const SHARE_THIS_SRC = 'https://platform-api.sharethis.com/js/sharethis.js';
async function injectSocialShareBlock() {
const main = document.querySelector('main');
if (!main || main.querySelector('.social-share')) return;
const section = createTag('div', {
class: 'section',
'data-section-status': 'initialized',
});
section.style.display = null;
const wrapper = createTag('div');
const block = buildBlock('social-share', [[]]);
wrapper.append(block);
section.append(wrapper);
main.append(section);
decorateBlock(block);
await loadBlock(block);
}
async function loadShareThis() {
if (!document.querySelector('.sharethis-share-buttons')) return;
await loadScript(SHARE_THIS_SRC, { async: '' });
}
async function init() {
await injectSocialShareBlock();
await loadShareThis();
}
init();