-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (65 loc) · 1.99 KB
/
index.js
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* Zones extension (Yozons)
*/
import * as zones from "./lib/zones.js";
import * as config from "./lib/config.js";
import * as story from "./lib/story.js";
async function distributeZones(locker) {
// Using a section config to switch from this repo to experiences
if(locker.getConfig("zones") == "experiences") {
return Promise.resolve("zones-loaded");
} else {
let subscriber, dma;
// DSP limited to production domains
try {
subscriber = locker.user.isSubscriber();
dma = await locker.user.isInDMA();
} catch(e) {
subscriber = false;
dma = false
console.warn("DSP is not available");
}
// Setup
zones.setLocker(locker);
zones.setConfig("subscriber", subscriber);
zones.setConfig("dma", subscriber ? true : dma);
zones.setConfig("ads", locker.getYozonsLocker("core").areAdsAllowed());
// Config files
if(!locker.config) {
locker.config = {
homepage: "/static/hi/zones/homepage.json",
sectfront: "/static/hi/zones/section.json",
story: "/static/hi/zones/story.json"
}
}
// Add the communication bridge
window.mi = window.mi || {};
window.mi.zones = window.mi.zones || {};
window.mi.zones = Object.assign(window.mi.zones, zones.getPublicAPI());
// Give the performance team a promise
return new Promise((resolve, reject) => {
locker.executeWhenDOMReady(async () => {
// Config keys match pageType coming from Yozons
const match = locker.config[locker.pageType];
// Load config file
if(match) {
try {
await config.load(match);
} catch(e) {
reject(e);
}
} else {
reject("zones: not a matching page type");
}
// Temporary cleanup
if(locker.pageType == "story") {
story.cleanup();
}
// Render and resolve
zones.render();
resolve("zones-loaded")
});
});
}
}
export default distributeZones;