(function ($) { 'use strict'; var WTBigshop = { _init: function () { var offCanvas = { menuBar: $('.trigger-off-canvas'), drawer: $('.wtbigshop-offcanvas-drawer'), drawerClass: '.wtbigshop-offcanvas-drawer', menuDropdown: $('.dropdown-menu.depth_0'), }; WTBigshop.menuDrawerOpen(offCanvas); WTBigshop.offcanvasMenuToggle(offCanvas); WTBigshop.headerSearchOpen(); WTBigshop.backToTop(); WTBigshop.counterUp(); WTBigshop.parallaxMouse(); WTBigshop.preLoader(); WTBigshop.menuOffset(); WTBigshop.magnificPopup(); WTBigshop.hasAnimation(); WTBigshop.swiperSlider(); WTBigshop.horizontalSwiperSlider(); WTBigshop.advanceProductSearch(); WTBigshop.headerCatVerticalMenu(); WTBigshop.HeadroomStickyHeader(); WTBigshop.timeCounter(); WTBigshop.imageFunction(); }, magnificPopup: function (){ var yPopup = $(".popup-youtube"); if (yPopup.length) { yPopup.magnificPopup({ disableOn: 700, type: 'iframe', mainClass: 'mfp-fade', removalDelay: 160, preloader: false, fixedContentPos: false }); } $(document).on('added_to_cart', function() { updateCartMenu(); }); // Update cart count when an item is removed from the cart $(document).on('click', '.remove_from_cart_button', function(e) { e.preventDefault(); $(document.body).on('removed_from_cart', function() { updateCartMenu(); }); }); // Function to update the cart count dynamically function updateCartMenu() { $.ajax({ url: wtbigshopObj.ajaxURL, type: 'GET', data: { action: 'wt_cart_count' }, success: function(response) { $('.wt-cart-menu-count').text(response.data.cart_count); $('.wt-cart-menu-total').html(response.data.cart_total); } }); } // Cart show & hide $(document).on('click', '.rt-cart-icon', function () { $(".cart-icon-total-products").addClass("visible-cart"); $(".body-overlay-cart").addClass("overlayshow"); }); $(document).on('click', '.body-overlay-cart', function () { $(this).removeClass("overlayshow"); $(".cart-icon-total-products").removeClass("visible-cart"); }); $(document).on('click', '.close-cart', function () { $(".cart-icon-total-products").removeClass("visible-cart"); $(".body-overlay-cart").removeClass("overlayshow"); }); }, slickSlider: function () { $('.rt-carousel').css({'opacity': 1, 'transition':'0.4s'}) if (typeof $.fn.slick == 'function') { $('.rt-slick').slick() } }, menuOffset: function () { $(".dropdown-menu > li").each(function () { var $this = $(this), $win = $(window); if ($this.offset().left + ($this.width() + 30) > $win.width() + $win.scrollLeft() - $this.width()) { $this.addClass("dropdown-inverse"); } else if ($this.offset().left < ($this.width() + 30)) { $this.addClass("dropdown-inverse-left"); } else { $this.removeClass("dropdown-inverse"); } }); }, HeadroomStickyHeader: function(){ var navContainer = document.querySelector('.intelligent-header'); if (navContainer != null){ var options = { offset: 450, classes: { initial: 'iheader', pinned: 'iheader--pinned', unpinned: 'iheader--unpinned', top: 'iheader--top', notTop: 'iheader--not-top', bottom: 'iheader--bottom', notBottom: 'iheader--not-bottom' } }; var headroom = new Headroom(navContainer, options); headroom.init(); var intHeight = $('.intelligent-header')[0].getBoundingClientRect().height; $('.fixed-header-space').height(intHeight); } }, headerSticky: function () { if ($('body').hasClass('has-sticky-header')) { var stickyPlaceHolder = $("#rt-sticky-placeholder"); var mainMenu = $(".main-header-section"); var menuHeight = mainMenu.outerHeight() || 0; var headerTopbar = $('.wtbigshop-topbar').outerHeight() || 0; var targrtScroll = headerTopbar + menuHeight; if ($('body').hasClass('wtbigshop-header-2')) { targrtScroll = $(window).height() - menuHeight; } // Main Menu if ($(window).scrollTop() > targrtScroll) { mainMenu.addClass('rt-sticky'); stickyPlaceHolder.height(menuHeight); } else { mainMenu.removeClass('rt-sticky'); stickyPlaceHolder.height(0); } //Mobile Menu var mobileMenu = $("#meanmenu"); var mobileTopHeight = $('#mobile-menu-sticky-placeholder'); if ($(window).scrollTop() > mobileMenu.outerHeight() + headerTopbar) { mobileMenu.addClass('rt-sticky'); mobileTopHeight.height(mobileMenu.outerHeight()); } else { mobileMenu.removeClass('rt-sticky'); mobileTopHeight.height(0); } } }, menuDrawerOpen: function (offCanvas) { offCanvas.menuBar.on('click', e => { e.preventDefault(); offCanvas.menuBar.toggleClass('is-open') offCanvas.drawer.toggleClass('is-open'); e.stopPropagation() }); $(document).on('click', e => { if (!$(e.target).closest(offCanvas.drawerClass).length) { offCanvas.drawer.removeClass('is-open'); offCanvas.menuBar.removeClass('is-open') } }); }, offcanvasMenuToggle: function (offCanvas) { offCanvas.drawer.each(function () { const caret = $(this).find('.caret'); caret.on('click', function (e) { e.preventDefault(); $(this).closest('li').toggleClass('is-open'); $(this).parent().next().slideToggle(300); }) }) }, headerSearchOpen: function () { $('.wtbigshop-search-trigger').on('click', function (e) { e.preventDefault(); $(this).parent().toggleClass('show'); e.stopPropagation() }) $(document).on('click', function (e) { if (!$(e.target).closest('.wtbigshop-search-form').length) { $('.wtbigshop-search-popup.show').removeClass('show') } }); }, backToTop: function () { /* Scroll to top */ $('.scrollToTop').on('click', function () { $('html, body').animate({scrollTop: 0}, 800); return false; }); }, /* windrow back to top scroll */ backTopTopScroll: function () { if ($(window).scrollTop() > 100) { $('.scrollToTop').addClass('show'); $('.intelligent-header').addClass('scrolling'); } else { $('.scrollToTop').removeClass('show'); $('.intelligent-header').removeClass('scrolling'); } }, /* Counter */ counterUp: function () { const counterContainer = $('.counter'); if (counterContainer.length) { counterContainer.counterUp({ delay: counterContainer.data('rtsteps'), time: counterContainer.data('rtspeed') }); } }, //mouse-parallax parallaxMouse: function () { const parallaxWrapper = $(".rt-image-parallax"); if ( parallaxWrapper.length ) { const parallaxInstances = []; $('.rt-mouse-parallax').each(function(index) { var $this = $(this); $this.attr('id', "rt-parallax-instance-" + index); if ($(window).width() > 1199) { parallaxInstances[index] = new Parallax($("#rt-parallax-instance-" + index).get(0), {}); } }); } }, /* preloader */ preLoader: function () { $('#preloader').fadeOut('slow', function () { $(this).remove(); }); }, /* windrow scroll animation */ hasAnimation: function () { if (!!window.IntersectionObserver) { let observer = new IntersectionObserver((entries, observer) => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add("active-animation"); observer.unobserve(entry.target); } }); }, { rootMargin: "0px 0px -100px 0px" }); document.querySelectorAll('.has-animation').forEach(block => { observer.observe(block) }); } else { document.querySelectorAll('.has-animation').forEach(block => { block.classList.remove('has-animation') }); } }, /* Swiper slider */ swiperSlider: function () { $('.rt-swiper-slider').each(function() { var $this = $(this); var settings = $this.data('options'); var autoplayconditon= settings['auto']; var pauseOnHover= settings['pauseOnHover']; var $pagination = settings['pagination']['el']; var $next = settings['navigation']['nextEl']; var $prev = settings['navigation']['prevEl']; var swiper = new Swiper( $this[0], { speed:settings['speed'], spaceBetween: settings['spaceBetween'], slidesPerGroup: settings['slidesPerGroup'] ? settings['slidesPerGroup']:1, autoplay:autoplayconditon ? {delay:settings['autoplay']['delay']}:false, effect: typeof settings['effect'] == "undefined" ? 'slide' : settings['effect'], pagination: { el: $pagination, clickable: true, type: 'bullets', }, navigation: { nextEl: $next, prevEl: $prev, }, breakpoints: { 0: { slidesPerView: settings['breakpoints']['0']['slidesPerView'], }, 576: { slidesPerView: settings['breakpoints']['576']['slidesPerView'], }, 768: { slidesPerView: settings['breakpoints']['768']['slidesPerView'], }, 992: { slidesPerView: settings['breakpoints']['992']['slidesPerView'], }, 1200: { slidesPerView: settings['breakpoints']['1200']['slidesPerView'], }, 1600: { slidesPerView: settings['breakpoints']['1600']['slidesPerView'], }, }, }); if( autoplayconditon === true && pauseOnHover === true ) { $(".rt-swiper-slider").mouseenter(function() { swiper.autoplay.stop(); }); $(".rt-swiper-slider").mouseleave(function() { swiper.autoplay.start(); }); } swiper.init(); }); }, /* Horizontal Thumbnail slider */ horizontalSwiperSlider: function () { $('.rt-horizontal-slider').each(function () { var slider_wrap = $(this); var $pagination = slider_wrap.find('.swiper-pagination')[0]; var $next = slider_wrap.find('.swiper-button-next')[0]; var $prev = slider_wrap.find('.swiper-button-prev')[0]; var target_thumb_slider = slider_wrap.find('.horizontal-thumb-slider'); var thumb_slider = null; if (target_thumb_slider.length) { var settings = target_thumb_slider.data('options'); var autoplayconditon = settings['auto']; thumb_slider = new Swiper(target_thumb_slider[0], { autoplay: autoplayconditon ? { delay:settings['autoplay']['delay'] } : false, speed: settings['speed'], loop: settings['loop'], pauseOnMouseEnter: true, slidesPerView: settings['slidesPerView'], spaceBetween: settings['spaceBetween'], // centeredSlides: true, // slidesPerGroup: settings['slidesPerGroup'], pagination: { el: $pagination, clickable: true, type: 'bullets', }, navigation: { nextEl: $next, prevEl: $prev, }, breakpoints: { 0: { slidesPerView: settings['breakpoints']['0']['slidesPerView'], }, 576: { slidesPerView: settings['breakpoints']['576']['slidesPerView'], }, 768: { slidesPerView: settings['breakpoints']['768']['slidesPerView'], }, 992: { slidesPerView: settings['breakpoints']['992']['slidesPerView'], }, 1200: { slidesPerView: settings['breakpoints']['1200']['slidesPerView'], }, 1600: { slidesPerView: settings['breakpoints']['1600']['slidesPerView'], }, }, }); } var target_slider = slider_wrap.find('.horizontal-slider'); if (target_slider.length) { var settings = target_slider.data('options'); new Swiper(target_slider[0], { autoplay: autoplayconditon ? { delay:settings['autoplay']['delay'] } : false, speed: settings['speed'], loop: settings['loop'], effect: settings && settings['effect'], thumbs: { swiper: thumb_slider, }, navigation: { nextEl: $next, prevEl: $prev, }, }); } }); }, advanceProductSearch:function() { $('#dropdownMenuButton1').on('click',function (){ var root_parent = $(this).parents('.product-search'); root_parent.find('.rt-drop-menu').toggleClass('show'); }); $('.category-search-dropdown-js .dropdown-menu li').on('click', function (e) { var root_parent = $(this).parents('.product-search'); var $parent = $(this).closest('.category-search-dropdown-js'), slug = $(this).data('slug'), name = $(this).text(); $parent.find('.cat-toggle .cat-label').text($.trim(name)); $parent.find('input[name="product_cat"]').val(slug); root_parent.find('.product-autocomplete-js').data('tax', slug); root_parent.find('.product-autocomplete-js').trigger('keyup'); }); $(document).on('keyup', '.product-autocomplete-js', function () { var root_parent = $(this).parents('.product-search'); var keyword = root_parent.find('.product-autocomplete-js').val(); var taxonomy = root_parent.find('.product-autocomplete-js').data('tax'); if ( keyword.length > 1 ) { $.ajax({ url: wtbigshopObj.ajaxURL, type: 'POST', data: { 'action': 'wtbigshop_product_search_autocomplete', 'category_val': taxonomy, 'keyword': keyword, nonce: wtbigshopObj.nonce }, beforeSend: function () { root_parent.find('.product-autoaomplete-spinner').css('opacity', '1'); }, success: function (data) { root_parent.find('.result').html(data); }, complete: function () { root_parent.find('.product-autoaomplete-spinner').css('opacity', '0'); } }); } else { root_parent.find('.result').empty(); } }); $(document).on('click', function (e) { var t = e.srcElement || e.target; if ($(t).attr('class')) { $('.result-wrap').remove(); } else { } }); }, headerCatVerticalMenu:function (){ $('#dropdownMenuButton2').on('click',function (){ var root_parent = $(this).parents('.cat-drop-area'); root_parent.find('.rt-vertical-drop-menu').toggleClass('show'); }); }, timeCounter: function (){ if ( typeof $.fn.countdown == 'function') { try { var eventCountdownTime = $('.rt-countdown').data('countdown'); $('.rt-countdown') .countdown(eventCountdownTime) .on('update.countdown', function(event) { $(this).html(event.strftime('' + '
%D ' + 'Days' + '
' + '
%H ' + 'Hours' + '
' + '
%M ' + ' Minutes ' + '
' + '
%S ' + 'Seconds' +'
')); }) .on('finish.countdown', function(event) { $(this).html(event.strftime('')); }); } catch (error) { console.error(error); } } }, imageFunction:function (){ $("[data-bg-image]").each(function () { let img = $(this).data("bg-image"); $(this).css({ backgroundImage: "url(" + img + ")", }); }); } }; $(document).ready(function (e) { WTBigshop._init(); }); $(document).on('load', () => { WTBigshop.menuOffset(); }) $(window).on('scroll', (event) => { //WTBigshop.headerSticky(event); WTBigshop.backTopTopScroll(event); }); $(window).on('resize', () => { WTBigshop.menuOffset($); }); $(window).on('elementor/frontend/init', () => { if (elementorFrontend.isEditMode()) { //For all widgets elementorFrontend.hooks.addAction('frontend/element_ready/widget', () => { WTBigshop.slickSlider($); WTBigshop.magnificPopup(); WTBigshop.hasAnimation(); WTBigshop.counterUp(); WTBigshop.parallaxMouse(); WTBigshop.swiperSlider(); WTBigshop.horizontalSwiperSlider(); WTBigshop.timeCounter(); WTBigshop.imageFunction(); }); } }); window.WTBigshop = WTBigshop; })(jQuery);