(function ($) { AOS.init({ once: true, startEvent: 'load' }) window.addEventListener('load', AOS.refresh) var change; //Navigation $('#show-menu').unbind('click').click(function (e) { e.stopPropagation(); $('#navigation').toggleClass('open'); $(this).attr('aria-expanded', function (i, attr) { return attr == 'true' ? 'false' : 'true' }); }); $('#menu-trigger').unbind('click').click(function (e) { console.log('click'); e.stopPropagation(); $('#navigation').toggleClass('open'); $('#show-menu').attr('aria-expanded', 'true'); }); $('body:not(.page-index) nav a[href^="/' + location.pathname.split("/")[1] + '"]').addClass('active'); //Lity lightbox caption $(document).on('lity:ready', function(event, $lightbox) { var $triggeringElement = $lightbox.opener(); $('.lity-content').append('

' + $triggeringElement.data('lity-desc') + '

'); }); //Animated counter function isElementVisible($elementToBeChecked) { var TopView = $(window).scrollTop(); var BotView = TopView + $(window).height(); var TopElement = $elementToBeChecked.offset().top; var BotElement = TopElement + $elementToBeChecked.height(); return ((BotElement <= BotView) && (TopElement >= TopView)); } function commaSeparateNumber(val) { while (/(\d+)(\d{3})/.test(val.toString())) { val = val.toString().replace(/(\d+)(\d{3})/, '$1' + ',' + '$2'); } return val; } function factCount() { //Counter $('.counter').each(function() { var $this = $(this); isOnView = isElementVisible($this); if(!$this.hasClass('counted')){ $this.parent('.fact--number').css('opacity','0'); } if(isOnView && !$this.hasClass('counted')){ $this.addClass('counted'); var countTo = $this.text(); $this.text(0); $this.parent('.fact--number').css('opacity','1'); var countTo = countTo.replace(/\D/g,''); var countTime = 5000; if (countTo < 100) { countTime = 3000; } if (countTo < 10) { countTime = 2000; } if (countTo < 5) { countTime = 1000; } $({ countNum: $this.text()}).animate({ countNum: countTo }, { duration: countTime, easing:'linear', step: function() { $this.text(commaSeparateNumber(Math.floor(this.countNum))); }, complete: function() { $this.text(commaSeparateNumber(this.countNum)); } }); } }); } factCount(); // SCROLL POSITION var position = $(window).scrollTop(); $(window).scroll(function () { var scroll = $(window).scrollTop(); if(scroll > position) { $('body').removeClass('up').addClass('down'); } else { $('body').removeClass('down').addClass('up') } position = scroll; if(position < '100') { $('body').addClass('at-top'); } else { $('body').removeClass('at-top'); } factCount(); }); })(jQuery);