1'use strict'; 2 3/****************************************************************************** 4Copyright (c) Microsoft Corporation. 5 6Permission to use, copy, modify, and/or distribute this software for any 7purpose with or without fee is hereby granted. 8 9THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH 10REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 11AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 12INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 13LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR 14OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 15PERFORMANCE OF THIS SOFTWARE. 16***************************************************************************** */ 17 18function __awaiter(thisArg, _arguments, P, generator) { 19 function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } 20 return new (P || (P = Promise))(function (resolve, reject) { 21 function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } 22 function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } 23 function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } 24 step((generator = generator.apply(thisArg, _arguments || [])).next()); 25 }); 26} 27 28function __generator(thisArg, body) { 29 var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype); 30 return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; 31 function verb(n) { return function (v) { return step([n, v]); }; } 32 function step(op) { 33 if (f) throw new TypeError("Generator is already executing."); 34 while (g && (g = 0, op[0] && (_ = 0)), _) try { 35 if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; 36 if (y = 0, t) op = [op[0] & 2, t.value]; 37 switch (op[0]) { 38 case 0: case 1: t = op; break; 39 case 4: _.label++; return { value: op[1], done: false }; 40 case 5: _.label++; y = op[1]; op = [0]; continue; 41 case 7: op = _.ops.pop(); _.trys.pop(); continue; 42 default: 43 if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } 44 if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } 45 if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } 46 if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } 47 if (t[2]) _.ops.pop(); 48 _.trys.pop(); continue; 49 } 50 op = body.call(thisArg, _); 51 } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } 52 if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; 53 } 54} 55 56typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) { 57 var e = new Error(message); 58 return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e; 59}; 60 61var IOLScriptLoaderModule = /** @class */ (function () { 62 function IOLScriptLoaderModule() { 63 this.promises = []; 64 } 65 IOLScriptLoaderModule.prototype.addScript = function (url) { 66 if (!this.isScriptLoaded(url)) { 67 var promise = new Promise(function (resolve, reject) { 68 var script = document.createElement("script"); 69 script.src = url; 70 script.addEventListener("load", function () { return resolve(script); }, false); 71 script.addEventListener("error", function () { return reject(script); }, false); 72 document.body.appendChild(script); 73 }); 74 this.promises.push(promise); 75 } 76 }; 77 IOLScriptLoaderModule.prototype.isScriptLoaded = function (url) { 78 return document.querySelector("script[src=\"".concat(url, "\"]")) !== null; 79 }; 80 IOLScriptLoaderModule.prototype.addStyle = function (url) { 81 if (!this.isStyleLoaded(url)) { 82 var promise = new Promise(function (resolve, reject) { 83 var link = document.createElement("link"); 84 link.setAttribute("rel", "stylesheet"); 85 link.setAttribute("type", "text/css"); 86 link.setAttribute("href", url); 87 link.addEventListener("load", function () { return resolve(link); }, false); 88 link.addEventListener("error", function () { return reject(link); }, false); 89 document.body.appendChild(link); 90 }); 91 this.promises.push(promise); 92 } 93 }; 94 IOLScriptLoaderModule.prototype.isStyleLoaded = function (url) { 95 return document.querySelector("link[href=\"".concat(url, "\"]")) !== null; 96 }; 97 IOLScriptLoaderModule.prototype.onLoaded = function (onLoaded, onError) { 98 Promise.all(this.promises).then(function () { return onLoaded(); }, function () { return onError(); }); 99 }; 100 return IOLScriptLoaderModule; 101}()); 102 103var IOLComercialSlotModel = /** @class */ (function () { 104 function IOLComercialSlotModel(name, sizes, viewport, formatName, targets, isRefreshable, extraCSS) { 105 this.name = name; 106 this.sizes = sizes; 107 this.viewports = viewport; 108 this.formatName = formatName; 109 this.key_values = targets; 110 this.isRefreshable = isRefreshable; 111 this.extraCSS = extraCSS; 112 } 113 return IOLComercialSlotModel; 114}()); 115 116//INTER [1, 1] 117//BILLBOARDXL [ "fluid", [2,1], [970,250], [989,250]] 118//BILLBOARD [[970,250], [989,250]] 119//LEADERBOARD [[728,90], [320,50]] 120//MPU [300,250] 121//MPUHALF [[300,250], [300,600]] 122//MPU2 [300,250] 123//INCONTENT [3, 3] 124//BRANDED ["fluid"] 125//POPIN [340, 100] 126//ANCHOR[320, 50] 127var IOLComercialFormatCreator = /** @class */ (function () { 128 function IOLComercialFormatCreator() { 129 } 130 IOLComercialFormatCreator.createSlotModel = function (slotID, formatName, position) { 131 return IOLComercialFormatCreator.FORMAT_CREATOR[formatName.toUpperCase()](slotID, position); 132 }; 133 IOLComercialFormatCreator.FORMAT_CREATOR = { 134 INTER: function (slotID) { 135 return new IOLComercialSlotModel(slotID, [[1, 1]], undefined, "INTER", { pos: "inter" }, false, ""); 136 }, 137 BILLBOARD_XL: function (slotID) { 138 return new IOLComercialSlotModel(slotID, [[970, 250], [980, 250], [320, 100], "fluid", [2, 1], [4, 4], [5, 5
138]], [ 139 { 140 viewport: [980, 600], 141 sizes: [[970, 250], [980, 250], "fluid", [2, 1], [4, 4], [5, 5]] 142 }, 143 { 144 viewport: [0, 0], 145 sizes: [[320, 100], "fluid", [2, 1], [4, 4], [5, 5]] 146 } 147 ], "BILLBOARDXL", { 148 pos: "billboardxl" 149 }, false, "iol-comercial-placement-label"); 150 }, 151 POPIN: function (slotID) { 152 return new IOLComercialSlotModel(slotID, [[340, 100]], undefined, "POPIN", { 153 pos: "popin" 154 }, true, ""); 155 }, 156 INCONTENT: function (slotID) { 157 return new IOLComercialSlotModel(slotID, [[3, 3]], undefined, "INCONTENT", { 158 pos: "incontent" 159 }, true, ""); 160 }, 161 MPU_HALF: function (slotID) { 162 return new IOLComercialSlotModel(slotID, [[300, 250], [300, 600]], undefined, "MPU_HALF", { 163 pos: "mpuhalf" 164 }, true, "iol-comercial-placement-label"); 165 }, 166 MPU: function (slotID) { 167 return new IOLComercialSlotModel(slotID, [[300, 250]], undefined, "MPU", { 168 pos: "mpu" 169 }, true, "iol-comercial-placement-label"); 170 }, 171 MPU2: function (slotID) { 172 return new IOLComercialSlotModel(slotID, [[300, 250]], undefined, "MPU2", { 173 pos: "mpu2" 174 }, true, "iol-comercial-placement-label"); 175 }, 176 MPUHALF_GAL: function (slotID) { 177 return new IOLComercialSlotModel(slotID, [[300, 250], [300, 600]], undefined, "MPUHALF_GAL", { 178 pos: "mpuhalf_gal" 179 }, true, "iol-comercial-placement-label"); 180 }, 181 MPUGAL: function (slotID) { 182 return new IOLComercialSlotModel(slotID, [[300, 250]], undefined, "MPUGAL", { 183 pos: "mpugal" 184 }, true, "iol-comercial-placement-label"); 185 }, 186 ANCHOR: function (slotID) { 187 return new IOLComercialSlotModel(slotID, [[320, 50]], undefined, "ANCHOR", { 188 pos: "anchor" 189 }, true, "iol-comercial-placement-label"); 190 }, 191 BRANDED: function (slotID) { 192 return new IOLComercialSlotModel(slotID, ["fluid"], undefined, "BRANDED_CONTENT", { pos: "branded" }, true, "iol-comercial-placement-label"); 193 }, 194 IOL_BRANDED: function (slotID) { 195 return new IOLComercialSlotModel(slotID, ["fluid"], undefined, "IOL_BRANDED_CONTENT", { 196 pos: "iol_branded" 197 }, true, "iol-comercial-placement-label"); 198 }, 199 LEADERBOARD: function (slotID) { 200 return new IOLComercialSlotModel(slotID, [ 201 [728, 90], 202 [320, 50], 203 [970, 250], 204 [980, 250] 205 ], [ 206 { 207 viewport: [728, 600], 208 sizes: [[728, 90]] 209 }, 210 { 211 viewport: [320, 400], 212 sizes: [[320, 50], [320, 100]] 213 }, 214 { 215 viewport: [970, 600], 216 sizes: [[970, 250], [728, 90]] 217 }, 218 { 219 viewport: [980, 600], 220 sizes: [[980, 250], [970, 250], [728, 90]] 221 } 222 ], "LDB", { 223 pos: "ldb" 224 }, true, "iol-comercial-placement-label"); 225 }, 226 LEADERBOARD2: function (slotID) { 227 return new IOLComercialSlotModel(slotID, [ 228 [728, 90], 229 [320, 50] 230 ], [ 231 { 232 viewport: [728, 600], 233 sizes: [[728, 90]] 234 }, 235 { 236 viewport: [320, 400], 237 sizes: [[320, 50]] 238 } 239 ], "LDB2", { 240 pos: "ldb2" 241 }, true, "iol-comercial-placement-label"); 242 }, 243 BILLBOARD_LEADERBOARD: function (slotID) { 244 return new IOLComercialSlotModel(slotID, [ 245 [970, 250], 246 [980, 250], 247 [728, 90], 248 [320, 50] 249 ], [ 250 { 251 viewport: [980, 600], 252 sizes: [ 253 [970, 250], 254 [980, 250], 255 [728, 90] 256 ] 257 }, 258 { 259 viewport: [728, 600], 260 sizes: [[728, 90]] 261 }, 262 { 263 viewport: [320, 400], 264 sizes: [[320, 50]] 265 } 266 ], "LDB", { 267 pos: "ldb" 268 }, true, "iol-comercial-placement-label"); 269 }, 270 "SPONSOR": function (slotID, position) { 271 return new IOLComercialSlotModel(slotID, ["fluid"], undefined, "SPONSOR".concat(position ? position : '1'), { 272 pos: "sponsor".concat(position ? position : '1') 273 }, true, "iol-comercial-placement-label"); 274 }, 275 AUDIO: function (slotID) { 276 return new IOLComercialSlotModel(slotID, [[1, 1]], undefined, "AUDIO", { pos: "audio" }, true, "iol-comercial-placement-label"); 277 }, 278 OUTSTREAM: function (slotID) { 279 return new IOLComercialSlotModel(slotID, [[640, 480]], undefined, "OUTSTREAM", { 280 pos: "outstream" 281 }, true, "iol-comercial-placement-label"); 282 }, 283 AUTOPROMO: function (slotID) { 284 return new IOLComercialSlotModel(slotID, [[6, 6]], undefined, "AUTOPROMO", { pos: "autopromo" }, false, ""); 285 }, 286 L_BAND: function (slotID) { 287 return new IOLComercialSlotModel(slotID, [[7, 7]], undefined, "L_BAND", { pos: "LBAND" }, false, ""); 288 } 289 }; 290 return IOLComercialFormatCreator; 291}()); 292 293// declare var window: Window & { iol?: { onUserLoggedIn?: () => void } & {} }; 294var IOLComercialPlatform = /** @class */ (function () { 295 function IOLComercialPlatform(AMUnit) { 296 this.hasPreloaded = false;
297 this.AMUnit = AMUnit; 298 this.AMGoogleTag = {}; 299 this.slotQueue = []; 300 this.slotsIndex = {}; 301 this.refreshableSlotsIndex = []; 302 this.noPubProducts = [7, 8, 9, 12, 13, 14]; 303 this.noPubPremiumProducts = [13, 14]; 304 this.correlator = Date.now(); 305 this.location = document.querySelector("meta[property='og:site_name']") 306 ? document 307 .querySelector("meta[property='og:site_name']") 308 .getAttribute("content") 309 : ""; 310 this.tags = this.getArticleTags(); 311 this.section = this.getSectionTags(); 312 this.ctags = this.getControlTags(); 313 this.pubTag = this.getPubTag(); 314 this.projTag = this.getProjTag(); 315 } 316 IOLComercialPlatform.prototype.loadDependencies = function (action) { 317 var _this = this; 318 var scriptLoader = new IOLScriptLoaderModule(); 319 scriptLoader.addScript("https://www.googletagservices.com/tag/js/gpt.js"); 320 scriptLoader.onLoaded(function () { return __awaiter(_this, void 0, void 0, function () { 321 var _a; 322 return __generator(this, function (_b) { 323 switch (_b.label) { 324 case 0: 325 this.AMGoogleTag = window["googletag"] || {}; 326 console.info("IOLCOMERCIAL: Dependencies successufly loaded"); 327 action(); 328 _b.label = 1; 329 case 1: 330 _b.trys.push([1, 3, , 4]); 331 _a = this; 332 return [4 /*yield*/, this.getIOLAnalyticsCookieValue()]; 333 case 2: 334 _a.ppID = _b.sent(); 335 return [3 /*break*/, 4]; 336 case 3: 337 _b.sent(); 338 return [3 /*break*/, 4]; 339 case 4: return [2 /*return*/]; 340 } 341 }); 342 }); }, function () { 343 console.error("IOLCOMERCIAL: Cannot load dependencies"); 344 }); 345 }; 346 IOLComercialPlatform.prototype.getIOLAnalyticsCookieValue = function () { 347 var cookie = document.cookie.split(";"); 348 var iola = cookie.find(function (el) { 349 if (el.includes("_iola")) { 350 return true; 351 } 352 }); 353 if (iola) { 354 var ids = iola.split("_iola="); 355 var id = ids[1]; 356 return id || undefined; 357 } 358 }; 359 IOLComercialPlatform.prototype.getArticleTags = function () { 360 var _this = this; 361 var _a, _b, _c, _d; 362 var ioltags = document.querySelector("meta[property='iol:tags']"); 363 var iolprogramme = document.querySelector("meta[property='iol:programme_name']"); 364 var metatags = (_b = (_a = ioltags === null || ioltags === void 0 ? void 0 : ioltags.getAttribute("content")) === null || _a === void 0 ? void 0 : _a.split(", ")) !== null && _b !== void 0 ? _b : []; 365 var programmetags = (_d = (_c = iolprogramme === null || iolprogramme === void 0 ? void 0 : iolprogramme.getAttribute("content")) === null || _c === void 0 ? void 0 : _c.split(", ")) !== null && _d !== void 0 ? _d : []; 366 var tags = metatags.concat(programmetags).filter(function (n) { return n; }); 367 var originURL = window.location.origin; 368 var homepage = originURL + '/'; 369 if (window.location.href === homepage) { 370 tags.push("homepage"); 371 console.log("tags: ", tags); 372 } 373 var tagList = []; 374 if (tags.length > 0) { 375 tagList = Array.from(new Set(tags.map(function (element) { return _this.tagConverter(element); }))); 376 } 377 // Add "homepage" if we are on the homepage 378 return tagList; 379 }; 380 IOLComercialPlatform.prototype.tagConverter = function (s) { 381 var lower = s.toLowerCase(); 382 var normal = lower.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); 383 return normal.replace(/ /g, ""); 384 }; 385 IOLComercialPlatform.prototype.getPubTag = function () { 386 var metatag = document.querySelector("meta[property='iol:pub_tag']"); 387 var pubtag = (metatag === null || metatag === void 0 ? void 0 : metatag.getAttribute("content")) || ""; 388 if (pubtag) { 389 var sectionList = this.tagConverter(pubtag); 390 return sectionList; 391 } 392 }; 393 IOLComercialPlatform.prototype.getSectionTags = function () { 394 var metapsection = document.querySelector("meta[property='iol:parent_section']"); 395 var metasection = document.querySelector("meta[property='iol:section']"); 396 var psection = (metapsection === null || metapsection === void 0 ? void 0 : metapsection.getAttribute("content")) || ""; 397 var section = (metasection === null || metasection === void 0 ? void 0 : metasection.getAttribute("content")) || ""; 398 var sectionList = [ 399 this.tagConverter(psection), 400 this.tagConverter(section) 401 ]; 402 return sectionList; 403 }; 404 IOLComercialPlatform.prototype.getControlTags = function () { 405 var _this = this; 406 var metactag = document.querySelector("meta[property='iol:ctags']"); 407 var ctags = (metactag === null || metactag === void 0 ? void 0 : metactag.getAttribute("content")) || ""; 408 var ctagList = []; 409 if (ctags !== "") { 410 var arr = ctags.split(", "); 411 ctagList = arr.map(function (element) { 412 return _this.tagConverter(element); 413 }); 414 } 415 return ctagList; 416 }; 417 IOLComercialPlatform.prototype.getProjTag = function () { 418 var _a; 419 var projTag = ((_a = document.querySelector("meta[property='iol:project']")) === null || _a === void 0 ? void 0 : _a.getAttribute("content")) || ""; 420 return projTag ? this.tagConverter(projTag) : ""; 421 }; 422 // nonioID(): Promise<string> { 423 // const value = this.getIOLAnalyticsCookieValue(); 424 // if (value) { 425 // // console.log("return with value: ", value); 426 // return Promise.resolve(value); 427 // } 428 // // return new Promise((resolve, reject) => { 429 // // window.iol = window.iol || {}; 430 // // window.iol.onLoaded = function () { 431 // // console.log("The bar is fully loaded and showing on the screen!"); 432 // // }; 433 // // window.iol.onUserLoggedIn = () => { 434 // // console.log("user login"); 435 // // const value = this.getIOLAnalyticsCookieValue(); 436 // // if (value) resolve(value); 437 // // else reject(); 438 // // }; 439 // // }); 440 // } 441 IOLComercialPlatform.prototype.isPlatformLoadedCorrectly = function () { 442 return !(Object.keys(this.AMGoogleTag).length === 0 && 443 this.AMGoogleTag.constructor === Object); 444 }; 445 IOLComercialPlatform.prototype.preloadMainPlacements = function () { 446 var _this = this; 447 if (!this.isPlatformLoadedCorrectly()) { 448 console.error("IOLCOMERCIAL: No googletag available"); 449 return; 450 } 451 this.loadPlacements(false); 452 this.AMGoogleTag.cmd.push(function () { 453 var _a, _b, _c, _d; 454 _this.AMGoogleTag.pubads().enableSingleRequest(); 455 _this.AMGoogleTag.pubads().setSafeFrameConfig({ 456 allowOverlayExpansion: true, 457 allowPushExpansion: true, 458 sandbox: true, 459 }); 460 _this.AMGoogleTag.pubads().enableLazyLoad({ 461 // Fetch slots within 2 viewports. 462 fetchMarginPercent: 200, 463 // Render slots within 1 viewports. 464 renderMarginPercent: 100, 465 // Double the above values on mobile, where viewports are smaller 466 // and users tend to scroll faster. 467 mobileScaling: 1.5, 468 }); 469 _this.AMGoogleTag.pubads().collapseEmptyDivs(true); 470 _this.AMGoogleTag.pubads().setPublisherProvidedId(_this.ppID); 471 var isTVIPlayer = _this.location === "TVI Player"; 472 if (((_a = _this.tags) === null || _a === void 0 ? void 0 : _a.length) > 0) { 473 console.log('tags', _this.tags); 474 _this.AMGoogleTag.pubads().setTargeting("category", _this.tags); 475 } 476 else if (isTVIPlayer && ((_b = _this.tags) === null || _b === void 0 ? void 0 : _b[0]) !== "tviplayer") { 477 _this.AMGoogleTag.pubads().setTargeting("programa", _this.tags[0]); 478 } 479 // Set targeting based on live pubTag 480 if (_this.pubTag) { 481 _this.AMGoogleTag.pubads().setTargeting("lives", _this.pubTag); 482 } 483 // Set universal targeting if ctags exist 484 if (((_c = _this.ctags) === null || _c === void 0 ? void 0 : _c.length) > 0) { 485 _this.AMGoogleTag.pubads().setTargeting("universal", _this.ctags); 486 } 487 // Set targeting based on section 488 if (((_d = _this.section) === null || _d === void 0 ? void 0 : _d.length) > 0) { 489 var _e = _this.section, parentSection = _e[0], section = _e[1]; 490 if (parentSection) { 491 _this.AMGoogleTag.pubads().setTargeting("parentsection", parentSection); 492 } 493 if (section) { 494 _this.AMGoogleTag.pubads().setTargeting("section", section); 495 } 496 } 497 if (_this.projTag) { 498 _this.AMGoogleTag.pubads().setTargeting("project", _this.projTag); 499 } 500 _this.AMGoogleTag.pubads().disableInitialLoad(); 501 _this.AMGoogleTag.enableServices(); 502 console.info("IOLCOMERCIAL: Preloaded ".concat(Object.keys(_this.slotsIndex).length)); 503 _this.hasPreloaded = true; 504 }); 505 }; 506 IOLComercialPlatform.prototype.loadNewPlacements = function () { 507 if (this.hasPreloaded) { 508 var loaded = Object.keys(this.slotsIndex).length; 509 this.loadPlacements(true); 510 console.info("IOLCOMERCIAL: ".concat(Object.keys(this.slotsIndex).length - loaded, " were loaded")); 511 } 512 else { 513 console.info("IOLCOMERCIAL: waiting for preloading."); 514 } 515 }; 516 IOLComercialPlatform.prototype.loadAllPlacementsIntoPage = function () { 517 var _this = this; 518 var adSlots = document.querySelectorAll('.iol-comercial-placement-loaded');
519 adSlots.forEach(function (slot) { 520 if (_this.isAboveFold(slot, 200)) { 521 _this.AMGoogleTag.cmd.push(function () { 522 _this.refresh(slot.id); 523 slot.classList.add("iol-comercial-placement-displayed"); 524 }); 525 } 526 else { 527 _this.lazyLoadAdSlot(slot); 528 } 529 }); 530 }; 531 IOLComercialPlatform.prototype.refresh = function (slotName) { 532 var _this = this; 533 if (!this.isPlatformLoadedCorrectly()) { 534 console.error("IOLCOMERCIAL: No googletag available"); 535 return; 536 } 537 var refreshSlots = this.refreshableSlotsIndex; 538 if (slotName) { 539 var slot = this.slotsIndex[slotName]; 540 refreshSlots = slot ? [slot["AMslot"]] : undefined; 541 } 542 if (refreshSlots) { 543 this.AMGoogleTag.cmd.push(function () { 544 _this.AMGoogleTag.pubads().refresh(refreshSlots, { 545 changeCorrelator: false 546 }); 547 }); 548 console.info("IOLCOMERCIAL: Refreshed with sucess (".concat(slotName ? slotName : "all", ")")); 549 } 550 else { 551 console.error("\"IOLCOMERCIAL: Couldn't refresh (".concat(slotName, " doesn't exists)")); 552 } 553 }; 554 IOLComercialPlatform.prototype.refreshDisplayedSlots = function () { 555 var _this = this; 556 var adSlotsDisplayed = document.querySelectorAll('.iol-comercial-placement-displayed'); 557 var refreshSlots = []; 558 adSlotsDisplayed.forEach(function (slot) { 559 if (_this.slotsIndex[slot.id] && _this.slotsIndex[slot.id].isRefreshable) { 560 refreshSlots.push(_this.slotsIndex[slot.id]["AMslot"]); 561 } 562 }); 563 this.AMGoogleTag.cmd.push(function () { 564 _this.AMGoogleTag.pubads().refresh(refreshSlots, { 565 changeCorrelator: false 566 }); 567 }); 568 }; 569 IOLComercialPlatform.prototype.createNewPlacement = function (divID) { 570 var element = document.getElementById(divID); 571 var slotId = element.id; 572 var slotFormat = element["dataset"]["iolComercialFormat"]; 573 var slotPositionStr = element["dataset"]["iolComercialFormatPosition"]; 574 var slotPosition; 575 try { 576 slotPosition = slotPositionStr ? parseInt(slotPositionStr) : undefined; 577 } 578 catch (_a) { 579 slotPosition = undefined; 580 } 581 if (this.checkRestrictions(element)) { 582 var slot = IOLComercialFormatCreator.createSlotModel(slotId, slotFormat, slotPosition); 583 this.addNewPlacement(slot); 584 } 585 else { 586 element.remove(); 587 } 588 }; 589 IOLComercialPlatform.prototype.createSlot = function (slot) { 590 var _this = this; 591 this.AMGoogleTag.cmd.push(function () { 592 var AMslot = undefined; 593 //begin of anchor 594 if (slot.formatName == "ANCHOR") { 595 AMslot = _this.AMGoogleTag.defineOutOfPageSlot("".concat(_this.AMUnit, "/").concat(slot.formatName), _this.AMGoogleTag.enums.OutOfPageFormat.BOTTOM_ANCHOR); 596 } 597 else { 598 AMslot = _this.AMGoogleTag.defineSlot("".concat(_this.AMUnit, "/").concat(slot.formatName), slot.sizes, slot.name); 599 } 600 //Defining Viewports 601 if (slot.viewports) { 602 var mapping_1 = _this.AMGoogleTag.sizeMapping(); 603 slot.viewports.forEach(function (vp) { 604 mapping_1.addSize(vp["viewport"], vp["sizes"]); 605 }); 606 AMslot = AMslot.defineSizeMapping(mapping_1.build()); 607 } 608 AMslot.addService(_this.AMGoogleTag.pubads()).setTargeting("sizes", slot.sizes); 609 //Define Targeting 610 if (slot.key_values) { 611 for (var _i = 0, _a = Object.entries(slot.key_values); _i < _a.length; _i++) { 612 var _b = _a[_i], key = _b[0], value = _b[1]; 613 AMslot = AMslot.setTargeting(key, value); 614 } 615 } 616 slot["AMslot"] = AMslot; 617 _this.slotsIndex[slot.name] = slot; 618 //this.AMGoogleTag.display(slot.name); 619 if (slot.isRefreshable) { 620 _this.refreshableSlotsIndex.push(AMslot); 621 } 622 }); 623 }; 624 IOLComercialPlatform.prototype.loadPlacements = function (shouldDisplay) { 625 var _this = this; 626 while (this.slotQueue.length > 0) 627 this.createSlot(this.slotQueue.pop()); 628 var placement = document.querySelectorAll(".iol-comercial-placement"); 629 placement.forEach(function (element) {
630 var slotId = element.id; 631 var slotFormat = element["dataset"]["iolComercialFormat"]; 632 var slotPositionStr = element["dataset"]["iolComercialFormatPosition"]; 633 var slotPosition; 634 try { 635 slotPosition = slotPositionStr ? parseInt(slotPositionStr) : undefined; 636 } 637 catch (_a) { 638 slotPosition = undefined; 639 } 640 if (_this.checkRestrictions(element)) { 641 var slot = IOLComercialFormatCreator.createSlotModel(slotId, slotFormat, slotPosition); 642 _this.addNewPlacement(slot); 643 element.classList.add("iol-comercial-placement-loaded"); 644 element.classList.remove("iol-comercial-placement"); 645 if (slot.extraCSS) 646 element.classList.add(slot.extraCSS); 647 if (shouldDisplay) 648 _this.refresh(slotId); 649 } 650 else { 651 element.remove(); 652 } 653 }); 654 }; 655 IOLComercialPlatform.prototype.addNewPlacement = function (slot) { 656 if (!slot) 657 return; 658 if (!this.isPlatformLoadedCorrectly()) { 659 this.slotQueue.push(slot); 660 console.error("IOLCOMERCIAL: Added to queue"); 661 return; 662 } 663 if (this.slotsIndex[slot.name]) { 664 console.error("IOLCOMERCIAL: Slot name already exists"); 665 return; 666 } 667 this.createSlot(slot); 668 }; 669 IOLComercialPlatform.prototype.checkRestrictions = function (element) { 670 return this.checkScreenRestriction(element); 671 }; 672 IOLComercialPlatform.prototype.checkScreenRestriction = function (element) { 673 var screenWidth = window.innerWidth; 674 var screenMinRestriction = element["dataset"]["iolComercialMinScreenWitdh"]; 675 var screenMaxRestriction = element["dataset"]["iolComercialMaxScreenWitdh"]; 676 if (!screenMinRestriction && !screenMaxRestriction) 677 return true; 678 try { 679 screenMinRestriction = screenMinRestriction 680 ? parseInt(screenMinRestriction) 681 : undefined; 682 screenMaxRestriction = screenMaxRestriction 683 ? parseInt(screenMaxRestriction) 684 : undefined; 685 if (screenMinRestriction && 686 !screenMaxRestriction && 687 screenWidth > screenMinRestriction) 688 return true; 689 if (screenMaxRestriction && 690 !screenMinRestriction && 691 screenWidth < screenMaxRestriction) 692 return true; 693 if (screenMinRestriction && 694 screenMaxRestriction && 695 screenWidth > screenMinRestriction && 696 screenWidth < screenMaxRestriction) 697 return true; 698 } 699 catch (error) { 700 console.error("IOLCOMERCIAL: Screen Restriction not valid."); 701 } 702 return false; 703 }; 704 IOLComercialPlatform.prototype.shouldAdsBeLoaded = function (project) { 705 var sluserx1 = localStorage.getItem("userx1"); 706 if (!sluserx1) 707 return true; 708 var user; 709 try { 710 user = JSON.parse(sluserx1); 711 } 712 catch (_a) { 713 return true; 714 } 715 var subscribedProducts = user === null || user === void 0 ? void 0 : user.subscribedProducts; 716 if (!(subscribedProducts === null || subscribedProducts === void 0 ? void 0 : subscribedProducts.length)) 717 return true; 718 var noAdsProducts = project === "tviplayer" 719 ? this.noPubProducts 720 : this.noPubPremiumProducts; 721 var isSubbed = noAdsProducts.some(function (p) { 722 return subscribedProducts.includes(p); 723 }); 724 return !isSubbed; 725 }; 726 IOLComercialPlatform.prototype.removeAllPlacements = function () { 727 var placement = document.querySelectorAll(".iol-comercial-placement"); 728 placement.forEach(function (element) { 729 element.remove(); 730 }); 731 }; 732 IOLComercialPlatform.prototype.removeAllPlacementWrappers = function () { 733 console.info("IOLCOMERCIAL: removing ads wrappers"); 734 var placement = document.querySelectorAll(".mcd-hidden-block"); 735 placement.forEach(function (element) { 736 element.remove(); 737 }); 738 }; 739 IOLComercialPlatform.prototype.lazyLoadAdSlot = function (slot) { 740 var _this = this; 741 var observer = new IntersectionObserver(function (entries) {
742 entries.forEach(function (entry) { 743 if (entry.isIntersecting) { 744 _this.AMGoogleTag.cmd.push(function () { 745 //this.AMGoogleTag.display(slot.id); 746 _this.refresh(slot.id); 747 slot.classList.add("iol-comercial-placement-displayed"); 748 console.log("IO - display ad: " + slot.id); 749 }); 750 observer.unobserve(slot); 751 } 752 }); 753 }, { 754 rootMargin: '250px' 755 }); 756 observer.observe(slot); 757 }; 758 IOLComercialPlatform.prototype.isAboveFold = function (element, threshold) { 759 if (threshold === void 0) { threshold = 0; } 760 var rect = element.getBoundingClientRect(); 761 return rect.top < (window.innerHeight + threshold); 762 }; 763 return IOLComercialPlatform; 764}()); 765 766var IOLComercial = /** @class */ (function () { 767 function IOLComercial(project, platform, section, contentType, quantcast) { 768 var _this = this; 769 //ADUNIT RULE: code/project/platform/section/contentType/format 770 this.AMCode = "130294768"; 771 this.project = project; 772 this.platform = platform; 773 this.pageSection = section; 774 this.pageContentType = contentType; 775 var AMUnit = "/".concat(this.AMCode, "/").concat(this.project, "/").concat(this.platform); 776 if (this.pageSection) { 777 AMUnit += "/".concat(this.pageSection); 778 } 779 if (this.pageContentType) { 780 AMUnit += "/".concat(this.pageContentType); 781 } 782 this.iolComercialPlatform = new IOLComercialPlatform(AMUnit); 783 if (this.iolComercialPlatform.shouldAdsBeLoaded(this.project)) { 784 this.iolComercialPlatform.loadDependencies(function () { 785 _this.loadStyle(); 786 _this.iolComercialPlatform.preloadMainPlacements(); 787 var development = document.location.host.includes("localhost") || document.location.host.includes("dev."); 788 if (quantcast && !development) { 789 _this.waitForQuantcast(); 790 } 791 else { 792 if (development) 793 console.info("IOLCOMERCIAL: DEV MODE"); 794 _this.iolComercialPlatform.loadAllPlacementsIntoPage(); 795 } 796 }); 797 } 798 else { 799 this.iolComercialPlatform.removeAllPlacements(); 800 this.iolComercialPlatform.removeAllPlacementWrappers(); 801 this.iolComercialPlatform.loadDependencies(function () { }); 802 } 803 } 804 IOLComercial.prototype.refreshSlot = function (slotname) { 805 this.iolComercialPlatform.refresh(slotname); 806 }; 807 IOLComercial.prototype.refreshAllSlots = function () { 808 this.iolComercialPlatform.refreshDisplayedSlots(); 809 }; 810 IOLComercial.prototype.addNewPlacementByName = function (divID) { 811 this.iolComercialPlatform.createNewPlacement(divID); 812 }; 813 IOLComercial.prototype.loadNewPlacements = function () { 814 this.iolComercialPlatform.loadNewPlacements(); 815 }; 816 IOLComercial.prototype.loadStyle = function () { 817 var head = document.head || document.getElementsByTagName("head")[0]; 818 var style = document.createElement("style"); 819 var css = ".iol-comercial-placement-label > div:before {\n content:'PUBLICIDADE';\n display:block;\n text-align: center;\n color:#808080;\n font-size: 9px;\n font-family: 'Arial';\n line-height: 16px;\n }\n [data-iol-comercial-format=\"MPU2\"], [data-iol-comercial-format=\"MPU_HALF\"] {\n > div{\n margin-top:16px;\n &:before {\n margin-top: -16px;\n }\n }\n }"; 820 style.type = "text/css"; 821 style.appendChild(document.createTextNode(css)); 822 head.appendChild(style); 823 }; 824 IOLComercial.prototype.waitForQuantcast = function () { 825 var _this = this; 826 var count = 0; 827 var consentCheckInterval = setInterval(function () { 828 var _a; 829 if (window["__tcfapi"] || count == 60) { 830 try { 831 (_a = window["__tcfapi"]) === null || _a === void 0 ? void 0 : _a.call(window, "addEventListener", 2, function (tcData, success) { 832 if (success && tcData.tcString) { 833 _this.iolComercialPlatform.loadAllPlacementsIntoPage(); 834 window["__tcfapi"]("removeEventListener", 2, function (success) { 835 if (success) 836 console.info("IOLCOMERCIAL: Quantcast listener removed"); 837 }, tcData.listenerId); 838 } 839 }); 840 clearInterval(consentCheckInterval); 841 } 842 catch (error) { 843 console.error(error); 844 clearInterval(consentCheckInterval); 845 console.error("IOLCOMERCIAL: CMP not loaded"); 846 } 847 } 848 count++; 849 }, 100); 850 }; 851 return IOLComercial; 852}()); 853 854window.IOLComercial = IOLComercial;
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.