(function() { "use strict"; // Parallax var parallax = function() { $(window).stellar(); }; // Preloader $(window).on('load', function() { if ($('#preloader').length) { $('#preloader').delay(100).fadeOut('slow', function() { $(this).remove(); }); } }); $(window).on('load', function() { var $stickyElement = $('#gnbArea'); var sticky; if ($stickyElement.length) { sticky = new Waypoint.Sticky({ element: $stickyElement[0], offset: function() { return -this.element.clientHeight } }); } }); /** * 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) } /** * Navbar links active state on scroll */ let navbarlinks = select('#navbar .scrollto', true) const navbarlinksActive = () => { let position = window.scrollY + 200 navbarlinks.forEach(navbarlink => { if (!navbarlink.hash) return let section = select(navbarlink.hash) if (!section) return if (position >= section.offsetTop && position <= (section.offsetTop + section.offsetHeight)) { navbarlink.classList.add('active') } else { navbarlink.classList.remove('active') } }) } window.addEventListener('load', navbarlinksActive) onscroll(document, navbarlinksActive) /** * Scrolls to an element with header offset */ const scrollto = (el) => { let header = select('#header') let offset = header.offsetHeight if (!header.classList.contains('header-scrolled')) { offset -= 0 } let elementPos = select(el).offsetTop window.scrollTo({ top: elementPos - offset, behavior: 'smooth' }) } /** * Toggle .header-scrolled class to #header when page is scrolled */ let selectHeader = select('#header') if (selectHeader) { const headerScrolled = () => { if (window.scrollY > 100) { selectHeader.classList.add('header-scrolled') } else { selectHeader.classList.remove('header-scrolled') } } window.addEventListener('load', headerScrolled) onscroll(document, headerScrolled) } /** * Mobile nav toggle */ on('click', '#navToggleMobile', function(e) { select('#navbar').classList.toggle('navbar-mobile') this.classList.toggle('fa-solid') this.classList.toggle('fa-xmark') }) /** * 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) /** * Scrol with offset on links with a class name .scrollto */ on('click', '.scrollto', function(e) { if (select(this.hash)) { e.preventDefault() let navbar = select('#navbar') if (navbar.classList.contains('navbar-mobile')) { navbar.classList.remove('navbar-mobile') let navbarToggle = select('#navToggleMobile') navbarToggle.classList.toggle('fa-solid') navbarToggle.classList.toggle('fa-xmark') } scrollto(this.hash) } }, true) /** * Back to top button */ let backtotop = select('#backToTop') if (backtotop) { const toggleBacktotop = () => { if (window.scrollY > 100) { backtotop.classList.add('active') } else { backtotop.classList.remove('active') } } window.addEventListener('load', toggleBacktotop) onscroll(document, toggleBacktotop) } // Cover carousel var introCarousel = $(".carousel"); var introCarouselIndicators = $("#carouselIndicators"); introCarousel.find(".carousel-inner").children(".carousel-item").each(function(index) { (index === 0) ? introCarouselIndicators.append("
  • "): introCarouselIndicators.append("
  • "); $(this).css("background-image", "url('" + $(this).children('.carousel-img').children('img').attr('src') + "')"); $(this).children('.carousel-img').remove(); }); $(".carousel").swipe({ swipe: function(event, direction, distance, duration, fingerCount, fingerData) { if (direction == 'left') $(this).carousel('next'); if (direction == 'right') $(this).carousel('prev'); }, allowPageScroll: "vertical" }); // Initiate the wowjs animation library new WOW().init(); /** * Porfolio isotope and filter */ window.addEventListener('load', () => { let portfolioContainer = select('.portfolio-items-wrap'); if (portfolioContainer) { let portfolioIsotope = new Isotope(portfolioContainer, { itemSelector: '.portfolio-item', layoutMode: 'fitRows' }); let portfolioFilters = select('#portfolioFlters li', true); on('click', '#portfolioFlters li', function(e) { e.preventDefault(); portfolioFilters.forEach(function(el) { el.classList.remove('filter-active'); }); this.classList.add('filter-active'); portfolioIsotope.arrange({ filter: this.getAttribute('data-filter') }); }, true); } }); /** * Initiate portfolio lightbox */ const portfolioLightbox = GLightbox({ selector: '.portfolio-lightbox' }); // Clients carousel (uses the Owl Carousel library) $(".gallery-carousel").owlCarousel({ margin: 30, autoplay: true, dots: true, loop: true, responsive: { 0: { items: 2 }, 768: { items: 4 }, 900: { items: 6 } } }); }());