(function() { 'use strict'; /** * Easy selector helper function */ const select = (el, all = false) => { el = el.trim(); if (all) { return [...document.querySelectorAll(el)]; } else { return document.querySelector(el); } }; /** * Easy event listener function */ const on = (type, el, listener, all = false) => { let selectEl = select(el, all); if (selectEl) { if (all) { selectEl.forEach(e => e.addEventListener(type, listener)); } else { selectEl.addEventListener(type, listener); } } }; /** * Easy on scroll event listener */ const onscroll = (el, listener) => { el.addEventListener('scroll', listener); }; /** * Back to top button */ let backtotop = select('.back-to-top'); if (backtotop) { const toggleBacktotop = () => { if (window.scrollY > 100) { backtotop.classList.add('active'); } else { backtotop.classList.remove('active'); } }; window.addEventListener('load', toggleBacktotop); onscroll(document, toggleBacktotop); } on('click', '.back-to-top', function(e) { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera }); /** * Mobile nav toggle */ on('click', '#mobile-nav-toggle', function(e) { select('#navbar').classList.toggle('navbar-mobile'); this.classList.toggle('fa-bars'); this.classList.toggle('fa-times'); }); on('click', '#user-nav-toggle', function(e) { select('#user').classList.toggle('navbar-mobile'); this.classList.toggle('fa-user'); this.classList.toggle('fa-times'); }); window.onresize = function(){ if(window.innerWidth>991){ if(select('#navbar').classList.contains('navbar-mobile')){ select('#mobile-nav-toggle').click(); } if(select('#user').classList.contains('navbar-mobile')){ select('#user-nav-toggle').click(); } } }; /** * Mobile nav dropdowns activate */ on('click', '#navbar .dropdown > a', function(e) { if (select('#navbar').classList.contains('navbar-mobile')) { e.preventDefault(); this.nextElementSibling.classList.toggle('dropdown-active'); } }, true); on('click', '#user .dropdown > a', function(e) { if (select('#user').classList.contains('navbar-mobile')) { e.preventDefault(); this.nextElementSibling.classList.toggle('dropdown-active'); } }, true); /** * Preloader */ let preloader = select('#preloader'); if (preloader) { window.addEventListener('load', () => { preloader.remove(); }); } /** * Testimonials slider */ new Swiper('.testimonials-slider', { speed: 600, loop: true, autoplay: { delay: 5000, disableOnInteraction: false }, slidesPerView: 'auto', pagination: { el: '.swiper-pagination', type: 'bullets', clickable: true }, breakpoints: { 320: { slidesPerView: 1, spaceBetween: 20 }, 1200: { slidesPerView: 2, spaceBetween: 20 } } }); /** * Animation on scroll */ window.addEventListener('load', () => { AOS.init({ duration: 1000, easing: 'ease-in-out', once: true, mirror: false }); }); var thisURL = window.location.href; if(thisURL){ var linkElement = $('a[href="' + thisURL + '"]'); linkElement.addClass('active'); linkElement.parents('.dropdown').children('a:first-child').addClass('active'); // var link2Element = $('.dropdown-item.nav-link.nav_item.active'); // link2Element.parents('.dropdown-menu').prev('a.nav-link').addClass('active'); } })();