// get current date for header/footer elements based on reader's location
jQuery(document).ready(function ($) {
var mydate = new Date();
var year = mydate.getYear();
if (year < 1000) year += 1900;
var day = mydate.getDay();
var month = mydate.getMonth();
var monthWithZero = (mydate.getMonth() + 1).toString().padStart(2, '0');
var daym = mydate.getDate();
var dayWithZero = (mydate.getDay() + 1).toString().padStart(2, '0');
var dayFullArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
var dayArray = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
var monthFullArray = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var monthArray = new Array("Jan.", "Feb.", "March", "April", "May", "June", "July", "Aug.", "Sept.", "Oct.", "Nov.", "Dec.");
$('.sno-hac-date').each(function () {
let format = $(this).data('format').toString().split("");
let date = '';
if (format[0] == '1') date += dayArray[day];
if (format[0] == '2') date += dayFullArray[day];
if (date) date += ', ';
if (format[1] == '1') date += monthArray[month];
if (format[1] == '2') date += monthFullArray[month];
date += ' ' + daym
if (format[3] != '0') date += ', ' + year
$(this).find('time').text(date);
$(this).find('time').attr('datetime', year + '-' + monthWithZero + '-' + dayWithZero)
});
});
// for My Calendar plugin
jQuery(document).ready(function ($) {
$('.mc-main a').each(function () {
$(this).attr('rel', 'nofollow')
})
});
// for moving Related Stories Sidebar content to be below the post on mobile devices
jQuery(document).ready(function ($) {
if ($('.sno-sidebar-related').length && $(window).width() < 600) {
$('.sno-sidebar-related').appendTo($('.sno-story-related-content-insertion'));
}
})
// for ImageLinks added 12/2024
jQuery(document).ready(function ($) {
$('body').on('click', '.dot-wrapper', function (e) {
if ($(this).hasClass('tooltip-only')) return;
const id = $(this).data('id');
const dot = $(this);
const wrap = $(this).closest('.imagelink-wrap');
$(wrap).find('.dot-wrapper:not(.dot-wrapper-' + id).hide();
$(wrap).find('.dot-wrapper-' + id).find('.pulsing-dot, .dot-pulse').fadeOut();
setTimeout(function () {
$(wrap).css('overflow', 'hidden');
$('.dot-wrapper-' + id).find('.dot-overlay').addClass('dot-enlarge');
setTimeout(function () {
const overlayContent = $(dot).find('.imagelink-overlay-content').clone().html()
$(wrap).find('.imagelink-overlay-displayed-content').html(overlayContent);
$(wrap).find('.imagelink-overlay').show();
$(wrap).find('.il-close').data('id', id);
const videoWidth = $('.imagelink-overlay-displayed-content').find('.il-video-full iframe').width();
$('.imagelink-overlay-displayed-content').find('.il-caption-area').width(videoWidth + 'px');
$(wrap).find('.overlay-' + id).focus();
}, 300)
}, 1)
})
$('body').on('click', '.il-close', function () {
const id = $(this).data('id');
const wrap = $(this).closest('.imagelink-wrap');
$(wrap).find('.dot-wrapper-' + id).find('.dot-overlay').removeClass('dot-enlarge')
$(wrap).find('.imagelink-overlay').fadeOut();
var $videoIframe = $(wrap).find('.imagelink-overlay iframe');
if ($videoIframe.length) {
var src = $videoIframe.attr('src');
$videoIframe.attr('src', '');
$videoIframe.attr('src', src);
}
setTimeout(function () {
$(wrap).find('.dot-wrapper').fadeIn();
$('.dot-wrapper-' + id).find('.pulsing-dot, .dot-pulse').fadeIn();
$('.dot-wrapper-' + id).focus();
const $tooltip = $('.dot-wrapper-' + id).find('.dot-tooltip');
$tooltip.css({
opacity: 0,
transform: 'translate(0px, 0px)'
});
setTimeout(() => {
$tooltip.hide();
}, 300);
}, 600)
})
$(document).on('keydown', '.dot-wrapper', function (e) {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
$(this).trigger('click')
}
});
$(document).on('keydown', '.il-close', function (e) {
if (e.key === 'Enter') {
e.preventDefault();
$(this).trigger('click')
}
});
$(document).on('keydown', function (e) {
if (e.key === 'Escape') {
$('.il-close:visible').trigger('click')
}
});
function positionAndShowTooltip($Dot, $tooltip) {
$tooltip.hide().css({
opacity: 0,
transform: 'translate(0px, 0px)'
});
if ($tooltip.text().trim() === "" || $('.preview-panel').length > 0) {
return;
}
const dotPosition = $Dot.position();
const containerWidth = $Dot.closest('.imagelink-wrap').width();
const dotCenterX = dotPosition.left + $Dot.width() / 2;
const dotCenterY = $Dot.height() / 2;
const tooltipHeight = $tooltip.outerHeight();
const tooltipTop = dotCenterY - (tooltipHeight / 2);
if (dotCenterX > containerWidth / 2) {
$tooltip.css({
top: tooltipTop + "px",
left: 'auto',
right: '100%',
transform: 'translate(-10px, 0px)',
opacity: 1,
});
} else {
$tooltip.css({
top: tooltipTop + "px",
left: '100%',
right: 'auto',
transform: 'translate(10px, 0px)',
opacity: 1,
});
}
$tooltip.show();
}
function hideTooltip($tooltip) {
$tooltip.css({
opacity: 0,
transform: 'translate(0px, 0px)',
});
setTimeout(() => {
$tooltip.hide();
}, 300);
}
// Hover events
$('.dot-wrapper').hover(
function () {
const $Dot = $(this);
const $tooltip = $Dot.find('.dot-tooltip');
positionAndShowTooltip($Dot, $tooltip);
},
function () {
const $tooltip = $(this).find('.dot-tooltip');
hideTooltip($tooltip);
}
);
// Focus and blur events for keyboard navigation
$(document).on('focus', '.dot-wrapper', function () {
const $Dot = $(this);
const $tooltip = $Dot.find('.dot-tooltip');
positionAndShowTooltip($Dot, $tooltip);
});
$(document).on('blur', '.dot-wrapper', function () {
const $tooltip = $(this).find('.dot-tooltip');
hideTooltip($tooltip);
});
});
// for live updates added 06/2024
jQuery(document).ready(function ($) {
$('body').on('mouseenter', '.live-update-share-wrap', function () {
$(this).find('.live-update-share-text').show();
$(this).find('.live-update-share-link').addClass('live-update-share-link-hover');
});
$('body').on('mouseleave', '.live-update-share-wrap', function () {
$(this).find('.live-update-share-text').hide();
$(this).find('.live-update-share-link').removeClass('live-update-share-link-hover');
});
$('body').on('click', '.live-update-share-link', function () {
$(this).closest('.live-update-share-wrap').find('.live-update-share-text').text('Link Copied');
var share_link = $(this).data('share-link');
var $tempInput = $('');
$('body').append($tempInput);
$tempInput.val(share_link).select();
document.execCommand('copy');
$tempInput.remove();
$(this).closest('.live-update-share-wrap').find('.live-update-share-link').removeClass('live-update-share-link-hover');
var clicked = $(this)
setTimeout(function () {
$(clicked).closest('.live-update-share-wrap').find('.live-update-share-text').hide();
var label = $(clicked).closest('.live-update-share-wrap').find('.live-update-share-text')
$(label).text('Sharing Link');
}, 1000)
});
if (window.location.hash && window.location.hash.includes('live-update')) {
setTimeout(function () {
var initialTargetId = window.location.hash;
var topoffset = ($('#wpadminbar').length > 0) ? 60 : 25;
var stickyHeaderOffset = 0;
$('.sno-header-wrap-desktop .sno-header-row-stick').each(function () {
stickyHeaderOffset += $(this).height();
})
$('html, body').animate({
scrollTop: $(initialTargetId).offset().top - topoffset - stickyHeaderOffset
}, 1000);
}, 500);
}
// functions for autoupdating timestamps on live updates
function adjustForGMTOffset(date, gmtOffset) {
var utc = date.getTime() + (date.getTimezoneOffset() * 60);
var offsetMilliseconds = gmtOffset * 3600000;
var adjustedDate = new Date(utc + offsetMilliseconds);
return adjustedDate;
}
function getElapsedTime(dateTimeStamp) {
var now = new Date();
var dateTime = new Date(dateTimeStamp);
dateTime = adjustForGMTOffset(dateTime, -5);
var difference = now - dateTime;
var elapsedMinutes = Math.floor(difference / 1000 / 60);
if (elapsedMinutes <= 0) {
return 'just now';
} else if (elapsedMinutes < 60) {
return elapsedMinutes + ' minute' + (elapsedMinutes === 1 ? '' : 's') + ' ago';
} else if (elapsedMinutes < 1440) {
var elapsedHours = Math.floor(elapsedMinutes / 60);
return elapsedHours + ' hour' + (elapsedHours === 1 ? '' : 's') + ' ago';
} else if (elapsedMinutes < 10080) {
var elapsedDays = Math.floor(elapsedMinutes / 60 / 24);
return elapsedDays + ' day' + (elapsedDays === 1 ? '' : 's') + ' ago';
}
return false;
}
function updateElapsedTime(updateDiv) {
var id = $(updateDiv).attr('id');
var dateTimeStamp = $(updateDiv).find('.live-update-timestamp').data('timestamp-gmt'); // Replace with your timestamp
var elapsedTime = getElapsedTime(dateTimeStamp);
if (elapsedTime && $(updateDiv).find('.timestamp-time').is(':visible')) {
scrollTextOnce(updateDiv, elapsedTime)
} else if (elapsedTime) {
scrollTextUpdate(updateDiv, elapsedTime);
} else {
$(updateDiv).find('.timestamp-elapsed').text($(updateDiv).find('.timestamp-time').text());
var intervalID = $('#' + id).data('intervalid');
clearInterval(intervalID);
}
}
function scrollTextUpdate(updateDiv, elapsedTime) {
var timeSize = parseInt($(updateDiv).find('.live-update-timestamp').data('time-size'));
$(updateDiv).find('.timestamp-elapsed-update').text(elapsedTime);
var text1 = $(updateDiv).find('.timestamp-elapsed').text();
var text2 = $(updateDiv).find('.timestamp-elapsed-update').text();
if (text1 != text2) {
// only animate the timestamp change if the browser tab is active
// this is needed because inactive browser tabs don't run animations
if (typeof document.hidden !== "undefined") {
if (document.hidden) {
// Tab is inactive or hidden
$(updateDiv).find('.timestamp-elapsed').css('top', '-' + timeSize + 'px');
$(updateDiv).find('.timestamp-elapsed-update').css('top', '0px');
$(updateDiv).find('.timestamp-elapsed').css('top', timeSize + 'px');
$(updateDiv).find('.timestamp-toggle').toggleClass('timestamp-elapsed timestamp-elapsed-update');
} else {
// Tab is active -- animate the change
$(updateDiv).find('.timestamp-elapsed').animate({top: '-' + timeSize + 'px'}, 500);
$(updateDiv).find('.timestamp-elapsed-update').animate({
'top': '0px'
}, 500, function () {
$(updateDiv).find('.timestamp-elapsed').css('top', timeSize + 'px');
$(updateDiv).find('.timestamp-toggle').toggleClass('timestamp-elapsed timestamp-elapsed-update');
});
}
}
}
}
if (typeof document.hidden !== "undefined") {
document.addEventListener("visibilitychange", function () {
});
}
function scrollTextOnce(updateDiv, elapsedTime) {
$(updateDiv).find('.timestamp-elapsed').text(elapsedTime);
var timeSize = parseInt($(updateDiv).find('.live-update-timestamp').data('time-size'));
var text1 = $(updateDiv).find('.timestamp-time').text();
var text2 = $(updateDiv).find('.timestamp-elapsed').text();
if (text1 != text2) {
$(updateDiv).find('.timestamp-time').animate({top: '-' + timeSize + 'px'}, 500);
$(updateDiv).find('.timestamp-elapsed').animate({'top': '0px'}, 500);
setTimeout(function () {
$(updateDiv).find('.timestamp-time').hide();
$(updateDiv).find('.timestamp-time').css('top', timeSize + 'px');
}, 501);
}
}
function isElementInViewport(el) {
var $el = $(el);
var elementTop = $el.offset().top;
var elementBottom = elementTop + $el.outerHeight();
var viewportTop = $(window).scrollTop();
var viewportBottom = viewportTop + $(window).height();
return elementBottom > viewportTop && elementTop < viewportBottom;
}
function checkUpdateDivsViewport() {
$('body').find('.live-update-wrap.timestamp-check').each(function (i, v) {
var updateDiv = $(this);
var id = $(this).attr('id').replace('live-update-', '');
if (isElementInViewport('#live-update-' + id)) {
$(this).removeClass('timestamp-check')
var intervalID = '';
setTimeout(function () {
updateElapsedTime(updateDiv);
}, 4000);
setTimeout(function () {
intervalID = setInterval(function () {
updateElapsedTime(updateDiv)
}, 30000);
}, 8000);
$('#live-update-' + id).data('intervalid', intervalID);
}
});
}
checkUpdateDivsViewport()
$('.live-updates-wrap').data('page-title', document.title)
$(window).on('scroll resize', function () {
checkUpdateDivsViewport();
});
// Determine whether or not to start the polling mechanism -- only do so if there was an update in the last 24 hours
var currentTime = Math.floor(Date.now() / 1000);
var oneDayAgo = currentTime - (24 * 60 * 60);
$('.live-update-wrap').each(function () {
var publishedOn = $(this).data('published-on');
if (publishedOn > oneDayAgo) {
// show the live coverage banner
$('.live-coverage-banner-wrap').insertBefore('h1.sno-story-headline').slideDown();
$('.live-coverage-banner').animate({'opacity': '1'}, 500);
pollForUpdates();
return false;
}
});
// move sharing link if both headline and byline are absent
$('.live-update-wrap').each(function () {
if ($(this).find('h3').length < 1 && $(this).find('.sno-story-byline').length < 1) {
$(this).find('.live-update-share-wrap').css({'top': '15px', 'right': '15px'});
}
if ($(this).find('.sno-story-byline').length < 1 && $(this).find('.pinned-flag').length < 1) {
$(this).find('.update-headline-wrap').css({'padding-right': '75px'});
}
})
var pollingIntervalID;
var stopPollingID;
function pollForUpdates() {
// ajax polling system to check server for updates to story every two minutes
pollingIntervalID = setInterval(function () {
checkForUpdates()
}, 120000); // 120000
// Set the timeout to stop the interval after 1 hour (3600000 milliseconds)
stopPollingID = setTimeout(function () {
clearInterval(pollingIntervalID);
showRefreshButton()
}, 3600000);
}
function checkForUpdates() {
var post_id = $('.live-updates-wrap').data('post-id');
var last_rendered = $('.live-updates-wrap').data('last-rendered');
var rendered_ids = [];
$('.live-update-wrap').each(function () {
rendered_ids.push($(this).data('id'));
});
$.ajax({
url: frontend_ajax_object.ajaxurl,
type: 'POST',
data: {
action: 'check_for_updates',
post_id: post_id,
last_rendered: last_rendered
},
success: function (results) {
if (results != 'false') {
$('.refresh-notification').fadeOut();
var update_ids = $.parseJSON(results);
var new_updates = [];
$.each(update_ids, function (i, v) {
if ($.inArray(v, rendered_ids) === -1) {
new_updates.push(v);
}
})
var count = new_updates.length;
if (count == 0) return;
posts_to_retrieve = new_updates.join(',');
var message = (count > 1) ? count + ' New Updates' : '1 New Update';
$('.update-notification').data('new-updates', posts_to_retrieve)
$('.update-notification').attr('data-new-updates', posts_to_retrieve)
$('.update-notification').text(message).fadeIn();
var currentTimestamp = Math.floor(Date.now() / 1000);
$('.live-updates-wrap').data('last-rendered', currentTimestamp)
document.title = '(' + count + ') ' + document.title;
// stop polling until the user clicks the button
if (pollingIntervalID) clearInterval(pollingIntervalID);
if (stopPollingID) clearTimeout(stopPollingID)
} else {
if ($('.refresh-notification').is(':visible')) {
$('.refresh-notification').text('No Updates Available');
setTimeout(function () {
$('.refresh-notification').fadeOut();
}, 4000);
pollForUpdates();
}
}
}
});
}
$('body').on('click', '.update-notification', function () {
var update_ids = $(this).data('new-updates');
$.ajax({
url: frontend_ajax_object.ajaxurl,
type: 'POST',
data: {
action: 'get_live_updates',
update_ids: update_ids
},
success: function (results) {
$('.update-notification').fadeOut();
$('.live-updates-wrap').prepend(results);
$('html, body').animate({scrollTop: $('.live-updates-wrap').offset().top - 50}, 'slow');
$('.update-new').slideDown();
$('.update-new').animate({opacity: 1}, 'slow');
document.title = $('.live-updates-wrap').data('page-title')
$('.update-new').each(function () {
if ($(this).css('background-color') != $('.sno-story-page').css('background-color')) $(this).addClass('update-add-padding')
})
// restart polling
pollingIntervalID = setInterval(function () {
checkForUpdates()
}, 120000);
// restart timeout check
stopPollingID = setTimeout(function () {
clearInterval(pollingIntervalID);
showRefreshButton()
}, 3600000);
// animation for new updates
setTimeout(function () {
$('.update-new').css({borderColor: 'rgba(255, 0, 0, 0)'})
$('.update-new').css({borderColor: 'rgba(255, 0, 0, 0)'})
setTimeout(function () {
$('.live-update-wrap.update-new').toggleClass('update-new update-rendered')
}, 1000);
}, 4000);
}
});
});
function showRefreshButton() {
$('.refresh-notification').fadeIn();
}
$('body').on('click', '.refresh-notification', function () {
checkForUpdates();
})
});
// jQuery(document).ready(function ($) {
// $('nav').find('li.menu-item-has-children').each(function() {
// $(this).find('li').attr('tabindex', '0')
// })
// });
jQuery(document).ready(function ($) {
$('body').on('click', '.carousel-widget img', function () {
var href = $(this).closest('.carousel-widget-slide').find('a').attr('href');
if (href) {
window.location.href = href;
}
})
$('body').on('click', '.emailshare img', function () {
var href = $(this).closest('.emailshare').find('a').attr('href');
if (href) {
window.location.href = href;
}
})
});
// for new story templates added 04/2023
jQuery(document).ready(function ($) {
// checking to see if an image is both a featured image and inserted into the post
// if it's both, hide the featured image
// written to work with both legacy and new templates
var featuredImageID = $('.photowrap a.modal-photo').data('photo-id')
if (featuredImageID != undefined) {
$('.sno-story-body-content img:not(.sno-story-body-media img), span.storycontent img:not(.permalinkphotobox img)').each(function () {
var classes = $(this).attr('class')
if (classes != undefined) classes = classes.split(' ');
$.each(classes, function (i, value) {
if (value.indexOf("wp-image-") >= 0) {
value = value.replace('wp-image-', '')
if (value == featuredImageID) {
$('.sno-story-body-media, .permalinkphotobox').hide()
var story_id = $('.photowrap a.modal-photo').data('story-id')
$.ajax({
url: frontend_ajax_object.ajaxurl,
type: 'POST',
data: {
action: 'hidefeaturedimage',
story: story_id,
photo: featuredImageID,
},
success: function (results) {
}
})
}
}
});
})
}
// activate print button for keyboard printing shortcuts
$('body').on('keydown', function (event) {
var key = event.keyCode || event.charCode || 0;
if (key == 80 && event.metaKey == true) {
if (!$('.sno-story-wrap').length) return;
if ($('body').hasClass('print-override-deactivate')) return;
event.preventDefault();
var url = window.location.href
if (url.indexOf('?') == -1) {
url += '?print=true'
} else {
url += '&print=true'
}
window.location = url
}
$('body').on('keydown', function (e) {
if (e.ctrlKey && e.keyCode == 80) {
if (!$('.sno-story-wrap').length) return;
if ($('body').hasClass('print-override-deactivate')) return;
event.preventDefault();
var url = window.location.href
if (url.indexOf('?') == -1) {
url += '?print=true'
} else {
url += '&print=true'
}
window.location = url
}
});
});
window.addEventListener('beforeprint', function (e) {
if (!$('.sno-story-wrap').length) return;
if ($('body').hasClass('print-override-deactivate')) return;
e.preventDefault
var url = window.location.href
if (url.indexOf('?') == -1) {
url += '?print=true'
} else {
url += '&print=true'
}
window.location = url
});
$('.sno-story-body-content figure.wp-caption').each(function (i, el) {
$(el).css('max-width', $(el).css('width'))
$(el).css('width', 'auto')
});
// full-size photos on immersive templates -- add parallax effect
$('.add-parallax img.size-full').each(function () {
if ($(this).attr('width') >= $(window).width()) $(this).addClass('image-parallax');
})
// for infobox accordions
$('body').on('click', '.infobox-segment-title-accordion', function () {
if ($(this).closest('.infobox-segment').find('.infobox-segment-body').is(':visible')) {
$(this).closest('.infobox-segment').find('.infobox-segment-body-wrap').slideUp();
} else {
$(this).closest('.sno-infobox').find('.infobox-segment-body-wrap').slideUp();
$(this).closest('.infobox-segment').find('.infobox-segment-body-wrap').slideDown();
$(this).closest('.sno-infobox').find('.infobox-toggle').removeClass('fa-minus').addClass('fa-plus');
}
$(this).closest('.infobox-segment').find('.infobox-toggle').toggleClass('fa-minus fa-plus');
});
// for related stories carousel on story pages
$('.related-carousel-list').each(function () {
$(this).flexslider({
animation: "slide",
animationLoop: true,
controlNav: false,
customDirectionNav: $(".rcl-nav .custom-navigation span"),
slideshow: false,
itemMargin: 10,
touch: true,
itemWidth: 375,
minItems: 1,
move: 1,
maxItems: 5
});
});
var TB_CurrentScroll = 0;
var TB_NextScroll = 0;
var isChanging = false
$(window).scroll(function (e) {
TB_CurrentScroll = TB_NextScroll;
TB_NextScroll = $(this).scrollTop();
if (TB_NextScroll < TB_CurrentScroll && $(document).scrollTop() > 300) { // scrolling up on the page causes it to display
if ($('.sno-story-related-content-carousel').is(":hidden")) {
$('.sno-story-related-content-carousel').show();
$('.sno-story-related-content-carousel').stop().animate({bottom: '0'}, {duration: 300, queue: false});
}
} else if ((TB_NextScroll > TB_CurrentScroll && $(document).scrollTop() > 300) || $(document).scrollTop() < 10 && isChanging == false) { // scrolling down on the page causes it to hide
isChanging = true;
$('.sno-story-related-content-carousel').stop().animate({
bottom: '-120px'
}, 200, function () {
$('.sno-story-related-content-carousel').hide();
isChanging = false;
});
}
});
if ($('.related-bottom-drawer').length) {
var window_position = $(window).scrollTop();
var window_height = $(window).height();
var footerTop = $('.footer').offset().top - window_height;
$(window).scroll(function () {
var scroll = $(window).scrollTop();
if ($('.sno-slideshow-segment').length) {
const lastSegment = $('.sno-slideshow-segment').last().offset().top;
if (scroll > lastSegment && !$('.bottom-drawer-header').is(':visible') && footerTop > scroll) {
$('.bottom-drawer-header').slideDown();
}
if ((scroll < lastSegment && $('.bottom-drawer-header').is(':visible')) || footerTop < scroll) {
$('.bottom-drawer-header').slideUp();
$('.related-term-container').slideUp();
$('.bottom-drawer-background').removeClass('bottom-drawer-background-active');
$('.related-bottom-drawer').removeClass('hide-shadow');
$('.bds-arrows').fadeOut();
}
}
if (!$('.sno-slideshow-segment').length) {
if (scroll < 200) {
$('.bottom-drawer-header').slideUp();
$('.related-term-container').slideUp();
$('.bottom-drawer-background').removeClass('bottom-drawer-background-active');
$('.related-bottom-drawer').removeClass('hide-shadow');
$('.bds-arrows').fadeOut();
} else if (scroll > (window_height / 2) && !$('.bottom-drawer-header').is(':visible') && footerTop > scroll) {
$('.bottom-drawer-header').slideDown();
}
}
// if( !$('.sno-slideshow-segment').length && footerTop < scroll ) {
// $('.bottom-drawer-header').slideUp();
// $('.related-term-container').slideUp();
// $('.bottom-drawer-background').removeClass('bottom-drawer-background-active');
// $('.related-bottom-drawer').removeClass('hide-shadow');
// $('.bds-arrows').fadeOut();
// }
window_position = scroll;
});
}
// end functions for related stories in bottom drawer on story page
if ($('img.image-parallax').length > 0) {
var images = document.querySelectorAll('img.image-parallax');
new simpleParallax(images);
}
// for fade image effect for story segment slideshows
var slideshow_photos = $('.sno-story-photo-fade')
slideshow_photos.each(function (i, el) {
var el = $(el)
if (el.is(':visible')) {
el.addClass('sno-story-photo-fade-in')
}
})
$(window).scroll(function (event) {
$('.sno-story-photo-fade').each(function (i, el) {
const rect = el.getBoundingClientRect();
var el = $(el)
if (rect.bottom < $(window).height() / 2) {
el.removeClass('sno-story-photo-fade-in');
} else if ($(window).height() - rect.top > $(window).height() / 4) {
el.addClass('sno-story-photo-fade-in')
}
})
})
$('.segment-split-text').each(function () {
if ($(this).find('.segment-split-text-inner').height() + 100 < $(this).height()) $(this).css('display', 'flex');
})
$('body').on('click', '.minimize-overlay', function () {
$(this).closest('.segment-overlay').addClass('segment-overlay-hidden');
$('body').on('mouseleave', '.segment-overlay', function () {
$('body').on('mouseenter', '.segment-overlay', function () {
$(this).removeClass('segment-overlay-hidden');
});
});
})
center_video()
function center_video() {
$('.sno-slideshow-segment .segment-video-immersive').each(function () {
$(this).css('margin-top', ($(window).height() - $(this).height()) / 2)
});
}
$(window).on('resize', function () {
center_video()
});
// up and down arrows for story segment slideshows
$('body').on('click', '.down-arrow', function () {
$('.segment-split-text, .segment-overlay').animate({scrollTop: 0}, 1000);
$('.segment-overlay').removeClass('segment-overlay-hidden');
$('.sno-slideshow-segment').each(function (i, el) {
const rect = el.getBoundingClientRect();
if (rect.top < 20) return
const scrollTop = $('html').scrollTop();
$("html, body").animate({scrollTop: scrollTop + rect.top}, 666);
return false;
})
})
$('body').on('click', '.up-arrow', function () {
$('.segment-split-text, .segment-overlay').animate({scrollTop: 0}, 1000);
$('.segment-overlay').removeClass('segment-overlay-hidden');
if (!$('.sno-header-wrap:visible').length) show_header();
$($('.sno-slideshow-segment').get().reverse()).each(function (i, el) {
const rect = el.getBoundingClientRect();
const scrollTop = $('html').scrollTop();
if (rect.top < 0) {
$("html, body").animate({scrollTop: scrollTop + rect.top}, 666);
return false;
}
if (scrollTop < $(window).height() + 100) {
$("html, body").animate({scrollTop: 0}, 666);
return false;
}
})
})
if ($('#wrap').data('post-template') == 'fulltop' || $('#wrap').data('post-template') == 'split') {
var position = $(window).scrollTop();
const ss_height = $("div.sno-format-slideshow").height();
$(window).scroll(function () {
var scroll = $(window).scrollTop();
if (scroll < position && !$('.sno-header-wrap:visible').length) {
show_header();
}
if (scroll > ($(window).height() / 2) && !$('.up-arrow:visible').length) {
$('.up-arrow').fadeIn();
}
if (scroll < ($(window).height() / 2) && $('.up-arrow:visible').length) {
$('.up-arrow').fadeOut();
}
if (scroll > ss_height - ($(window).height() / 2) && $('.down-arrow:visible').length) {
$('.down-arrow').fadeOut();
}
if (scroll < ss_height - ($(window).height() / 2) && !$('.down-arrow:visible').length) {
$('.down-arrow').show();
}
position = scroll;
});
}
;
function show_header() {
var desktop_breakpoint = $('#wrap').data('desktop-breakpoint');
var tablet_breakpoint = $('#wrap').data('tablet-breakpoint');
var mobile_breakpoint = $('#wrap').data('mobile-breakpoint');
var site_width = $(window).width();
if (site_width < mobile_breakpoint) {
var header_target = '.sno-header-wrap-mobile';
} else if (site_width < tablet_breakpoint) {
var header_target = '.sno-header-wrap-tablet';
} else {
var header_target = '.sno-header-wrap-desktop';
}
if ($(header_target).find('.sno-header-row-stick').length && !$('.sno-slideshow-segment').length) {
var fixed_element_adjustment = $('#wpadminbar').length && $('#wpadminbar').is(':visible') ? $('#wpadminbar').outerHeight() : 0
var stick_height = 0
$(header_target).scrollToFixed({
marginTop: fixed_element_adjustment + stick_height,
spacerClass: 'topheaderspacer',
zIndex: 2000,
})
stick_height += $(this).height()
$(header_target).fadeIn();
} else {
$(header_target).show();
}
}
// fixing text in story that didn't get wrapped with p tags
if ($('#sno-story-body-content').length) {
var elems = document.getElementById('sno-story-body-content').childNodes;
for (var i = 0; i < elems.length; i++) {
var el = elems[i];
if (el.nodeType === 3 && el.nodeValue.trim().length) {
const newNode = document.createElement('p');
const textNode = document.createTextNode(el.nodeValue);
newNode.appendChild(textNode);
$(elems[i + 1]).after(newNode)
$(elems[i]).remove();
}
}
}
// detect if sno ad collides with any elements within the post story
var story_p = $('.sno-story-body-content > p')
var story_divs = $('.sno-story-body-content > div, .sno-story-body-content > figure');
if (story_p.length > 1) {
$.each(story_p, function () {
$.each(story_divs, function (index, value) {
var sno_ad = $('.sno-ad');
if (sno_ad.length < 1) return;
if ($(value).hasClass('sno-ad')) return;
if (collision($(sno_ad), $(value)) == true) {
var next_ps = sno_ad.nextAll('p');
$.each(next_ps, function (index, value) {
if ($(this).text().trim().length) {
sno_ad.insertAfter($(this));
return false;
}
})
return false;
}
});
})
}
// detect if a slideshow or infobox inserted into the story is colliding with the featured image
var story_featured = $('.sno-story-body-content .sno-story-body-media');
var story_slideshow = $('.sno-story-body-content .slideshowwrap');
if (story_slideshow.length && story_featured.length) {
$.each(story_slideshow, function (index, value) {
if (collision($(story_featured), $(value)) == true) {
story_featured.hide();
}
})
}
// detect if a slideshow or infobox inserted into the story is colliding with the featured image
var story_featured = $('.sno-story-body-content .sno-story-body-media');
var story_infobox = $('.sno-story-body-content .sno-infobox');
if (story_infobox.length && story_featured.length) {
$.each(story_infobox, function (index, value) {
if (collision($(story_featured), $(value)) == true) {
story_featured.hide();
}
})
}
function collision($div1, $div2) {
var x1 = $div1.offset().left;
var y1 = $div1.offset().top;
var h1 = $div1.outerHeight(true);
var w1 = $div1.outerWidth(true);
var b1 = y1 + h1;
var r1 = x1 + w1;
var x2 = $div2.offset().left;
var y2 = $div2.offset().top;
var h2 = $div2.outerHeight(true);
var w2 = $div2.outerWidth(true);
var b2 = y2 + h2;
var r2 = x2 + w2;
if (b1 < y2 || y1 > b2 || r1 < x2 || x1 > r2) return false;
return true;
}
$('.sno-story-wrap').find('.slideshowwrap').each(function () {
var image_ratio = $(this).data('ratio')
var width = $(this).width();
var height = $(this).height();
var photo_width = $(this).find('img').data('width');
var photo_height = $(this).find('img').data('height');
if (photo_height < height && photo_width < width) return;
if (height != 0 && width != 0) {
var area_ratio = (width / height).toFixed(2)
if (Math.abs(image_ratio - area_ratio) < 0.25) $(this).find('img').css({'object-fit': 'cover'})
}
})
$('body').on('click', '.byline-photo', function () {
var link = $(this).data('link');
if (link) {
window.location = link
}
});
$('body').on('click', '.related-story.preview-card, .contributor-area', function () {
var link = $(this).find('a').attr('href')
if (link) {
window.location = link
}
})
$('.sno-story-related-content').find('img.scale').each(function () {
var image_ratio = $(this).data('ratio')
var width = $(this).closest('.related-story-photo').width();
if ($(this).closest('.column-count-1').length) {
var height = $(this).closest('.related-story-photo-area').height();
} else {
var height = $(this).closest('.related-story-photo-area').height() - $(this).closest('.related-story-photo-area').find('.related-story-headline').height();
}
if (height != 0 && width != 0) {
var area_ratio = (width / height).toFixed(2)
if (Math.abs(image_ratio - area_ratio) < 0.25) $(this).css({'object-fit': 'cover'})
}
})
// SNO Story Element - Story Collection
$('.sno-collection').find('img.scale').each(function () {
var image_ratio = $(this).data('ratio')
var shape = $(this).data('shape');
var width = $(this).closest('div').width();
if (shape === undefined) {
var height = $(this).closest('div').height();
} else {
var height = (shape == 'Horizontal') ? width * .66 : width;
}
if (height != 0 && width != 0) {
var area_ratio = (width / height).toFixed(2)
if (Math.abs(image_ratio - area_ratio) < 0.25) $(this).css({'object-fit': 'cover'})
}
})
$('body').on('mouseenter', '.collection-grid.preview-card', function () {
$(this).find('.collection-grid-overlay').css('opacity', 1);
});
$('body').on('mouseleave', '.collection-grid.preview-card', function () {
$(this).find('.collection-grid-overlay').css('opacity', 0);
});
// opening up collection
$('body').on('click', '.collection-tile.preview-card, .collection-grid.preview-card, a.collection-title', function () {
const link_type = $(this).closest('.collection-area').data('link-type');
$('.modal-story-collection').fadeIn();
if (link_type == 'story') {
var link = $(this).find('a').attr('href')
if (link === undefined) link = $(this).attr('href');
if (link) {
window.location = link
}
return false;
} else {
var parent_id = $(this).closest('.snopostid').data('post-id');
if (parent_id === undefined) $parent_id = 0;
var postid = $(this).data('postid');
if (postid === undefined) postid = $(this).closest('.collection-grid-item-wrap').data('postid');
var collection = $(this).closest('.collection-area').data('collection-ids')
var collection_title = $(this).closest('.collection-area').data('collection-title')
$.ajax({
url: frontend_ajax_object.ajaxurl,
type: 'POST',
data: {
action: 'getcollection',
story: postid,
parent_id: parent_id,
collection: collection,
collection_title: collection_title,
},
success: function (results) {
$('.remodal-collection-inner-container').replaceWith(results)
var scrollDistance = $(document).scrollTop();
$('#wrap').addClass('lockposition')
$('#wrap').data('scrolled', scrollDistance)
$('.flexslider').animate({opacity: 1}, {duration: 'slow'})
$('.flex-container').css('background', 'unset')
$('.modal-story-collection').find('#collection-thumbnails').flexslider({
animation: 'slide',
controlNav: false,
customDirectionNav: $('.modal-story-collection').find('#sfi-thumbnav span'),
animationLoop: true,
slideshow: false,
itemWidth: 300,
itemMargin: 20,
touch: true,
})
$('.modal-story-collection').find('.infobox-carousel').each(function () {
var infobox_id = $(this).closest('.sno-infobox').data('id');
$(this).flexslider({
animation: "slide",
animationLoop: false,
controlNav: true,
customDirectionNav: $('.modal-story-collection').find('.sno-infobox-' + infobox_id + ' .custom-navigation span'),
slideshow: false,
itemMargin: 0,
touch: true,
itemWidth: 800,
minItems: 1,
move: 1,
maxItems: 1
});
});
if (typeof initialize_countdown === "function") initialize_countdown();
if (typeof initialize_polls === "function") initialize_polls();
if (typeof initialize_quiz === "function") initialize_quiz();
if (typeof initialize_test === "function") initialize_test();
if (typeof initialize_sno_infographic === "function") initialize_sno_infographic();
// if( typeof Ot === "function" ) Ot();
initialize_flipbooks();
var thumbAreaWidth = $('.modal-story-collection').find('#collection-thumbnails').width()
var thumbRowWidth = 320 * $('.modal-story-collection').find('#collection-thumbnails li').length
if (thumbRowWidth < thumbAreaWidth) {
$('.modal-story-collection').find('.sfi-thumbnails').width(thumbRowWidth)
}
setTimeout(function () {
check_thumbnail_nav(postid)
}, 333)
},
})
return false;
}
})
function check_thumbnail_nav(postid) {
if ($('.sfi-thumb[data-postid="' + postid + '"]').offset().left < 0) {
$('.sfi-thumb-navigation-area .flex-prev').trigger('click')
} else if ($('.sfi-thumb[data-postid="' + postid + '"]').offset().left + $('.sfi-thumb[data-postid="' + postid + '"]').width() > $(document).width()) {
$('.sfi-thumb-navigation-area .flex-next').trigger('click')
}
}
// selecting a new story in an open collection
$('body').on('click', '#collection-thumbnails .sfi-thumb', function () {
postid = $(this).data('postid')
getCollectionStory(postid)
})
$('body').on('click', '.modal-story-collection .slideshow_left, .modal-story-collection .slideshow_right', function () {
const current = $('.collection-viewer-body').data('visible-story')
var collection = $('.sfi-thumb-navigation-area li.sfi-thumb').map(function () {
return $(this).data('postid');
}).get();
if ($(this).hasClass('slideshow_right')) collection = collection.reverse()
const first = collection[0];
const last = collection[collection.length - 1];
var prev = 0;
var postid = 0;
$.each(collection, function (index, value) {
if (value == first && value == current) {
postid = last;
} else if (value == current) {
postid = prev;
}
prev = value;
});
getCollectionStory(postid)
check_thumbnail_nav(postid)
// scroll the thumbnail navigation if newly clicked story is offscreen
});
function getCollectionStory(postid) {
$('.collection-viewer-transition').addClass('collection-viewer-transition-active');
$('.sfi-thumb').removeClass('active-story');
$('.sfi-thumb[data-postid="' + postid + '"]').addClass('active-story');
$.ajax({
url: frontend_ajax_object.ajaxurl,
type: 'POST',
data: {
action: 'getcollectionstory',
story: postid,
},
success: function (results) {
$('.collection-viewer-body').replaceWith(results)
$('.collection-viewer-wrap').scrollTop(0);
$('.collection-viewer-transition').removeClass('collection-viewer-transition-active');
$('.modal-story-collection').find('.infobox-carousel').each(function () {
var infobox_id = $(this).closest('.sno-infobox').data('id');
$(this).flexslider({
animation: "slide",
animationLoop: false,
controlNav: true,
customDirectionNav: $('.modal-story-collection').find('.sno-infobox-' + infobox_id + ' .custom-navigation span'),
slideshow: false,
itemMargin: 0,
touch: true,
itemWidth: 800,
minItems: 1,
move: 1,
maxItems: 1
});
$(this).css('opacity', '1');
});
if (typeof initialize_countdown === "function") initialize_countdown();
if (typeof initialize_polls === "function") initialize_polls();
if (typeof initialize_quiz === "function") initialize_quiz();
if (typeof initialize_test === "function") initialize_test();
if (typeof initialize_sno_infographic === "function") initialize_sno_infographic();
// if( typeof Ot === "function" ) Ot();
initialize_flipbooks();
},
})
}
// closing collections
$('body').on('click', '.modal-story-collection .sfi-return-to-story, .modal-story-collection .sno-overlay-close', function () {
$('#wrap').removeClass('lockposition')
$(document).scrollTop($('#wrap').data('scrolled'));
$(this).closest('.modal-story-collection').fadeOut();
setTimeout(function () {
$('.collection-viewer-body').fadeOut();
$('#collection-thumbnails').fadeOut();
}, 1000)
});
// function to initialize any flipbooks found in collection stories
function initialize_flipbooks() {
canvases = jQuery("body").find(".sno-pdf-flipbook-canvas")
canvases.each(function () {
const flipbook = jQuery(this).find("#sno-flipbook")
const width = flipbook.data("width")
const aspect_ratio = flipbook.data("aspect-ratio")
const arrowLeft = jQuery(this).find(".sno-flipbook-arrow-left")
const arrowRight = jQuery(this).find(".sno-flipbook-arrow-right")
flipbook.turn({
width: width - 62,
height: (width - 62) / aspect_ratio,
elevation: 50,
gradients: false,
autoCenter: true,
})
flipbook.bind("turning", function (_event, page) {
const atFirstPage = page == 1
const atLastPage = page == jQuery(this).turn("pages")
if (atFirstPage) {
arrowLeft.addClass("disabled")
} else {
arrowLeft.removeClass("disabled")
}
if (atLastPage) {
arrowRight.addClass("disabled")
} else {
arrowRight.removeClass("disabled")
}
})
flipbook.addClass("animated")
arrowLeft.click(function () {
flipbook.turn("previous")
})
arrowRight.click(function () {
flipbook.turn("next")
})
window.addEventListener("keydown", (ev) => {
if (ev.key == "ArrowLeft") flipbook.turn("previous")
if (ev.key == "ArrowRight") flipbook.turn("next")
})
})
}
// social icons hover effects
$('.sno-row-icon').on('mouseenter', function () {
const hover_style = $(this).closest('.sno-row-icons').data('hover-style');
const mono = $('.snodo-template-group:visible').find('.icons-mono-color input').val();
switch (hover_style) {
case 'Full Color':
$(this).addClass('hover-full-color');
break;
case 'Full Color Inverse':
$(this).addClass('hover-full-color-inverse');
break;
case 'Monochromatic':
$(this).addClass('monochromatic');
break;
case 'Monochromatic Inverse':
$(this).addClass('monochromatic-inverse');
break;
}
});
$('body').on('mouseleave', '.sno-row-icon', function () {
$(this).removeClass('hover-full-color hover-full-color-inverse monochromatic monochromatic-inverse');
});
if ($('#wrap').data('post-template') == 'fulltop' || $('#wrap').data('post-template') == 'split') {
$('.sno-story-media-area-fade').fadeOut('slow');
$('.sno-row-icons').hide();
$(window).scroll(function () {
if ($(this).scrollTop() > $(window).height() / 2) {
$('.sno-row-icons').fadeIn();
} else {
$('.sno-row-icons').fadeOut();
}
});
var wp_adminbar = ($('#wpadminbar').length > 0 && $('#wpadminbar').is(':visible')) ? $('#wpadminbar').height() : 0;
$('#jump-arrow').click(function () {
var header_height = ($('.sno-header-wrap:visible').length) ? $('.sno-header-wrap:visible').height() : 0;
if ($('.sno-story-fulltop-container').length) {
$('html, body').animate({scrollTop: $('.sno-story-fulltop-container').offset().top - wp_adminbar - header_height}, 500)
}
if ($('.sno-story-split-header-area').length) {
$('html, body').animate({scrollTop: $('.sno-story-split-header-area').offset().top - wp_adminbar - header_height}, 500)
}
$('#jump-arrow').fadeOut()
return false
})
jQuery(window).scroll(function () {
if (jQuery(this).scrollTop() > jQuery(window).height()) {
jQuery('#jump-arrow').fadeOut()
} else {
jQuery('#jump-arrow').fadeIn()
}
});
$('.sno-story-split-image-area').on('mouseenter', function () {
$(this).find('.fullphoto-overlay').fadeIn();
});
$('.sno-story-split-image-area').on('mouseleave', function () {
$(this).find('.fullphoto-overlay').fadeOut();
});
} else {
$('.sno-row-icons').fadeIn();
}
});
// carousel adjustment for mobile
jQuery(document).ready(function ($) {
if ($(window).width() < 600) {
$('.carousel-widget-slide-beside').width($(window).width() - 20)
}
})
// snoAds integration
jQuery(document).ready(function ($) {
if ($('.snods_footer').length) {
var spot_id = $('.snods_footer').first().data('spot_id')
var fill = $('.snods_footer').first().data('fill')
var sno_client_id = $('.snods_footer').first().data('sno_client_id')
var url = 'https://snoads.com/api/v1/adspot/' + spot_id + '/serve'
jQuery.get(url, '', function (response) {
if (response && response.link != null && response.image != null) {
$('.footerboardwrap .footerimage')
.filter(':visible')
.html(
''
)
} else {
let rand_num = Math.floor(Math.random() * 2 + 1)
$('.footerboardwrap .footerimage')
.filter(':visible')
.html(
`
`
)
}
}).fail(() => {
if (fill) {
$('.footerboardwrap .footerimage')
.filter(':visible')
.html('
')
} else {
let rand_num = Math.floor(Math.random() * 2 + 1)
$('.footerboardwrap .footerimage')
.filter(':visible')
.html(
`
`
)
}
})
$('.footerimage').on('click', '.sno-spot', function () {
let ad_id = $(this).data('spot-id')
var url = 'https://snoads.com/api/v1/ad/' + ad_id + '/click'
jQuery.post(url, '', function (response) {
})
})
$('.footerimage').on('click', '.sno-fill', function () {
const url = `https://snoads.com/marketplace?site=${sno_client_id}`
window.open(url, '_blank')
})
}
})
jQuery(document).ready(function ($) {
if ($('.footer .snoads-unplaced').length) {
if ($('.footer .snoads-unplaced').closest('.sno-designer-area-row').next('.sno-designer-area-row').hasClass('sno-designer-row-fullscreen')) {
$('.footer .snoads-unplaced').addClass('sno-designer-row-fullscreen');
}
}
if ($('.sno-header-wrap .snoads-unplaced').length) {
if ($('.sno-header-wrap .snoads-unplaced').closest('.sno-designer-area-row').next('.sno-designer-area-row').hasClass('sno-designer-row-fullscreen')) {
const bg_color = $('.sno-header-wrap .snoads-unplaced').closest('.sno-designer-area-row').next('.sno-designer-area-row').css("background-color")
$('.sno-header-wrap .snoads-unplaced').closest('.sno-designer-area-row').css({'background-color': bg_color + '!important'})
}
}
});
jQuery(document).ready(function ($) {
if ($('.snods_sidebar').length) {
var spot_id = $('.snods_sidebar').first().data('spot_id')
var fill = $('.snods_sidebar').first().data('fill')
var sno_ads_id = $('.snods_sidebar').first().data('sno_client_id')
var url = 'https://snoads.com/api/v1/adspot/' + spot_id + '/serve'
jQuery.get(url, '', function (response) {
if (response && response.link != null && response.image != null) {
$('.sidebarimage')
.filter(':visible')
.html(
'
'
)
} else {
let rand_num = Math.floor(Math.random() * 2 + 1)
$('.sidebarimage')
.filter(':visible')
.html(
`
`
)
}
}).fail(() => {
if (fill) {
$('.sidebarimage')
.filter(':visible')
.html('
')
} else {
let rand_num = Math.floor(Math.random() * 2 + 1)
$('.sidebarimage')
.filter(':visible')
.html(
`
`
)
}
})
$('.sidebarimage').on('click', '.sno-spot', function () {
let ad_id = $(this).data('spot-id')
var url = 'https://snoads.com/api/v1/ad/' + ad_id + '/click'
jQuery.post(url, '', function (response) {
})
})
$('.sidebarimage').on('click', '.sno-fill', function () {
const url = `https://snoads.com/marketplace?site=${sno_ads_id}`
window.open(url, '_blank')
})
}
})
jQuery(document).ready(function ($) {
if ($('.snods_leaderboard').length) {
var spot_id = $('.snods_leaderboard').first().data('spot_id')
var fill = $('.snods_leaderboard').first().data('fill')
var sno_ads_id = $('.snods_leaderboard').first().data('sno_client_id')
var url = 'https://snoads.com/api/v1/adspot/' + spot_id + '/serve'
jQuery.get(url, '', function (response) {
if (response && response.link != null && response.image != null) {
$('.leaderboardimage')
.filter(':visible')
.html(
'
'
)
} else {
let rand_num = Math.floor(Math.random() * 2 + 1)
$('.leaderboardimage')
.filter(':visible')
.html(
`
`
)
}
}).fail(() => {
if (fill) {
$('.leaderboardimage')
.filter(':visible')
.html('
')
} else {
let rand_num = Math.floor(Math.random() * 2 + 1)
$('.leaderboardimage')
.filter(':visible')
.html(
`
`
)
}
})
$('.leaderboardimage').on('click', '.sno-spot', function () {
let ad_id = $(this).data('spot-id')
var url = 'https://snoads.com/api/v1/ad/' + ad_id + '/click'
jQuery.post(url, '', function (response) {
})
})
$('.leaderboardimage').on('click', '.sno-fill', function () {
// url = 'https://snoads.com/marketplace/' + sno_ads_id
const url = `https://snoads.com/marketplace?site=${sno_ads_id}`
window.open(url, '_blank')
})
}
})
// scrollToFixed for header elements
jQuery(function ($) {
var fixed_element_adjustment = $('#wpadminbar').length && $('#wpadminbar').is(':visible') ? $('#wpadminbar').outerHeight() : 0
var stick_height = 0
$('.sno-header-row-stick:visible').each(function () {
$(this).scrollToFixed({
marginTop: fixed_element_adjustment + stick_height,
spacerClass: 'topheaderspacer',
zIndex: 2000,
})
stick_height += $(this).height()
})
var bottom_stick_height = 0
$($('.footer .sno-footer-row-stick:visible').get().reverse()).each(function () {
var row = this
$(this).scrollToFixed({
bottom: bottom_stick_height,
limit: $(row).offset().top,
})
bottom_stick_height += $(this).height()
})
})
// If a draft is being displayed via query string, append all hyperlinks on the page with the query string to keep the user in the draft as they click through the site
jQuery(function ($) {
$(document).ready(function () {
if ($('.sno-viewing-draft-notice').length) {
$('a').each(function () {
if ($(this).hasClass('draft-live')) return
if ($(this).closest('#wpadminbar').length) return
if ($(this).attr('href').indexOf($('.sno-viewing-draft-notice').data('url')) > 0) {
var joiner = ($(this).attr('href').includes('?')) ? '&' : '?';
$(this).attr('href', $(this).attr('href') + joiner + 'draft=' + $('.sno-viewing-draft-notice').data('draft-id'))
}
})
} else if (window.location.href.indexOf("draft=live") > -1) {
$('a').each(function () {
if ($(this).closest('#wpadminbar').length) return
var joiner = ($(this).attr('href').includes('?')) ? '&' : '?';
$(this).attr('href', $(this).attr('href') + joiner + 'draft=live')
})
}
})
})
jQuery(function ($) {
$('body').on('keydown', '.back-to-list', function (e) {
if (!$('.return-focus-to-item').length) return;
e.preventDefault();
$('.return-focus-to-item').focus();
$('.return-focus-to-item').removeClass('return-focus-to-item')
$('ul.menu-with-teasers a').attr('tabindex', '0')
});
$('ul.menu-with-teasers').on('keyup', function (event) {
if (event.key === 'Tab' || event.keyCode === 9) {
if ($(event.target).hasClass('sf-with-ul')) return;
var visibleCards = $(event.target).closest('ul').find('.menu-ta-wrap .sno-menu-card:visible');
if (!visibleCards.length) return;
var lastVisibleCard = visibleCards.last();
var lastLink = lastVisibleCard.find('a');
$(lastLink).addClass('last-menu-teaser-headline');
if ($(event.target).hasClass('last-menu-teaser-headline')) {
$(event.target).addClass('back-to-list')
$('.return-focus-to-item').attr('tabindex', '0')
} else {
var allLinks = $(event.target).closest('li.menu-item-has-children').find('ul li > a');
var unfocusedLinks = allLinks.filter(function () {
return this !== document.activeElement;
});
var tabindex = '0';
var nextlink = false;
allLinks.each(function (i, link) {
$(link).attr('tabindex', tabindex)
if (nextlink == true) {
$(link).addClass('return-focus-to-item');
nextlink = false;
}
if (link == document.activeElement) {
tabindex = '-1';
nextlink = true;
}
})
}
}
});
// show teasers for selected menus on hover of category or via focus from tabbing
$('body').on('focus', 'ul.menu-with-teasers .menu-item-object-category a, ul.menu-with-teasers .menu-item-object-page a', function () {
load_menu_teasers($(this).closest('li'));
})
$('body').on('mouseenter', 'ul.menu-with-teasers .menu-item-object-category, ul.menu-with-teasers .menu-item-object-page', function () {
load_menu_teasers($(this));
})
function load_menu_teasers(triggerDiv) {
var menu_object_id = ''
$.each($(triggerDiv).attr('class').split(' '), function (index, value) {
if (/\d/.test(value) == true) {
menu_object_id = value.replace('menu-item-', '')
return
}
})
if (menu_object_id == '') return
$('.menu-ta-inner').empty()
$('.menu-ta-inner').hide()
if ($(triggerDiv).find('.menu-ta-inner').length) {
$(triggerDiv)
.find('.menu-ta-inner')
.append(
$(triggerDiv)
.closest('.sno-designer-area-container')
.find('.sub-menu-teaser-display-' + menu_object_id)
.clone()
.hide()
)
} else {
$(triggerDiv)
.siblings('li')
.last()
.find('.menu-ta-inner')
.append(
$(triggerDiv)
.closest('.sno-designer-area-container')
.find('.sub-menu-teaser-display-' + menu_object_id)
.clone()
.hide()
)
}
$('.menu-ta-inner').fadeIn('slow')
$('.sub-menu .sub-menu-teaser-display-' + menu_object_id).fadeIn()
$(triggerDiv)
.find('img.scale')
.each(function () {
var image_ratio = $(triggerDiv).data('ratio')
var width = 220 // this is an approximation
var height = $(triggerDiv).closest('.sno-story-card-photo-wrap').height()
if (height != 0 && width != 0) {
var area_ratio = (height / width).toFixed(2)
if (Math.abs(image_ratio - area_ratio) < 0.25) $(triggerDiv).css({'object-fit': 'cover'})
}
})
}
// adjust menu markup for menus that have teasers enabled
function prepare_menus_with_teasers(menu) {
// special adjustments for the More menu item
$(menu)
.find('ul.menu-with-teasers')
.find('li.menu-more-item-top')
.find('ul.sub-menu')
.each(function () {
$(this).closest('li').removeClass('menu-item-has-children')
$(this).closest('li').find('a').removeClass('sf-with-ul')
$(this).remove()
})
// removing the ability for the More Menu to have category teasers display -- unless I can figure out how to have one of them display by default
/*
$(menu).find('ul.menu-with-teasers').find('ul.sno-hac-menu-more').each(function() {
$('