jQuery(document).ready(function($) {
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
var w = Math.max(document.documentElement.clientWidth, window.innerWidth || 0);
var h = Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
$('.arrow').click(function(event) {
$( "html, body" ).animate({ scrollTop: $('.landing-hero').height() }, 2000);
});
$(".sparkle-box").sparkle({
color: "rainbow",
count: 150,
overlap: 20,
speed: 1,
minSize: 5,
maxSize: 10,
direction: "both"
});
$('.sparkle-box').trigger("start.sparkle");
setTimeout(function() {
$('.sparkle-box').trigger("stop.sparkle");
}, 15000);
$('.front-action--play').hover(function() {
$('.sparkle-box').trigger("start.sparkle");
}, function() {
$('.sparkle-box').trigger("stop.sparkle");
});
Modernizr.on( 'videoautoplay', function (hasAutoPlay) {
if (!hasAutoPlay) {
if ($('.hero--b-roll').length) {
$('.hero--b-roll').hide();
$('.video-control').hide();
$('.video-modal').css({
position: 'static',
width: 'auto',
height: 'auto',
opacity: '1'
});
$('button.action--play').hide();
}
}
});
$('#block-atlas-branding img').css( 'cursor', 'pointer' );
$('#block-atlas-branding img').click(function(event) {
if (window.location.hostname.indexOf('.dd') !== -1) {
window.location = window.location.protocol + "//" + window.location.hostname + ":8083";
} else {
window.location = window.location.protocol + "//" + window.location.hostname;
}
});
$('.para-container').first().children('p').first().addClass('first-para');
$('#flipQuote').click(function(event) {
$('.flip-container').toggleClass('hover');
});
$(document).keydown(function(event) {
if (event.which == 27) {
closeVideo();
$('.burger').removeClass('open');
$('body').removeClass('locked');
$('body').removeClass('nav-open');
$('.main-navigation').removeClass('show');
setTimeout(function() {
$('.main-navigation').removeClass('is-visible');
}, 500);
}
});
$(window).resize(function(event) {
positionDonorQuote();
videoModalFit();
});
function positionDonorQuote() {
$marginRight = (Math.max(document.documentElement.clientWidth, window.innerWidth || 0) - $('.container').width()) / 2;
if ($('.flip-container-container').length && $marginRight > 75) {
$('.flip-container-container').css('margin-right', $marginRight);
} else {
$('.flip-container-container').removeAttr('style');
}
}
function videoModalFit() {
$('.video-modal').css('max-width',($('.hero').height() + 100) * 1.8);
}
positionDonorQuote();
videoModalFit();
var waypoints = $('body').waypoint(function(direction) {
//console.log("headers!")
var $header = $('.header');
$header.toggleClass('smaller');
}, {
offset: '-111px'
});
$('.effect-goliath').click(function(event) {
window.location = $(this).find('a').attr('href');
});
$('.close-video').click(function(event) {
closeVideo();
});
function closeVideo() {
$('.curtain').removeClass('visible');
$('body').removeClass('locked');
}
$('.carousel-items').slick({
slide: '.carousel-item',
accessibility: true,
autoplay: true,
prevArrow: '',
nextArrow: '',
dots: true,
slidesToShow: 1,
centerMode: true,
centerPadding: "30px",
variableWidth: true
});
$('.infographic-carousel').slick({
slide: '.quick-fact-item',
accessibility: true,
autoplay: true,
prevArrow: '',
nextArrow: '',
dots: true,
slidesToShow: 1,
centerMode: true,
centerPadding: "30px",
variableWidth: true
})
function toggleNav() {
$('.burger').toggleClass('open');
$('body').toggleClass('locked');
$('body').toggleClass('nav-open');
$('.main-navigation').toggleClass('show');
setTimeout(function() {
$('.main-navigation').toggleClass('is-visible');
}, 500);
}
$('.burger-container').click(function () {
toggleNav();
// if ($('.main-navigation').hasClass('show')) {
// $('.wrapper p').text("Close");
// } else {
// $('.wrapper p').text("Menu")
// }
});
if ($('.hero--b-roll').find('iframe').length) {
var broll = $('.hero--b-roll').find('iframe')[0];
if (broll) {
var bRollPlayer = new Vimeo.Player(broll);
bRollPlayer.setLoop(true);
}
}
if ($('.video-modal').find('iframe').length) {
var iframe = $('.video-modal').find('iframe')[0];
if (iframe) {
var player = new Vimeo.Player(iframe);
$('.video-modal').hover(function() {
$('.close-video').addClass('show');
}, function() {
$('.close-video').removeClass('show');
});
}
}
$('.close-video').hover(function() {
$('.close-video').addClass('show');
}, function() {
});
$('.action--play').click(function(event) {
if (!Modernizr.videoautoplay && !Modernizr.csstransforms3d) {
window.location = $(this).attr('data-video-url');
return;
}
$(this).toggleClass('is-playing');
$('.video-modal').removeClass('is-hidden');
$('.video-modal').addClass('is-shown');
$('.action--play').addClass('hide');
setTimeout(function() {
player.play();
}, 1500);
});
$('.front-action--play').click(function(event) {
if (!Modernizr.videoautoplay || !Modernizr.csstransforms3d) {
window.location = $('.video-modal').find('iframe').attr('src');
return;
}
$(this).toggleClass('is-playing');
$('.video-modal').removeClass('is-hidden');
$('.video-modal').addClass('is-shown');
$('.action--play').addClass('hide');
$('.hero--contents').hide();
$('.arrow').hide();
setTimeout(function() {
$('.landing-hero').addClass('no-curtain');
player.play();
}, 1500);
});
if ($('.all-stories').length) {
var $grid = $('.all-stories').imagesLoaded(function() {
$grid.isotope({
// options
masonry: {
gutter: 18,
columnWidth: 360,
fitWidth: true
},
layoutMode: 'masonry',
itemSelector: '.effect-goliath',
});
});
var myEfficientFn = debounce(function() {
$grid.isotope('layout');
}, 250);
window.addEventListener('resize', myEfficientFn);
$('.filters').on( 'click', 'button', function() {
$('.filters button').each(function(index, el) {
$(el).removeClass('is-checked');
});
$('#P1info').hide();
$('#P2info').hide();
$('#P3info').hide();
$(this).addClass('is-checked');
var filterValue = $(this).attr('data-filter');
Cookies.remove('sort');
Cookies.set('sort', filterValue);
if (filterValue !== "*") {
$('.'+filterValue).fadeIn('fast');
}
if (filterValue=="*") {
$grid.isotope({ filter: "*" });
} else {
$grid.isotope({
filter: function() {
var item = $(this).find('.visited-test').attr( 'data-filter-val' );
return filterValue == item;
}
});
}
});
var cook = Cookies.get('sort');
if (cook == 'invigorate') {
$('#P1').trigger('click');
} else if (cook == 'increase') {
$('#P2').trigger('click');
} else if (cook == 'enhance') {
$('#P3').trigger('click');
} else {
$('#Pall').trigger('click');
}
}
if ($('.priority').length) {
$('.tax-drawer').insertAfter('.hero');
}
$('.close-video').click(function(event) {
$('.video-modal').removeClass('is-shown');
$('.video-modal').addClass('is-hidden');
$('.action--play').removeClass('hide');
$('.close-video').removeClass('show');
$('.hero--contents').show();
$('.landing-hero').removeClass('no-curtain');
$('.arrow').show();
player.pause();
})
// if ($("[data-c-end]").length) {
// $("[data-c-end]").each(function(index, el) {
// var entered = false;
// var countID = 'count' + index;
// $(el).text(' ');
// $(this).attr('id', countID);
// new Waypoint.Inview({
// element: $(this)[0],
// entered: function(direction) {
// if ($(el).attr('data-c-counted') !== 'true') {
// var id = $(el).attr('id');
// var val = $(el).attr('data-c-end');
// var dec = $(el).attr('data-c-decimals');
// var suffix = $(el).attr('data-c-suffix') ? $(el).attr('data-c-suffix') : '';
// var prefix = $(el).attr('data-c-prefix') ? $(el).attr('data-c-prefix') : '';
// var startVal = $(el).attr('data-c-start');
// var numAnim = new CountUp(id, startVal, val, dec, 5, {
// 'useEasing': true,
// 'useGrouping': true,
// 'separator': ',',
// 'decimal': '.',
// 'prefix': prefix,
// 'suffix': suffix
// });
// numAnim.start();
// $(el).attr('data-c-counted', 'true');
// }
// },
// });
// });
// }
if ($('#block-nextblock').length) {
var flag = false;
var inview = new Waypoint.Inview({
element: $('#block-nextblock')[0],
// enter: function(direction) {
// notify('Enter triggered with direction ' + direction)
// },
entered: function(direction) {
if (!flag) {
$('#block-nextblock').addClass('fill');
flag = true;
}
},
// exit: function(direction) {
// notify('Exit triggered with direction ' + direction)
// },
exited: function(direction) {
}
});
$('#block-nextblock').click(function() {
window.location = $(this).find('a').attr('href');
})
}
});