//**All js for woocommerce of theme (function ($) { 'use strict'; $(document).ready(function () { $(document).on('click','.zoo-product-quick-view .woocommerce-product-gallery__wrapper a',function (e) { e.preventDefault(); }) //Alternative image, change to alt image when hover to product. zoo_alternate_image(); //Sticky add to cart button zoo_sticky_add_to_cart(); //Clever Swatches extend function for theme zoo_cleverswatches_function(); //Scroll to review tab zoo_scroll_to_review_tab(); // Sidebar control zoo_sidebar_control(); //Binding ajax zoo_binding_ajax(); $(document).on('focus','#review_form textarea, #review_form input[type="text"],#review_form input[type="email"], #customer_login input.input-text',function (e) { e.preventDefault(); $(this).closest('p').addClass('focus') }); $(document).on('focusout','#review_form textarea, #review_form input[type="text"],#review_form input[type="email"], #customer_login input.input-text',function (e) { e.preventDefault(); if($(this).val()=='') { $(this).closest('p').removeClass('focus') } }); $(document).on('click','.toggle-login-form',function (e) { e.preventDefault(); $('#customer_login .u-column1, #customer_login .u-column2').slideToggle(); }) let url = new URL(window.location.href); let param= url.searchParams.get('action'); if(param=="register"){ $('#customer_login .u-column1').hide();$('#customer_login .u-column2').show(); } //Product qty control $(document).zoo_CartQuantity('.quantity .qty-nav'); $(document).on('cwapf_after_filtered',function(){ $('.zoo-sidebar-control.active').trigger('click'); }) }); /** * Set a cookie * @param {String} cname, cookie name, {String} cookie value */ function setCookie(cname, cvalue) { document.cookie = cname + "=" + cvalue + "; "; } /** * Delete a cookie * @param {String} cname, cookie name */ function deleteCookie(cname) { var d = new Date(); //Create an date object d.setTime(d.getTime() - (1000 * 60 * 60 * 24)); //Set the time to the past. 1000 milliseonds = 1 second var expires = "expires=" + d.toGMTString(); //Compose the expirartion date window.document.cookie = cname + "=" + "; " + expires;//Set the cookie with name and the expiration date } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for (var i = 0; i < ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } //Binding ajax function zoo_binding_ajax(){ $(document).on('cwpf_ajax_done',function(){ $('.product-sidebar').removeClass('active'); $('.zoo-mask-close').removeClass('sidebar-active active'); $('.zoo-top-sidebar.product-sidebar').slideToggle("slow"); }); } //Scroll effect for Review link when click. function zoo_scroll_to_review_tab() { $(document).on('click', '.woocommerce-review-link', function (e) { if ($('.zoo-product-data-tabs.accordion-layout')[0]) { if ($('#tab-reviews').closest('.zoo-group-accordion:not(.accordion-active)')[0]) { $('.zoo-group-accordion.accordion-active .wc-tab').hide(); } $('#tab-reviews').closest('.zoo-group-accordion:not(.accordion-active)').find('.tab-heading').trigger('click'); $('html, body').animate({ scrollTop: $('#tab-reviews').offset().top - $('.site-header').height() }, 500); } }); } //Clever Swatches extend Function function zoo_cleverswatches_function() { $(document).on('cleverswatch_button_select_option', function (event, response) { var add_to_cart_button = response.selector; add_to_cart_button.closest('.variations_form').find('.zoo-buy-now').addClass('disabled'); }); //Bind for button if button is Add to Cart $(document).on('cleverswatch_button_add_cart', function (event, response) { var add_to_cart_button = response.selector; add_to_cart_button.closest('.variations_form').find('.zoo-buy-now').removeClass('disabled'); }); //Bind for button if button is Out of stock $(document).on('cleverswatch_button_out_stock', function (event, response) { var add_to_cart_button = response.selector; add_to_cart_button.closest('.variations_form').find('.zoo-buy-now').addClass('disabled'); }); } //Sidebar control function zoo_sidebar_control(){ $(document).on('click', '.zoo-sidebar-control', function (e) { e.preventDefault(); $(this).toggleClass('active'); $('.product-sidebar').toggleClass('active'); if (!$(this).closest('.top-sidebar-layout')[0] || $(window).width() < 992) { $('.zoo-mask-close').addClass('sidebar-active active'); } if ($(this).closest('.top-sidebar-layout')[0] && $(window).width() > 992) { $('.zoo-top-sidebar.product-sidebar').slideToggle("slow"); } }); $(document).on('click', '.sidebar-active.active, .close-btn.close-sidebar', function (e) { e.preventDefault(); $('.product-sidebar, .zoo-sidebar-control').removeClass('active'); $('.zoo-mask-close').removeClass('sidebar-active active'); }); } //Alternative Image function zoo_alternate_image() { $(document).on('mouseenter', '.products .product', function () { let $this = $(this).find('.sec-img'); if (!!$this.data('src') && $this.attr('src') != $this.data('src')) { $this.attr('src', $this.data('src')); $this.attr('srcset', $this.data('srcset')); } }); } //Stick add to cart button function zoo_sticky_add_to_cart() { $(window).on('load', function () { if ($('.zoo-sticky-add-to-cart')[0] && $('.summary form.cart')[0]) { jQuery(window).on("scroll", function () { var footer = 0; if ($('footer.site-footer')[0]) { footer = $('footer.site-footer').offset().top; } else if ($('footer.cafe-site-footer')[0]) { footer = $('footer.cafe-site-footer').offset().top; } if ($(window).scrollTop() > $('.summary form.cart').height() + $('.summary form.cart').offset().top && $(window).scrollTop() + $(window).height() < footer) { $('.zoo-sticky-add-to-cart:not(.active)').addClass('active') } else { $('.zoo-sticky-add-to-cart.active').removeClass('active') } }); $(document).on('click', '.zoo-sticky-add-to-cart .button-sticky-add-to-cart', function (e) { e.preventDefault(); $('html, body').animate({ scrollTop: $('.summary').offset().top }, 700); }); } }); } jQuery.fn.extend({ zoo_CartQuantity: function (target) { if ($(this)[0]) { $(this).on("click", target, function () { let qty = jQuery(this).parents('.quantity').find('input.qty'); let val = parseInt(!!qty.val()?qty.val():0); if ($(this).hasClass('increase')) { qty.val(val + 1); } else { if ($(this).closest('.woocommerce-grouped-product-list')[0]) { if (val > 0) { qty.val(val - 1); } } else { if (val > 1) { qty.val(val - 1); } } } qty.trigger('change'); }); } },}) }) (jQuery);