1/** 2 * PubX ad-collapse: removes dead space when GPT returns no creative or when 3 * an ad blocker / network failure prevents GPT from loading at all. 4 * 5 * Two signals drive this: 6 * 1. `slotRenderEnded` with `event.isEmpty = true` â handled in the GPT 7 * config in functions.php; adds `.pubx-gpt-slot--empty` on the slot div. 8 * 2. GPT never runs (blocker, DNS block, offline) â covered here via: 9 * a. A hard timeout that marks any unfilled slot as empty, and 10 * b. A `pubx-ad-blocked` flag on <html> when googletag never becomes 11 * ready, so stylesheet rules can hide every ad shell at once. 12 * 13 * CSS in style.css does the actual hiding; this file only toggles classes. 14 */ 15(function () { 16 'use strict'; 17 18 var SLOT_SELECTOR = '[id^="div-gpt-ad-"]'; 19 var SLOT_CLASS = 'pubx-gpt-slot'; 20 var EMPTY_CLASS = 'pubx-gpt-slot--empty'; 21 var BLOCKED_CLASS = 'pubx-ad-blocked'; 22 /* How long to wait for GPT to render a slot before declaring it dead. Chosen 23 * to be long enough to ride out slow networks but short enough that empty 24 * real estate doesn't sit on the page. */ 25 var SLOT_TIMEOUT_MS = 4500; 26 /* How long to wait for `googletag.apiReady` before declaring GPT blocked. */ 27 var GPT_TIMEOUT_MS = 4000; 28 29 function markEmpty(slot) { 30 if (!slot || slot.classList.contains(EMPTY_CLASS)) { 31 return; 32 } 33 slot.classList.add(EMPTY_CLASS); 34 } 35 36 /** A filled GPT slot always has an iframe descendant (including fluid creatives). */ 37 function isFilled(slot) { 38 return !!(slot && slot.querySelector('iframe')); 39 } 40 41 /** Ensures every GPT slot div carries `.pubx-gpt-slot` so CSS can target uniformly. */ 42 function tagSlots() { 43 var slots = document.querySelectorAll(SLOT_SELECTOR); 44 for (var i = 0; i < slots.length; i++) { 45 slots[i].classList.add(SLOT_CLASS); 46 } 47 return slots; 48 } 49 50 /** Schedules a fallback check per slot in case `slotRenderEnded` never fires. */ 51 function watchSlots(slots) { 52 for (var i = 0; i < slots.length; i++) { 53 (function (slot) { 54 window.setTimeout(function () { 55 if (!isFilled(slot)) { 56 markEmpty(slot); 57 } 58 }, SLOT_TIMEOUT_MS); 59 })(slots[i]); 60 } 61 } 62 63 /** 64 * Flags ad-blocker / network failure if googletag never initialises. We 65 * avoid bait-div heuristics (false positives from privacy extensions that 66 * clean up the DOM) and rely on the one thing that actually matters: 67 * whether GPT's API is reachable. 68 */ 69 function watchGpt() { 70 window.setTimeout(function () { 71 var gt = window.googletag; 72 if (!gt || !gt.apiReady) { 73 document.documentElement.classList.add(BLOCKED_CLASS); 74 } 75 }, GPT_TIMEOUT_MS); 76 } 77 78 function init() { 79 var slots = tagSlots(); 80 watchSlots(slots); 81 watchGpt(); 82 } 83 84 if (document.readyState === 'loading') { 85 document.addEventListener('DOMContentLoaded', init); 86 } else { 87 init(); 88 } 89})();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.