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'; if (document.activeElement.src.indexOf('apple') != -1) type = 'apple'; } 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(); function trackSearchClicks() { const trackedLinks = document.querySelectorAll('a.track-links'); trackedLinks.forEach(function (link) { link.addEventListener('click', function (event) { try { const href = this.getAttribute('href'); const type = this.getAttribute('data-type'); const fullUrl = new URL(href, window.location.href); const gaItem = { 'eventCategory': 'search', 'eventAction': 'search_click', 'eventLabel': type, 'eventUrl': fullUrl.href, 'eventReferrer': window.parent.location.href, 'event': 'cos_search_click', 'eventValue': 1, }; window.dataLayer.push(gaItem); } catch (error) { console.log('search click', 'error', error); } }); }); } trackSearchClicks();; /** * 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 $(document).ready(function() { // 1. Identify "flat" items (no sub-menu) and add the CSS flag $('.accordion .col').each(function() { // If this column does not contain a sub-menu list if ($(this).find('.sub-cats').length === 0) { // Add a class so CSS can hide the arrow icon $(this).find('.menu-item').addClass('no-sub'); } }); // 2. Unified Click Handler $(".menu-item").on('click', function(e) { // Stop default behavior and event clashing e.preventDefault(); e.stopImmediatePropagation(); var $this = $(this); var $parentCol = $this.closest('.col'); var $subMenu = $parentCol.find('.sub-cats'); var $link = $parentCol.find('.menu-d a').attr('href'); // Close all other open submenus $(".sub-cats").not($subMenu).hide(); $(".menu-item").not($this).removeClass("open"); // IF SUBMENU EXISTS: Toggle the accordion if ($subMenu.length > 0) { $this.toggleClass("open"); $subMenu.stop(true, true).toggle(); } // IF NO SUBMENU: Navigate to the destination URL else if ($link) { window.location.href = $link; } }); }); // 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 }); */ $(window).on('load', function () { if ( $('.mobile-bar-drop').length > 0 && typeof $.fn.scrollToFixed === 'function' ) { $('.mobile-bar-drop').scrollToFixed({ marginTop: 110 }); } }); // 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) { if ($(v).hasClass('no-resize')) { return; } var domains = ['spotify', 'apple', 'vevo', 'music.amazon']; 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'); } } }); } // inifiite scroll on category and tag pages (function ($) { $(document.body).on('post-load', function () { window.EncoreAdSystem.observerAds(); embedInitiate(); }); })(jQuery); // For initial load window.addEventListener('load', function () { embedInitiate(); }); function embedInitiate() { if (window.instgrm) { window.instgrm.Embeds.process(); } if (window.twttr && window.twttr.widgets && typeof window.twttr.widgets.load === 'function') { window.twttr.widgets.load(); } if (typeof window.tiktokEmbedLoad === 'function') { window.tiktokEmbedLoad(); } } // 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 window.EncoreAdSystem.observerAds(); } $(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); }); } let appleRegex = /(itunes.apple.com|podcasts.apple.com)([A-Za-z0-9\/_-]+)/gm; $("a").attr('href', function (index, item) { let affId = 'at=1001l36gv'; if (item && item.match(appleRegex) && item.indexOf(affId) === -1) { if (item.indexOf('?') != -1) return item + "&" + affId; else return item + "?" + affId; } }); });;