|
1 | 1 | (function(source, args) { |
2 | 2 | function GoogleTagServicesGpt(source) { |
| 3 | + var slots = new Map; |
| 4 | + var slotsById = new Map; |
| 5 | + var eventCallbacks = new Map; |
| 6 | + var addEventListener = function addEventListener(name, listener) { |
| 7 | + if (!eventCallbacks.has(name)) { |
| 8 | + eventCallbacks.set(name, new Set); |
| 9 | + } |
| 10 | + eventCallbacks.get(name).add(listener); |
| 11 | + return this; |
| 12 | + }; |
| 13 | + var removeEventListener = function removeEventListener(name, listener) { |
| 14 | + if (eventCallbacks.has(name)) { |
| 15 | + return eventCallbacks.get(name).delete(listener); |
| 16 | + } |
| 17 | + return false; |
| 18 | + }; |
| 19 | + var fireSlotEvent = function fireSlotEvent(name, slot) { |
| 20 | + return new Promise((function(resolve) { |
| 21 | + requestAnimationFrame((function() { |
| 22 | + var size = [ 0, 0 ]; |
| 23 | + var callbacksSet = eventCallbacks.get(name) || []; |
| 24 | + var callbackArray = Array.from(callbacksSet); |
| 25 | + for (var i = 0; i < callbackArray.length; i += 1) { |
| 26 | + callbackArray[i]({ |
| 27 | + isEmpty: true, |
| 28 | + size: size, |
| 29 | + slot: slot |
| 30 | + }); |
| 31 | + } |
| 32 | + resolve(); |
| 33 | + })); |
| 34 | + })); |
| 35 | + }; |
| 36 | + var displaySlot = function displaySlot(slot) { |
| 37 | + if (!slot) { |
| 38 | + return; |
| 39 | + } |
| 40 | + var id = slot.getSlotElementId(); |
| 41 | + if (!document.getElementById(id)) { |
| 42 | + return; |
| 43 | + } |
| 44 | + var parent = document.getElementById(id); |
| 45 | + if (parent) { |
| 46 | + parent.appendChild(document.createElement("div")); |
| 47 | + } |
| 48 | + fireSlotEvent("slotRenderEnded", slot); |
| 49 | + fireSlotEvent("slotRequested", slot); |
| 50 | + fireSlotEvent("slotResponseReceived", slot); |
| 51 | + fireSlotEvent("slotOnload", slot); |
| 52 | + fireSlotEvent("impressionViewable", slot); |
| 53 | + }; |
3 | 54 | var companionAdsService = { |
4 | | - addEventListener: noopThis, |
5 | | - removeEventListener: noopThis, |
| 55 | + addEventListener: addEventListener, |
| 56 | + removeEventListener: removeEventListener, |
6 | 57 | enableSyncLoading: noopFunc, |
7 | 58 | setRefreshUnfilledSlots: noopFunc, |
8 | 59 | getSlots: noopArray |
9 | 60 | }; |
10 | 61 | var contentService = { |
11 | | - addEventListener: noopThis, |
| 62 | + addEventListener: addEventListener, |
| 63 | + removeEventListener: removeEventListener, |
12 | 64 | setContent: noopFunc |
13 | 65 | }; |
14 | 66 | function PassbackSlot() {} |
|
22 | 74 | function SizeMappingBuilder() {} |
23 | 75 | SizeMappingBuilder.prototype.addSize = noopThis; |
24 | 76 | SizeMappingBuilder.prototype.build = noopNull; |
25 | | - function Slot() {} |
| 77 | + function Slot(adUnitPath, creatives, optDiv) { |
| 78 | + this.adUnitPath = adUnitPath; |
| 79 | + this.creatives = creatives; |
| 80 | + this.optDiv = optDiv; |
| 81 | + if (slotsById.has(optDiv)) { |
| 82 | + var _document$getElementB; |
| 83 | + (_document$getElementB = document.getElementById(optDiv)) === null || _document$getElementB === void 0 ? void 0 : _document$getElementB.remove(); |
| 84 | + return slotsById.get(optDiv); |
| 85 | + } |
| 86 | + slotsById.set(optDiv, this); |
| 87 | + } |
26 | 88 | Slot.prototype.addService = noopThis; |
27 | 89 | Slot.prototype.clearCategoryExclusions = noopThis; |
28 | 90 | Slot.prototype.clearTargeting = noopThis; |
29 | 91 | Slot.prototype.defineSizeMapping = noopThis; |
30 | 92 | Slot.prototype.get = noopNull; |
31 | | - Slot.prototype.getAdUnitPath = noopStr; |
| 93 | + Slot.prototype.getAdUnitPath = function() { |
| 94 | + return this.adUnitPath; |
| 95 | + }; |
32 | 96 | Slot.prototype.getAttributeKeys = noopArray; |
33 | 97 | Slot.prototype.getCategoryExclusions = noopArray; |
34 | | - Slot.prototype.getDomId = noopStr; |
35 | | - Slot.prototype.getSlotElementId = noopStr; |
| 98 | + Slot.prototype.getDomId = function() { |
| 99 | + return this.optDiv; |
| 100 | + }; |
| 101 | + Slot.prototype.getSlotElementId = function() { |
| 102 | + return this.optDiv; |
| 103 | + }; |
36 | 104 | Slot.prototype.getSlotId = noopThis; |
37 | 105 | Slot.prototype.getSizes = noopArray; |
38 | 106 | Slot.prototype.getTargeting = noopArray; |
|
43 | 111 | Slot.prototype.setCollapseEmptyDiv = noopThis; |
44 | 112 | Slot.prototype.setTargeting = noopThis; |
45 | 113 | var pubAdsService = { |
46 | | - addEventListener: noopThis, |
47 | | - removeEventListener: noopThis, |
| 114 | + addEventListener: addEventListener, |
| 115 | + removeEventListener: removeEventListener, |
48 | 116 | clear: noopFunc, |
49 | 117 | clearCategoryExclusions: noopThis, |
50 | 118 | clearTagForChildDirectedTreatment: noopThis, |
|
84 | 152 | setVideoContent: noopThis, |
85 | 153 | updateCorrelator: noopFunc |
86 | 154 | }; |
| 155 | + var getNewSlot = function getNewSlot(adUnitPath, creatives, optDiv) { |
| 156 | + return new Slot(adUnitPath, creatives, optDiv); |
| 157 | + }; |
87 | 158 | var _window = window, _window$googletag = _window.googletag, googletag = _window$googletag === void 0 ? {} : _window$googletag; |
88 | 159 | var _googletag$cmd = googletag.cmd, cmd = _googletag$cmd === void 0 ? [] : _googletag$cmd; |
89 | 160 | googletag.apiReady = true; |
|
100 | 171 | googletag.content = function() { |
101 | 172 | return contentService; |
102 | 173 | }; |
103 | | - googletag.defineOutOfPageSlot = function() { |
104 | | - return new Slot; |
105 | | - }; |
106 | | - googletag.defineSlot = function() { |
107 | | - return new Slot; |
| 174 | + googletag.defineOutOfPageSlot = getNewSlot; |
| 175 | + googletag.defineSlot = getNewSlot; |
| 176 | + googletag.destroySlots = function() { |
| 177 | + slots.clear(); |
| 178 | + slotsById.clear(); |
108 | 179 | }; |
109 | | - googletag.destroySlots = noopFunc; |
110 | 180 | googletag.disablePublisherConsole = noopFunc; |
111 | | - googletag.display = noopFunc; |
| 181 | + googletag.display = function(arg) { |
| 182 | + var id; |
| 183 | + if (arg !== null && arg !== void 0 && arg.getSlotElementId) { |
| 184 | + id = arg.getSlotElementId(); |
| 185 | + } else if (arg !== null && arg !== void 0 && arg.nodeType) { |
| 186 | + id = arg.id; |
| 187 | + } else { |
| 188 | + id = String(arg); |
| 189 | + } |
| 190 | + displaySlot(slotsById.get(id)); |
| 191 | + }; |
112 | 192 | googletag.enableServices = noopFunc; |
113 | 193 | googletag.getVersion = noopStr; |
114 | 194 | googletag.pubads = function() { |
|
0 commit comments