-
Notifications
You must be signed in to change notification settings - Fork 0
/
nos.js
84 lines (67 loc) · 3.01 KB
/
nos.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
77
78
79
80
81
82
83
84
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
var options = {
root: document.querySelector('#scrollArea'),
rootMargin: '0px',
threshold: 0.5
};
var ObserverCallback = function(entries, observer) {
for (var i = 0; i < entries.length; i++) {
if (entries[i].intersectionRatio >= 0.50) {
if (!adCalled)
doConsent();
}
}
};
var polyfillCallback = function() {
var observer = new IntersectionObserver(ObserverCallback, options);
var target = document.querySelector('#sterad');
observer.observe(target);
};
var adCalled = false;
function doConsent() {
googletag.cmd.push(function() {
googletag.pubads().refresh();
});
adCalled = true;
}
var polyfillScript = document.createElement('script');
polyfillScript.type = 'text/javascript';
polyfillScript.crossorigin = 'anonymous';
polyfillScript.src = 'https://polyfill.io/v3/polyfill.min.js?callback=polyfillCallback&flags=gated&features=default%2CIntersectionObserver';
polyfillScript.async = true;
var head = document.getElementsByTagName('head')[0];
head.insertBefore(polyfillScript, head.firstChild);
(function() {
var adslot = '/9233/Teletekst/Pagina100_199(Nieuws)';
var adsizes = [[468,60],[320,50],[728,90],[300,600],[120,600],[160,600]] ;
var adid = 'sterad';
var bottomSlot = null
function insertSterHeader() {
var addiv = document.getElementById(adid);
addiv.insertAdjacentHTML('beforebegin', '<div class="ster-header"><style>.ster-header { display: none; text-align: center }</style>Advertentie door <a target = "_blank" href="https://www.ster.nl">Ster.nl</a></div>');
}
prepareGoogle();
function prepareGoogle() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://www.googletagservices.com/tag/js/gpt.js';
script.async = true;
var head = document.getElementsByTagName('head')[0];
head.insertBefore(script, head.firstChild);
googletag.cmd.push(function() {
bottomSlot = googletag.defineSlot(adslot, adsizes, adid).addService(googletag.pubads());
var mapping = googletag.sizeMapping().addSize([0,0],[[320,50]]).addSize([600,0],[[468,60]]).addSize([800,0],[[728,90]]).addSize([1200,0],[[120,600],[160,600],[300,600]]).build();
bottomSlot.defineSizeMapping(mapping);
bottomSlot.setCollapseEmptyDiv(true);
googletag.pubads().disableInitialLoad();
googletag.pubads().addEventListener('slotRenderEnded', function(event) {
if (!event.isEmpty && event.slot == bottomSlot) {
insertSterHeader();
}
});
googletag.enableServices();
googletag.display(adid); try { window.addEventListener("hashchange", updateSterAd, false); function updateSterAd() { googletag.pubads().refresh([bottomSlot]); } }catch (err) { } //doesn't actually display until refresh() is called
});
}
}());