// ADS let adUnitPrefix = '/134312942/'; let adRefreshDelay = 20000; var apsPrebid = {}; var adDivIds = {}; var dfpAdDivIds = {}; let googleAdsSizeArray = { 'billboard': [970, 250], 'leaderboard': [[728, 90], [468, 60]], 'leaderboard_small': [468, 60], 'skyscraper': [300, 600], 'skyscraper_mobile': [300, 600], 'square': [ [300, 250], [336, 280] ], 'mobile': [ [320, 50], [300, 50], [320, 100] ], 'mobile_adhesion': [ [320, 50], [300, 50] ], 'mobile_bit': [ [320, 50], [320, 152] ], 'mobile_apple': [ [320, 50], [320, 80] ], 'mobile_podcast_apple': [ [320, 100] ], 'native_in_content': ['fluid'], 'nativo_mobile_mpu': [336, 280], 'short_billboard': [750, 250], 'out_1x1': [1, 1], 'out_300x250': [ [1, 1], [300, 250] ] }; /* let googleAdsBidArray = { 'leaderboard': [{ bidder: 'appnexus', params: { placementId: '11832878' } }] } */ function prebidConfig() { var CMP_TIMEOUT = 8000; var consentManagement = { gdpr: { cmpApi: 'iab', timeout: CMP_TIMEOUT, allowAuctionWithoutConsent: false //defaultGdprScope: true // TCF 2.0 & PBJS v4+ }, usp: { cmpApi: 'iab', timeout: CMP_TIMEOUT } } if (typeof __tcfapi !== 'function') { delete consentManagement.gdpr; } pbjs.que.push(function () { pbjs.setConfig({ useBidCache: true, userSync: { filterSettings: { iframe: { bidders: '*', filter: 'include' }, image: { bidders: '*', filter: 'include' } }, syncsPerBidder: 3, // and no more than 3 syncs at a time syncDelay: 6000, // 6 seconds after the auction }, consentManagement: consentManagement, bidderSequence: 'random', enableSendAllBids: false, priceGranularity: 'high', publisherDomain: window.location.origin }); }); } function setupAllDfpAds() { var dfpElements = document.getElementsByClassName("cos_dfp_ad"); for (var i = 0; i < dfpElements.length; i++) { if (dfpElements[i].getAttribute('id') in dfpAdDivIds) { continue; } setupDfpAd(dfpElements[i].getAttribute('data-adunit'), dfpElements[i].getAttribute('data-size'), dfpElements[i].getAttribute('id')); dfpAdDivIds[dfpElements[i].getAttribute('id')] = true; } } function setupDfpAd(adUnit, size, divId) { //cX.callQueue.push(['invoke', function() { googletag.cmd.push(function () { var slot = googletag.defineSlot(adUnitPrefix + adUnit, googleAdsSizeArray[size], divId); // all other targeting if (googleAdsTargetingArray) { for (var i = 0; i < googleAdsTargetingArray.length; i++) { slot.setTargeting(googleAdsTargetingArray[i][0], googleAdsTargetingArray[i][1]); } } slot.addService(googletag.pubads()); googletag.enableServices(); googletag.pubads().refresh([slot]); }); //}]); } setupAllDfpAds(); function setupAd(adUnit, size, divId) { googletag.cmd.push(function () { if (divId in adDivIds) return; var bidData; // normalize bid data if (size in googleAdsBidArray) { if (googleAdsBidArray[size].hasOwnProperty('mediaTypes')) { bidData = googleAdsBidArray[size]; } else { bidData = { code: adUnitPrefix + adUnit, mediaTypes: { banner: { sizes: googleAdsSizeArray[size] } }, bids: googleAdsBidArray[size] }; } } // add bid data to prebid pbjs.que.push(function () { pbjs.addAdUnits(bidData); }); // create google ad slot var slot = googletag.defineSlot(adUnitPrefix + adUnit, googleAdsSizeArray[size], divId); // ad type targeting if (bidData != null) { if (bidData.hasOwnProperty('video')) { slot.setTargeting('adType', 'video'); } else { slot.setTargeting('adType', 'banner'); } } slot.addService(googletag.pubads()); // all other targeting if (googleAdsTargetingArray) { for (var i = 0; i < googleAdsTargetingArray.length; i++) { googletag.pubads().setTargeting(googleAdsTargetingArray[i][0], googleAdsTargetingArray[i][1]); } } trackAd(divId, slot, bidData, true); }); } function getSizesFromSlot(divId) { var sizes = []; var slotSizes = adDivIds[divId]['slot'].getSizes(); for (var i = 0; i < slotSizes.length; i++) { sizes.push([slotSizes[i].width, slotSizes[i].height]); } return sizes; } function __refreshAd(divId) { // wait for both aps and prebid to return with bids if (!apsPrebid[divId]['aps'] || !apsPrebid[divId]['prebid']) { return; } googletag.cmd.push(function () { pbjs.setTargetingForGPTAsync([adDivIds[divId]['slot'].getAdUnitPath()]); googletag.pubads().refresh([adDivIds[divId]['slot']]); }); apsPrebid[divId]['aps'] = false; apsPrebid[divId]['prebid'] = false; } function refreshAd(divId) { trackAd(divId); // do this immediately otherwise ads will refresh twice cuz of the delay // APS apstag.fetchBids({ slots: [{ slotID: divId, slotName: adDivIds[divId]['slot'].getAdUnitPath(), sizes: getSizesFromSlot(divId) }] }, function (bids) { /* console.log('APS request', { slotID: divId, slotName: adDivIds[divId]['slot'].getAdUnitPath(), sizes: getSizesFromSlot(divId) }); console.log('APS bids', bids); */ googletag.cmd.push(function () { apstag.setDisplayBids(); apsPrebid[divId]['aps'] = true; __refreshAd(divId); }); }); // PREBID // fetch bids for display ad units if (adDivIds[divId]['slot'].getTargeting('adType') != 'video') { pbjs.que.push(function () { pbjs.requestBids({ timeout: 3000, adUnitCodes: [adDivIds[divId]['slot'].getAdUnitPath()], bidsBackHandler: function () { apsPrebid[divId]['prebid'] = true; __refreshAd(divId); //trackAd(divId); } }); }); } else { // only refresh the video ad unit without fetching any new bids pbjs.que.push(function () { __refreshAd(divId); }); } } function trackAd(divId, slot = null, bidData = null, initial = false) { if (!(divId in adDivIds)) { adDivIds[divId] = { time: null, slot: null, viewed: false }; } adDivIds[divId]['time'] = new Date().getTime(); if (slot !== null) { adDivIds[divId]['slot'] = slot; } if (bidData !== null) { adDivIds[divId]['bidData'] = bidData; } if (initial) { adDivIds[divId]['initial'] = true; // store also in apsPrebid combo if (!(divId in apsPrebid)) { apsPrebid[divId] = { aps: false, prebid: false }; } } else { adDivIds[divId]['initial'] = false; } } function adElapsed(divId, milliseconds) { return (new Date().getTime() - adDivIds[divId]['time']) >= milliseconds; } function adMonitor() { var elements = document.getElementsByClassName("cos_ad"); for (var i = 0; i < elements.length; i++) { // remove auto refresh for 300x250 sticky /* if (elements[i].getAttribute('data-adunit') === 'COS_DT_300_250_STICKY') { elements[i].classList.remove('ad_refresh'); }*/ // add to setup if not available if (!(elements[i].getAttribute('id') in adDivIds)) { setupAd(elements[i].getAttribute('data-adunit'), elements[i].getAttribute('data-size'), elements[i].getAttribute('id')); } else { // if visible in viewport if (isVisible(elements[i], 0.5)) { //console.log('impression VISIBLE', elements[i].getAttribute('id')) // second time in view and has ad_refresh class if (adDivIds[elements[i].getAttribute('id')]['initial'] == false && elements[i].classList.contains('ad_refresh')) { if (adDivIds[elements[i].getAttribute('id')]['viewed'] == true) { adDivIds[elements[i].getAttribute('id')]['viewed'] = false; refreshAd(elements[i].getAttribute('id')); } // first time in view } else if (adDivIds[elements[i].getAttribute('id')]['initial'] == true) { refreshAd(elements[i].getAttribute('id')); } } } } } prebidConfig(); // Monitor all ads every second let adInterval = setInterval(adMonitor, 500); window.onunload = function () { clearInterval(adInterval); } // resize ad slot on render to fit googletag.cmd.push(function () { googletag.pubads().addEventListener('slotRenderEnded', function (event) { var size = event.size; if (size === null) return; var slot = event.slot; var slotDiv = document.getElementById(slot.getSlotElementId()); if (size[0] > slotDiv.clientWidth) { slotDiv.style.width = size[0] + 'px'; slotDiv.parentElement.style.width = slotDiv.style.width; slotDiv.style.height = size[1] + 'px'; slotDiv.parentElement.style.height = slotDiv.style.height; } }); }); // impression viewable event googletag.cmd.push(function () { googletag.pubads().addEventListener('impressionViewable', function (event) { var slot = event.slot; if (document.getElementById(slot.getSlotElementId()).classList.contains('ad_refresh')) { setTimeout(function () { adDivIds[slot.getSlotElementId()]['viewed'] = true; }, adRefreshDelay); //console.log("impression VIEWABLE fired", slot.getSlotElementId()); } // leaderboard sticky var lboard = document.getElementById(slot.getSlotElementId()).closest('.bg-white'); if (lboard) lboard.classList.remove('leaderboard-sticky'); }); }); function isVisible(el, visibleRatio) { var visible = horizontal(el) * vertical(el); return visible > visibleRatio; } function horizontal(el) { var windowWidth = window.innerWidth var elemLeft = el.getBoundingClientRect().left var elemRight = el.getBoundingClientRect().right var elemWidth = elemRight - elemLeft // Not viewable, below viewport if (elemLeft > windowWidth) return 0; // Not viewable, above the viewport else if (elemRight <= 0) return 0; // Element is completely visible else if (elemLeft >= 0 && elemRight <= windowWidth) return 1; // Top and bottom of element truncated else if (elemLeft < 0 && elemRight > windowWidth) return windowWidth / elemWidth; // Top of element is truncated else if (elemLeft < 0 && elemRight <= windowWidth) return elemRight / elemWidth; // Bottom of element is truncated else if (elemLeft >= 0 && elemRight > windowWidth) return (windowWidth - elemLeft) / elemWidth; // Error else return 0; } function vertical(el) { var windowHeight = window.innerHeight var elemTop = el.getBoundingClientRect().top var elemBottom = el.getBoundingClientRect().bottom var elemHeight = elemBottom - elemTop // Not viewable, below viewport if (elemTop > windowHeight) return 0; // Not viewable, above the viewport else if (elemBottom <= 0) return 0; // Element is completely visible else if (elemTop >= 0 && elemBottom <= windowHeight) return 1; // Top and bottom of element truncated else if (elemTop < 0 && elemBottom > windowHeight) return windowHeight / elemHeight; // Top of element is truncated else if (elemTop < 0 && elemBottom <= windowHeight) return elemBottom / elemHeight; // Bottom of element is truncated else if (elemTop >= 0 && elemBottom > windowHeight) return (windowHeight - elemTop) / elemHeight; // Error else return 0; } function loadOnDemand(url, id, type) { // already exists if (document.querySelectorAll('#' + id).length > 0) return; if (!type) return; var s; if (type == 'script') { s = document.createElement("script"); s.src = url; s.id = id; } else { s = document.createElement("link"); s.rel = 'stylesheet'; s.href = url; s.id = id; } // append to head in dom let head = document.head || document.getElementsByTagName('head')[0]; head.insertBefore(s, head.firstChild); } function delayScriptsOnLoad() { loadOnDemand('//cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css?ver=5.4.2', 'animate-style', 'style'); } // delay loading of certain resources var raf = requestAnimationFrame || mozRequestAnimationFrame || webkitRequestAnimationFrame || msRequestAnimationFrame; if (raf) raf(delayScriptsOnLoad); else window.addEventListener('load', delayScriptsOnLoad); function delayIframe(iframeID, iframeURL) { setTimeout(function () { var el = document.querySelectorAll('[data-delay="' + iframeID + '"]'); if (el.length > 0) el[0].src = iframeURL; }, 1000); } /* sticky sidebar ads */ window.addEventListener('scroll', sticky_sidebar_ads); function sticky_sidebar_ads() { var article_content = document.querySelector("article.content-col"); if (!article_content) return; var article_content_height = article_content.offsetHeight; const boxes = document.querySelectorAll('.sticky-container'); boxes.forEach(box => { box.style.height = article_content_height / 2 + 'px'; }); } ; window.dataLayer = window.dataLayer || []; function trackIframeClick() { window.addEventListener('blur', function (e) { if (document.activeElement.nodeName == "IFRAME" && (document.activeElement.src != '' || document.activeElement.name != '')) { var type = ''; var iframeURL = document.activeElement.src; if (document.activeElement.src != '') { if (document.activeElement.src.indexOf('spotify') != -1) type = 'spotify'; if (document.activeElement.src.indexOf('itunes') != -1) type = 'itunes'; if (document.activeElement.src.indexOf('youtube') != -1) type = 'youtube'; if (document.activeElement.src.indexOf('tunein') != -1) type = 'tunein'; if (document.activeElement.src.indexOf('acast') != -1) type = 'acast'; if (document.activeElement.src.indexOf('anchor') != -1) type = 'anchor'; } else if (document.activeElement.name != '') { if (document.activeElement.name.indexOf('frame-product') != -1) { type = 'cosstore'; iframeURL = document.activeElement.name; } } try { const fullUrl = new URL(iframeURL); const gaItem = { 'eventCategory': 'iframe', 'eventAction': 'iframe_click', 'eventLabel': type, 'eventUrl': fullUrl.href, 'eventReferrer': window.parent.location.href, 'event': 'cos_click', 'eventValue': 1, }; window.dataLayer.push(gaItem); } catch (error) { console.log('iframe click', 'error', error); } } }); } trackIframeClick();; /** * Check if key exists in local storage * @param string key * @return boolean */ function localStorageHas (key) { var item = localStorage.getItem(key); return ( item !== null ); } /** * Retrive an object from local storage. * @param string key * @return mixed */ function localStorageGet (key) { var item = localStorage.getItem(key); if ( ! item ) return; if ( item[0] === '{' || item[0] === '[' ) return JSON.parse(item); return item; } /** * Save some value to local storage. * @param string key * @param string value */ function localStorageSet (key, value) { if ( value === undefined ) $.error("Can't store undefinded value"); if ( typeof(value) === 'object' || typeof(value) === 'array' ) { value = JSON.stringify(value); } if ( typeof(value) !== 'string' ) $.error("Can't store unrecognized format value"); localStorage.setItem(key, value); } /** * Remove element from local storage. * @param string key */ function localStorageRemove (key) { localStorage.removeItem(key); }; window.jQuery = window.$ = jQuery; $(document).ready(function () { /* // FIXED TOP NAV $(document).on("scroll", function() { if ($(document).scrollTop() > 400) { $(".fixed-top").addClass("scrolled slideInDown"); } else { $(".fixed-top").removeClass("scrolled"); } }); // FIXED TOP CATEGORIES NAV INNER PAGE $(document).on("scroll", function() { if ($(document).scrollTop() > 1200) { $(".cats-bar").addClass("scrolled slideInDown"); } else { $(".cats-bar").removeClass("scrolled"); } }); */ // MENU $(".but-menu").click(function () { $("#menu").addClass("reveal slideInLeft"); $('html').css('overflow', 'hidden'); $('body').bind('touchmove', function (e) { e.preventDefault() }); }); $(".menu-close").click(function () { $("#menu").removeClass("reveal"); $('html').css('overflow', 'scroll'); $('body').unbind('touchmove'); }); // MENU CATS $(".menu-item").click(function () { $(".menu-item").toggleClass("open").not(this).removeClass("open"); }); $(".menu-news").click(function () { $(".sub-reviews, .sub-features, .sub-live, .sub-podcasts, .sub-videos, .sub-heavy, .sub-shop").hide(); $(".sub-news").toggle(); }); $(".menu-reviews").click(function () { $(".sub-news, .sub-features, .sub-live, .sub-podcasts, .sub-videos, .sub-heavy, .sub-shop").hide(); $(".sub-reviews").toggle(); }); $(".menu-features").click(function () { $(".sub-news, .sub-reviews, .sub-live, .sub-podcasts, .sub-videos, .sub-heavy, .sub-shop").hide(); $(".sub-features").toggle(); }); $(".menu-live").click(function () { $(".sub-news, .sub-reviews, .sub-podcasts, .sub-videos, .sub-heavy, .sub-shop").hide(); $(".sub-live").toggle(); }); $(".menu-podcasts").click(function () { $(".sub-news, .sub-reviews, .sub-features, .sub-live, .sub-videos, .sub-heavy, .sub-shop").hide(); $(".sub-podcasts").toggle(); }); $(".menu-videos").click(function () { $(".sub-news, .sub-reviews, .sub-features, .sub-live, .sub-heavy, .sub-shop").hide(); $(".sub-videos").toggle(); }); $(".menu-heavy").click(function () { $(".sub-news, .sub-reviews, .sub-features, .sub-live, .sub-podcasts .sub-videos, .sub-shop").hide(); $(".sub-heavy").toggle(); }); $(".menu-shop").click(function () { $(".sub-news, .sub-reviews, .sub-features, .sub-live, .sub-podcasts .sub-videos, .sub-heavy").hide(); $(".sub-shop").toggle(); }); $(".menu-hometowns").click(function () { $(".sub-news, .sub-reviews, .sub-features, .sub-live, .sub-podcasts .sub-videos, .sub-heavy, .sub-shop").hide(); }); // SEARCH $(".but-search").click(function () { $("#search-bar").addClass("reveal slideInDown"); }); $(".search-close").click(function () { $("#search-bar").removeClass("reveal"); }); $("#search_404").click(function () { $("#search-bar").addClass("reveal slideInDown"); }); // FIXED FILTERS / TRENDING BAR ON SCROLL $('.fixed-bar.trending-bar').scrollToFixed({ marginTop: 130 }); $('.mobile-bar-drop').scrollToFixed({ marginTop: 130 }); // FIXED AD ON SCROLL /* $('.fixed-ad-scroll').scrollToFixed({ marginTop: 140, zIndex: 10, limit: function() { var limit = $('#footer').offset().top - $('.fixed-ad-scroll').outerHeight(true) - 0; return limit; } }); */ /* $('.fixed-ad-scroll-bottom').scrollToFixed({ marginTop:400, limit: function() { var limit; if ($('.post-related').length > 0) { limit = $('.post-related').offset().top - $('.fixed-ad-scroll-bottom').outerHeight(true) - 80; } else { limit = $('#footer').offset().top - $('.fixed-ad-scroll-bottom').outerHeight(true) - 40; } return limit; } }); */ // FIXED SOCIAL ON SCROLL /* $('.social-follow.fixed').scrollToFixed({ marginTop: 200, limit: function() { var limit = $('.post-tags').offset().top - $('.social-follow.fixed').outerHeight(true) - 40; return limit; } }); */ // FIXED VIDEO ON SCROLL /* $('.fixed-watch-video').scrollToFixed({ marginTop: 200, limit: function() { var limit; if ($('.post-related').length > 0) { limit = $('.post-related').offset().top - $('.fixed-watch-video').outerHeight(true) - 80; } else { limit = $('#footer').offset().top - $('.fixed-watch-video').outerHeight(true) - 40; } return limit; } }); */ // FIXED SQUARE ON SCROLL /* $('.fixed-ad-aside').scrollToFixed({ marginTop: 200, limit: function() { var limit; if ($('.post-related').length > 0) { limit = $('.post-related').offset().top - $('.fixed-ad-aside').outerHeight(true) - 80; } else { limit = $('#footer').offset().top - $('.fixed-ad-aside').outerHeight(true) - 40; } if ($('.fixed-watch-video').length > 0) { limit += $('.fixed-watch-video').outerHeight(true); } return limit; } }); */ // READER'S RATING $(document).on("scroll", function () { if ($(document).scrollTop() > 200) { $(".reader-rating").addClass("scrolled bounceInUp"); } else { $(".reader-rating").removeClass("scrolled"); } }); // MOBILE BAR DROP $(".open-drop").click(function () { $(".open-drop").toggleClass("open"); }); $(".open-drop").click(function () { $(".mobile-bar-drop ul").toggle(); }); // VIDEOS PLAYLIST $(".video-playlist a").click(function () { var parent_div = $(this).closest('div'); var src = $(parent_div).attr('data-src'); var type = $(parent_div).attr('data-type'); var poster = $(parent_div).attr('data-poster'); var title = $(parent_div).attr('data-title'); var videoObj = $(this).parents(".mod-playlist").find(".video-js"); if (videoObj.length !== 0) { var player = videojs(videoObj.attr('id')); if (src == player.src()) { return; } if (player.ads && player.ads.isInAdMode()) { return; } player.poster(poster); player.src([{ type: type, src: src }]); player.play(); player.on('loadstart', function (event) { $('#' + player.id() + '_title').text(title) }); $(this).parents('.col-video-scrollable').find('p.play-now a').text('Play Now'); $(this).parents('.video-playlist').find('p.play-now a').text('Now Playing'); } }); // VIDEOS Playing Now Text $("p.play-now a").first().text('Now Playing'); // MOBILE ADHESION //$(".mobile-adhesion").delay(5000).fadeOut('slow'); /* // RENDER PENDING ADS function renderPendingAds() { $(".ad_pending").each(function(i, e){ renderAd($(e).attr('data-adunit'), $(e).attr('data-size'), $(e).attr('id')); $(e).removeClass('ad_pending'); }); } // REGULAR ADS renderPendingAds(); // INFINITE SCROLL ADS $(document.body).on('post-load', function () { renderPendingAds(); }); */ resizeIframes(); }); // IFRAME RESIZING function resizeIframes() { $("iframe").each(function (i, v) { var domains = ['spotify', 'apple', 'vevo']; if (typeof $(v).attr('src') !== 'undefined') { $(domains).each(function (di, dv) { if ($(v).attr('src').indexOf(dv) !== -1) { $(v).attr('height', 450); } }); if ($(v).attr('src').indexOf('anchor') !== -1) { $(v).attr('height', 160); $(v).attr('scrolling', 'no'); } } }); } // ajax load more - next page in infinite scroll window.almComplete = function (alm) { resizeIframes(); setupAllDfpAds(); //setupIframeOnDemand(); if (typeof initGallery === 'function') initGallery(); // actual code in partials/common/_gallery.php } $(document).ready(function () { if (typeof initGallery === 'function') initGallery(); // actual code in partials/common/_gallery.php }); window.almUrlUpdate = function (permalink, type) { gtag("event", "page_view", { page_path: window.location.pathname, custom_map: { 'dimension1': 'Categories', 'dimension2': 'Tags', 'dimension3': 'Authors', 'dimension4': 'Artists', 'dimension6': 'page_id', 'dimension7': 'Primary Category', 'dimension9': 'Paged Article', 'dimension10': 'Primary Search Term' } }); } // iframe on demand for youtube function setupIframeOnDemand() { $(".embed-youtube-on-demand").click(function () { var id = $(this).children('img').attr('data-id'); var iframe = ''; $(this).replaceWith(iframe); }); } $(function () { var url = new URL(window.location.href); if (url.searchParams.get('app')) { $("a").attr('href', function (index, item) { if (item) return item + (item.indexOf('?') != -1 ? "&app=true" : "?app=true"); }); } var subId3 = ''; if (subId3 = url.searchParams.get('subId3')) { $("a").attr('href', function (index, item) { if (item && item.indexOf('ticketmaster') !== -1) return item + (item.indexOf('?') != -1 ? "&subId3=" + subId3 : "?subId3=" + subId3); }); } });;