// remap jQuery to $ (function($){ /* trigger when page is ready */ $(document).ready(function (){ if ($('.cp-masthead__countdown-wrapper').length) { if (window.innerWidth < 768) { $('.cp-masthead__countdown').insertAfter('.cp-masthead'); mobileCountdown = true; } else { mobileCountdown = false; } var timeWithSpaces = $('.cp-masthead__countdown-wrapper').attr('datetime'); var timeTrimmed = timeWithSpaces.replace(/\s+/g, ''); $('.cp-masthead__countdown-wrapper').attr('datetime', timeTrimmed); var date1 = new Date() var date2 = new Date(timeTrimmed) var timeDiff = (date2.getTime() - date1.getTime()) if (timeDiff < 0) { console.log('Countdown expired. Hiding countdown...') $('.cp-masthead__countdown').hide(); $('body').removeClass('countdown') } else { $('.cp-masthead__countdown-wrapper').countDown({ css_class: 'timer-inner', separator_days: ':' }); } $('.cp-masthead__countdown-wrapper').on('time.elapsed', function () { $('.cp-masthead__countdown').hide(); $('body').removeClass('countdown') }); $(window).resize(function() { if ((window.innerWidth < 768) && (mobileCountdown == false)) { $('.cp-masthead__countdown').insertAfter('.cp-masthead'); mobileCountdown = true; console.log('mob fired') } else if ((window.innerWidth >= 768) && (mobileCountdown == true)) { $('.cp-masthead__countdown').appendTo('.cp-masthead__wrapper'); console.log('desktop fired') mobileCountdown = false; } }) } $(".cp-header__nav--icon, .cp-nav__close--icon").click(function(e){ e.preventDefault(); $('body').toggleClass('nav-open'); $('.cp-nav').toggleClass('active'); $('.cp-header').toggleClass('nav-open'); }); $('.menu-item-has-children--toggle').on('click', function() { parent = $(this).parent('li'); $(parent).toggleClass('active') }) }); /* optional triggers $(window).load(function() { }); $(window).resize(function() { }); */ })(window.jQuery);