$(document).ready(function() {
$("html").addClass("js");
$('a[href*=#]').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var $target = $(this.hash);
$target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
if ($target.length) {
var targetOffset = $target.offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
return false;
}
}
});
if ($('#commentform').length) {
$("#commentform").validate({
rules: {
name: "required",
comment: "required",
email: {
required: true,
email: true,
}
},
errorElement: "div",
errorPlacement: function(error, element) {
error.insertBefore(element);
}
});
};
if ($('#pg-home').length) {
callout = $('.latest-feature-callout');
callout_height = callout.height();
header = callout.find('.r-feature-article-header');
header_height = header.height();
center_spacing = (callout_height - header_height) / 2;
header.css({
"margin-top": center_spacing
});
};
// mobile: toggle menu curtain
$('.header-new .open-menu').on('click.toggleMenu', function (e) {
e.preventDefault();
$('.header-new').find('.open-menu, .header-new__main-nav').toggleClass('open');
$('.header-new').find('.open-menu, .header-new__main-nav .header-new__main-nav-item:first-child').addClass('active')
// $('body').toggleClass('fixed');
});
// mobile: show submenu items
$('.header-new .header-new__main-nav-item >a').on('click', function (e) {
if( $(this).parent('.active').length != 0 ){
$('.header-new__main-nav-item').removeClass('active');
if( $(window).width() >= 480 ){
e.preventDefault();
}
return;
} else {
$('.header-new__main-nav-item').removeClass('active');
if( $(window).width() >= 480 ){
e.preventDefault();
$(this).parent('.header-new__main-nav-item').addClass('active');
}
}
})
// close menu on scroll
$(window).on('scroll.headerFixed', function(){
// active fixe header
if( $(window).scrollTop() > 95 ){
$('.header-new').not('.fixed').addClass('fixed')
} else if( $(window).scrollTop() == 0 ){
$('.header-new.fixed').removeClass('fixed')
}
});
// hide footer social media
$(window).on('touchstart.footerSocial', function(){
var checkPosition = setInterval(function () {
var documentHeight = $(document).height();
// give padding to hide before getting to the bottom
var bottomPosition = ( 200 + ($(window).scrollTop() + $(window).height()) );
if( documentHeight <= bottomPosition ){
$('.footer-new__fixed').addClass('hidden')
} else {
$('.footer-new__fixed.hidden').removeClass('hidden');
}
}, 100);
$(window).off('touchstart.footerSocial')
})
// hide menu on resize
$(window).on('resize.closeMenu', function () {
$('.header-new').find('.open-menu.open, .header-new__main-nav.open').removeClass('open');
$('.header-new__main-nav-item.active').removeClass('active');
// $('body').removeClass('fixed');
})
$('.popup-modal').magnificPopup({
items: {
src: '.header-new__mobile-search.modal',
type: 'inline'
}
});
$('.header-new__mobile-search-close').on('click.closePopup', function(){
$.magnificPopup.close()
})
});