(function ($) { 'use strict'; var razzi = razzi || {}; razzi.init = function () { razzi.$body = $(document.body), razzi.$window = $(window), razzi.$header = $('#site-header'); this.preloader(); // Common this.toggleModals(); this.toggleOffPopup(); // Header this.stickyHeader(); this.instanceSearch(); this.focusSearchField(); this.menuSideBar(); this.scrollSection(); this.miniCartQuantity(); this.closeTopbar(); this.ajaxCounter(); // Blog this.blogFilterAjax(); this.blogLoadingAjax(); this.postFound(); this.postsRelated(); // Product Loop this.addWishlist(); this.productLoopHover(); this.productLoopATCForm(); this.productLoopHoverSlider(); this.productLoopHoverZoom(); this.productQuickView(); this.productQuantityDropdown(); this.productQuantityNumber(); this.updateQuantityAuto(); this.productLoopFormAJAX(); this.productAttribute(); this.productLoaded(); // Single Product this.productLightBox(); this.reviewProduct(); this.stickyAddToCart(); // Product Notification this.openMiniCartPanel(); this.addedToCartNotice(); this.productPopupATC(); this.addedToWishlistNotice(); this.addToCartSingleAjax(); // Cart this.cartPageQuantity(); this.crossSellProductsCarousel(); // Account this.accountOrder(); this.loginPanel(); this.loginPanelAuthenticate(); this.newsletterPopup(); this.backToTop(); this.recentlyViewedProducts(); // Mobile this.footerDropdown(); this.historyBack(); // Style this.inlineStyle(); }; /** * Preloader. */ razzi.preloader = function() { var $preloader = $( '#preloader' ); if ( ! $preloader.length ) { return; } var ignorePreloader = false; $( document.body ).on( 'click', 'a[href^=mailto], a[href^=tel]', function() { ignorePreloader = true; } ); $( window ).on( 'beforeunload', function( event ) { if ( ! ignorePreloader ) { $preloader.fadeIn(); } ignorePreloader = false; } ); setTimeout( function() { $preloader.fadeOut(); }, 200 ); window.onpageshow = function( event ) { if ( event.persisted ) { setTimeout( function() { $preloader.fadeOut(); }, 200 ); } }; }; /** * Toggle modals. */ razzi.toggleModals = function () { $(document.body).on('click', '[data-toggle="modal"]', function (event) { var target = '#' + $(this).data('target'); if ($(target).hasClass('open')) { razzi.closeModal(target); } else if (razzi.openModal(target)) { event.preventDefault(); } }).on('click', '.rz-modal .button-close, .rz-modal .off-modal-layer', function (event) { event.preventDefault(); razzi.closeModal(this); }).on('keyup', function (e) { if (e.keyCode === 27) { razzi.closeModal(); } }); }; /** * Open a modal. * * @param string target */ razzi.openModal = function (target) { var $target = $(target); if (!$target.length) { return false; } $target.fadeIn(); $target.addClass('open'); $(document.body).addClass('modal-opened ' + $target.attr('id') + '-opened').trigger('razzi_modal_opened', [$target]); if( $target.attr('id') == 'search-modal' ) { $('.ra-search-modal .search-field').focus(); } else if( $target.attr('id') == 'account-modal' ) { $('.woocommerce-account .input-text[name="username"]').focus(); } var widthScrollBar = window.innerWidth - document.documentElement.clientWidth; if( document.documentElement.clientWidth < 767 ) { widthScrollBar = 0; } $(document.body).css({'padding-right': widthScrollBar, 'overflow': 'hidden'}); if ($(document.body).hasClass('header-transparent')) { razzi.$header.css({'right': widthScrollBar}); } if ($(document.body).hasClass('header-sticky')) { $(document.body).find('#site-header.minimized').css({'right': widthScrollBar, 'transition' : 'none'}); } return true; } /** * Close a modal. * * @param string target */ razzi.closeModal = function (target) { if (!target) { $('.rz-modal').removeClass('open').fadeOut(); $('.rz-modal').each(function () { var $modal = $(this); if (!$modal.hasClass('open')) { return; } $modal.removeClass('open').fadeOut(); $(document.body).removeClass($modal.attr('id') + '-opened'); }); } else { target = $(target).closest('.rz-modal'); target.removeClass('open loaded').fadeOut(); $(document.body).removeClass(target.attr('id') + '-opened'); } $(document.body).removeAttr('style'); razzi.$header.removeAttr('style'); $(document.body).removeClass('modal-opened').trigger('razzi_modal_closed', [target]); } /** * Toggle off-screen panels */ razzi.toggleOffPopup = function () { $(document.body).on('click', '[data-toggle="off-popup"]', function (event) { var target = '#' + $(this).data('target'); if ($(target).hasClass('open')) { razzi.closeOffPopup(target); } else if (razzi.openOffPopup(target)) { event.preventDefault(); } }).on('click', '.offscreen-popup .button-close, .offscreen-popup .backdrop', function (event) { event.preventDefault(); razzi.closeOffPopup(this); }).on('keyup', function (e) { if (e.keyCode === 27) { razzi.closeOffPopup(); } }); }; /** * Open off popup panel. */ razzi.openOffPopup = function (target) { var $target = $(target); if (!$target.length) { return false; } $target.fadeIn(); $target.addClass('open'); $(document.body).addClass('offpopup-opened ' + $target.attr('id') + '-opened').trigger('razzi_off_popup_opened', [$target]); return true; } /** * Close off popup panel. */ razzi.closeOffPopup = function (target) { if (!target) { $('.offscreen-popup').each(function () { var $panel = $(this); if (!$panel.hasClass('open')) { return; } $panel.removeClass('open').fadeOut(); $(document.body).removeClass($panel.attr('id') + '-opened'); }); } else { target = $(target).closest('.offscreen-popup'); target.removeClass('open').fadeOut(); $(document.body).removeClass(target.attr('id') + '-opened'); } $(document.body).removeClass('offpopup-opened').trigger('razzi_off_popup_closed', [target]); } /** * Product instance search */ razzi.instanceSearch = function () { if (razziData.header_ajax_search != '1') { return; } var $modal = $('#search-modal, .header-search'); $modal.on('change', '.product-cat-dd', function () { var value = $(this).find('option:selected').text().trim(); $modal.find('.product-cat-label .label').html(value); }); $modal.find('.products-search').on('submit', function () { if ($(this).find('.product-cat-dd').val() == '0') { $(this).find('.product-cat-dd').removeAttr('name'); } }); var xhr = null, searchCache = {}, $form = $modal.find('form'); $modal.on('keyup', '.search-field', function (e) { var valid = false; if (typeof e.which == 'undefined') { valid = true; } else if (typeof e.which == 'number' && e.which > 0) { valid = !e.ctrlKey && !e.metaKey && !e.altKey; } if (!valid) { return; } if (xhr) { xhr.abort(); } $modal.find('.result-list-found, .result-list-not-found').html(''); $modal.find('.result-title').addClass('not-found'); var $currentForm = $(this).closest('.form-search'), $search = $currentForm.find('input.search-field'); if ($search.val().length < 2) { $currentForm.removeClass('searching searched actived found-products found-no-product invalid-length'); } search($currentForm); }).on('change', '.product-cat-dd', function () { if (xhr) { xhr.abort(); } $modal.find('.result-list-found').html(''); $modal.find('.result-title').addClass('not-found'); var $currentForm = $(this).closest('.form-search'); search($currentForm); }).on('focus', '.product-cat-dd', function () { if (xhr) { xhr.abort(); } $modal.find('.product-cat-label').addClass('border-color-dark'); }).on('focusout', '.product-cat-dd', function () { if (xhr) { xhr.abort(); } $modal.find('.product-cat-label').removeClass('border-color-dark'); }).on('focusout', '.search-field', function () { var $currentForm = $(this).closest('.form-search'), $search = $currentForm.find('input.search-field'); if ($search.val().length < 2) { $currentForm.removeClass('searching searched actived found-products found-no-product invalid-length'); } }); $modal.on('click', '.close-search-results', function (e) { e.preventDefault(); $modal.find('.search-field').val(''); $modal.find('.form-search').removeClass('searching searched actived found-products found-no-product invalid-length'); $modal.find('.result-title').addClass('not-found'); $modal.find('.result-list-found').html(''); }); $(document).on('click', function (e) { if ($('#search-modal').find('.form-search').hasClass('actived')) { return; } var target = e.target; if ($(target).closest('.products-search').length < 1) { $form.removeClass('searching actived found-products found-no-product invalid-length'); } }); /** * Private function for search */ function search($currentForm) { var $search = $currentForm.find('input.search-field'), keyword = $search.val(), cat = 0, $results = $currentForm.find('.search-results'); if ($modal.hasClass('ra-search-form')) { $results = $modal.find('.search-results'); } if ($currentForm.find('.product-cat-dd').length > 0) { cat = $currentForm.find('.product-cat-dd').val(); } if (keyword.trim().length < 2) { $currentForm.removeClass('searching found-products found-no-product').addClass('invalid-length'); return; } $currentForm.removeClass('found-products found-no-product').addClass('searching'); var keycat = keyword + cat, url = $form.attr('action') + '?' + $form.serialize(); if (keycat in searchCache) { var result = searchCache[keycat]; $currentForm.removeClass('searching'); $currentForm.addClass('found-products'); $results.html(result.products); $(document.body).trigger('razzi_ajax_search_request_success', [$results]); $currentForm.removeClass('invalid-length'); $currentForm.addClass('searched actived'); } else { var data = { 'term': keyword, 'cat': cat, 'ajax_search_number': razziData.header_search_number, 'search_type': razziData.search_content_type }, ajax_url = razziData.ajax_url.toString().replace('%%endpoint%%', 'razzi_instance_search_form'); xhr = $.post( ajax_url, data, function (response) { var $products = response.data; $currentForm.removeClass('searching'); $currentForm.addClass('found-products'); $results.html($products); $currentForm.removeClass('invalid-length'); $(document.body).trigger('razzi_ajax_search_request_success', [$results]); // Cache searchCache[keycat] = { found: true, products: $products }; $results.find('.view-more a').attr('href', url); $currentForm.addClass('searched actived'); } ); } } } razzi.getOptionsDropdown = function () { var options = { onChange: function (value, input) { razzi.updateCartAJAX(value, input); } }; return options; } razzi.updateCartAJAX = function (value, input) { var $row = $( input ).closest('.woocommerce-mini-cart-item'), key = $row.find('a.remove').data('cart_item_key'), nonce = $row.find('.woocommerce-cart-item__qty').data('nonce'), ajax_url = wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'update_cart_item'); if ($.fn.block) { $row.block({ message: null, overlayCSS: { opacity: 0.6, background: '#fff' } }); } $.post( ajax_url, { cart_item_key: key, qty: value, security: nonce }, function (response) { if (!response || !response.fragments) { return; } if ($.fn.unblock) { $row.unblock(); } $( document.body ).trigger( 'added_to_cart', [response.fragments, response.cart_hash] ); }).fail(function () { if ($.fn.unblock) { $row.unblock(); } return; }); } /** * Make the cart widget more flexible. */ razzi.miniCartQuantity = function () { if (typeof wc_add_to_cart_params === undefined) { $('.woocommerce-mini-cart-item .quantity .qty').prop('disabled', true); $(document.body).on('wc_fragments_refreshed removed_from_cart', function () { $('.woocommerce-mini-cart-item .quantity .qty').prop('disabled', true); }); return; } if ($.fn.quantityDropdown && ! razzi.$body.hasClass('product-qty-number')) { var options = razzi.getOptionsDropdown(); $('.woocommerce-mini-cart-item .quantity .qty').quantityDropdown(options); $(document.body).on('wc_fragments_refreshed removed_from_cart added_to_cart', function () { $('.woocommerce-mini-cart-item .quantity .qty').quantityDropdown(options); }); } }; /** * Make the cart widget more flexible. */ razzi.cartPageQuantity = function () { if (typeof wc_add_to_cart_params === undefined) { $('.woocommerce-cart-form__cart-item .quantity .qty').prop('disabled', true); $(document.body).on('wc_fragments_refreshed removed_from_cart', function () { $('.woocommerce-cart-form__cart-item .quantity .qty').prop('disabled', true); }); return; } if ($.fn.quantityDropdown && ! razzi.$body.hasClass('product-qty-number')) { var options = ''; $('.woocommerce-cart-form__cart-item .quantity .qty').quantityDropdown(options); $(document.body).on('wc_fragments_refreshed removed_from_cart added_to_cart', function () { $('.woocommerce-cart-form__cart-item .quantity .qty').quantityDropdown(options); }); } }; /** * Quantity dropdown */ razzi.productQuantityDropdown = function () { if ($.fn.quantityDropdown && ! razzi.$body.hasClass('product-qty-number')) { // Quantity dropdown $('div.product, .razzi-sticky-add-to-cart').find('.quantity .qty').quantityDropdown(); $(document.body).on('wc_fragments_refreshed removed_from_cart added_to_cart', function () { $('div.product, .razzi-sticky-add-to-cart').find('.quantity .qty').quantityDropdown(); }); } }; /** * Change product quantity */ razzi.productQuantityNumber = function () { if( ! razzi.$body.hasClass('product-qty-number') ) { return; } razzi.$body.on('click', '.razzi-qty-button', function (e) { e.preventDefault(); var $this = $(this), $qty = $this.siblings('.qty'), current = 0, min = parseFloat($qty.attr('min')), max = parseFloat($qty.attr('max')), step = parseFloat($qty.attr('step')); if ($qty.val() !== '') { current = parseFloat($qty.val()); } else if ($qty.attr('placeholder') !== '') { current = parseFloat($qty.attr('placeholder')) } min = min ? min : 0; max = max ? max : current + 1; if ($this.hasClass('decrease') && current > min) { $qty.val(current - step); $qty.trigger('change'); } if ($this.hasClass('increase') && current < max) { $qty.val(current + step); $qty.trigger('change'); } }); }; razzi.updateQuantityAuto = function() { $( document.body ).on( 'change', 'table.cart .qty', function() { if (typeof razziData.update_cart_page_auto !== undefined && razziData.update_cart_page_auto == '1') { razzi.$body.find('button[name="update_cart"]').attr( 'clicked', 'true' ).prop( 'disabled', false ).attr( 'aria-disabled', false ); razzi.$body.find('button[name="update_cart"]').trigger('click'); } } ); $( document.body ).on( 'change', '.woocommerce-mini-cart .qty', function() { razzi.updateCartAJAX( this.value, this ); } ); } /** * Cross sell products carousel. */ razzi.crossSellProductsCarousel = function () { var $crossSells = $('.woocommerce .cross-sells'); if (!$crossSells.length) { return; } var $products = $crossSells.find('ul.products'); $products.wrap('
'); $products.after(''); $products.addClass('swiper-wrapper'); $products.find('li.product').addClass('swiper-slide'); new Swiper($crossSells.find('.linked-products-carousel'), { loop: false, spaceBetween: 30, scrollbar: { el: $crossSells.find('.swiper-scrollbar'), hide: false, draggable: true }, on: { init: function () { this.$el.css('opacity', 1); } }, breakpoints: { 300: { slidesPerView: razziData.mobile_portrait, slidesPerGroup: razziData.mobile_portrait, spaceBetween: 20, }, 480: { slidesPerView: razziData.mobile_landscape, slidesPerGroup: razziData.mobile_landscape, }, 768: { spaceBetween: 20, slidesPerView: 3, slidesPerGroup: 3 }, 992: { slidesPerView: 3, slidesPerGroup: 3 }, 1200: { slidesPerView: 4, slidesPerGroup: 4 } } }); }; // Filter Ajax razzi.blogFilterAjax = function () { razzi.$body.find('#razzi-posts__taxs-list').on('click', 'a', function (e) { e.preventDefault(); var btn = $(this), url = btn.attr('href'); razzi.$body.trigger('razzi_blog_filter_ajax', url, $(this)); razzi.$body.on('razzi_ajax_filter_request_success', function (e, btn) { $(this).addClass('selected'); razzi.postFound(); }); }); razzi.$body.on('razzi_blog_filter_ajax', function (e, url) { var $container = $('.razzi-posts__wrapper'), $categories = $('#razzi-posts__taxs-list'); $('.razzi-posts__loading').addClass('show'); if ('?' == url.slice(-1)) { url = url.slice(0, -1); } url = url.replace(/%2C/g, ','); history.pushState(null, null, url); if (razzi.ajaxXHR) { razzi.ajaxXHR.abort(); } razzi.ajaxXHR = $.get(url, function (res) { $container.replaceWith($(res).find('.razzi-posts__wrapper')); $categories.html($(res).find('#razzi-posts__taxs-list').html()); $('.razzi-posts__loading').removeClass('show'); $('.razzi-posts__wrapper .blog-wrapper').addClass('animated razziFadeInUp'); razzi.$body.trigger('razzi_ajax_filter_request_success', [res, url]); }, 'html'); }); }; razzi.blogLoadingAjax = function () { razzi.$body.on('click', '#razzi-blog-previous-ajax a', function (e) { e.preventDefault(); var $found = $('.razzi-posts__found'); if ($(this).data('requestRunning')) { return; } $(this).data('requestRunning', true); var $posts = $(this).closest('#primary'), $postList = $posts.find('.razzi-posts__list'), currentPosts = $postList.children('.blog-wrapper').length, $pagination = $(this).parents('.load-navigation'); $pagination.addClass('loading'); $.get( $(this).attr('href'), function (response) { var content = $(response).find('.razzi-posts__list').children('.blog-wrapper'), numberPosts = content.length + currentPosts, $pagination_html = $(response).find('.load-navigation').html(); $pagination.addClass('loading'); $pagination.html($pagination_html); $postList.append(content); $pagination.find('a').data('requestRunning', false); // Add animation class for (var index = 0; index < content.length; index++) { $(content[index]).css('animation-delay', index * 100 + 'ms'); } content.addClass('razziFadeInUp'); $found.find('.current-post').html(' ' + numberPosts); $pagination.removeClass('loading'); razzi.postFound(); } ); }); }; razzi.postFound = function (el) { var $found = $('.razzi-posts__found-inner'), $foundEls = $found.find('.count-bar'), $current = $found.find('.current-post').html(), $total = $found.find('.found-post').html(), pecent = ($current / $total) * 100; $foundEls.css('width', pecent + '%'); } razzi.postsRelated = function () { var $selector = $('.razzi-posts__related'), $el = $selector.find('.razzi-post__related-content'), $col = $el.data('columns'), options = { loop: false, autoplay: false, speed: 800, watchOverflow: true, spaceBetween: 30, pagination: { el: $selector.find('.swiper-pagination'), type: 'bullets', clickable: true }, breakpoints: { 0: { slidesPerView: 1, slidesPerGroup: 1 }, 380: { slidesPerView: 2, slidesPerGroup: 2 }, 992: { slidesPerView: 3, slidesPerGroup: 3 }, 1025: { slidesPerView: parseInt($col), slidesPerGroup: parseInt($col) }, } }; $selector.find('.blog-wrapper').addClass('swiper-slide'); new Swiper($el, options); }; // Toggle Menu Sidebar razzi.menuSideBar = function () { var $menuSidebar = $('#primary-menu.has-arrow, #topbar-menu.has-arrow, #hamburger-modal, #mobile-menu-modal, #mobile-category-menu-modal, .header-v6 .main-navigation'), $menuClick = $('#hamburger-modal, #mobile-menu-modal, #mobile-category-menu-modal, .header-v6 #primary-menu'); $menuSidebar.find('.nav-menu .menu-item-has-children').removeClass('active'); $menuSidebar.find('.nav-menu .menu-item-has-children > a').prepend(''); $menuClick.find('.click-item li.menu-item-has-children > a').on('click', function (e) { e.preventDefault(); $(this).closest('li').siblings().find('ul.sub-menu, ul.dropdown-submenu').slideUp(); $(this).closest('li').siblings().removeClass('active'); $(this).closest('li').children('ul.sub-menu, ul.dropdown-submenu').slideToggle(); $(this).closest('li').toggleClass('active'); return false; }); $menuClick.find('.click-icon li.menu-item-has-children > a > .toggle-menu-children').on('click', function (e) { e.preventDefault(); $(this).closest('li').siblings().find('ul.sub-menu, ul.dropdown-submenu').slideUp(); $(this).closest('li').siblings().removeClass('active'); $(this).closest('li').children('ul.sub-menu, ul.dropdown-submenu').slideToggle(); $(this).closest('li').toggleClass('active'); return false; }); // Active menu header layout 7 $('.header-v7 .main-navigation').find('li.menu-item > a').on('click', function (e) { e.preventDefault(); $(this).closest('li').siblings().removeClass('active'); $(this).closest('li').toggleClass('active'); }); }; /** * Close the topbar */ razzi.closeTopbar = function () { $(document.body).on('click', '.razzi-topbar__close', function (event) { event.preventDefault(); $('#topbar, #topbar-mobile').slideUp(); }); }; // Wishlist razzi.ajaxCounter = function() { $(document).on('added_to_wishlist removed_from_wishlist', function() { var ajax_url = razziData.ajax_url.toString().replace('%%endpoint%%', 'update_wishlist_count'); $.get( ajax_url, function(data) { $('.wishlist-counter').html(data.count); } ); }); } // Sticky Header razzi.stickyHeader = function () { if (!razzi.$body.hasClass('header-sticky')) { return; } var isHeaderTransparent = razzi.$body.hasClass('header-transparent'), $headerMinimized = $('#site-header-minimized'), heightHeaderMain = razzi.$header.find('.header-contents').hasClass('header-main') ? razzi.$header.find('.header-main').outerHeight() : 0, heightHeaderBottom = razzi.$header.find('.header-contents').hasClass('header-bottom') ? razzi.$header.find('.header-bottom').outerHeight() : 0, heightHeaderMobile = razzi.$header.find('.header-contents').hasClass('header-mobile') ? razzi.$header.find('.header-mobile').outerHeight() : 0, heightHeaderMinimized = heightHeaderMain + heightHeaderBottom; if( razzi.$header.hasClass('header-bottom-no-sticky') ) { heightHeaderMinimized = heightHeaderMain; } else if(razzi.$header.hasClass('header-main-no-sticky') ) { heightHeaderMinimized = heightHeaderBottom; } if( razzi.$body.hasClass('header-v6') ) { heightHeaderMinimized = heightHeaderBottom; } if( isHeaderTransparent ) { razzi.$header.addClass('has-transparent'); } razzi.$window.on('scroll', function () { var scroll = razzi.$window.scrollTop(), scrollTop = razzi.$header.outerHeight(true), hBody = razzi.$body.outerHeight(true); if (hBody <= scrollTop + razzi.$window.height()) { return; } if (scroll > scrollTop) { razzi.$header.addClass('minimized'); $('#razzi-header-minimized').addClass('minimized'); razzi.$body.addClass('sticky-minimized'); if (isHeaderTransparent) { razzi.$body.removeClass('header-transparent'); } if (razzi.$window.width() > 992) { $headerMinimized.css('height', heightHeaderMinimized); } else { $headerMinimized.css('height', heightHeaderMobile); } } else { razzi.$header.removeClass('minimized'); $('#razzi-header-minimized').removeClass('minimized'); razzi.$body.removeClass('sticky-minimized'); if (isHeaderTransparent) { razzi.$body.addClass('header-transparent'); } $headerMinimized.removeAttr('style'); } }); }; // add wishlist razzi.addWishlist = function () { razzi.$body.on('click', 'a.add_to_wishlist', function () { $(this).addClass('loading'); }); razzi.$body.on('added_to_wishlist', function (e, $el_wrap) { e.preventDefault(); $('ul.products li.product .yith-wcwl-add-button a').removeClass('loading'); }); // update wishlist count razzi.$body.on('added_to_wishlist removed_from_wishlist cart_page_refreshed', function () { var ajax_url = razziData.ajax_url.toString().replace('%%endpoint%%', 'update_wishlist_item'); $.post( ajax_url, function (data) { if(data == 0) { razzi.$header.find('.header-wishlist .wishlist-counter').addClass('hidden'); razzi.$body.find('.rz-navigation-bar .wishlist-counter').addClass('hidden'); } else { razzi.$header.find('.header-wishlist .wishlist-counter').removeClass('hidden'); razzi.$body.find('.rz-navigation-bar .wishlist-counter').removeClass('hidden'); } razzi.$header.find('.header-wishlist .wishlist-counter').html(data); razzi.$body.find('.rz-navigation-bar .wishlist-counter').html(data); } ); }); }; // Product loop hover razzi.productLoopHover = function () { if (typeof razziData.product_loop_layout === 'undefined') { return; } if (razziData.product_loop_layout !== '8') { return; } var on_mobile = false; razzi.$window.on('resize', function () { if (razzi.$window.width() < 992) { on_mobile = true; } else { on_mobile = false; } }).trigger('resize'); razzi.$body.on('mouseover', '.product-inner', function () { if (on_mobile) { return; } if ($(this).hasClass('has-transform')) { return; } if ($(this).closest('ul.products').hasClass('shortcode-element')) { return; } var $product_bottom = $(this).find('.product-loop__buttons'), product_bottom_height = $product_bottom.outerHeight(), $product_summary = $(this).find('.product-summary'); $(this).addClass('has-transform'); $product_summary.css({ '-webkit-transform': "translateY(-" + product_bottom_height + "px)", 'transform': "translateY(-" + product_bottom_height + "px)" }); }); $(document.body).on('tawcvs_initialized', function (e, form) { if (form.hasClass('variations_form_loop') && $.fn.tooltip) { form.find('.swatch').tooltip({disabled: true}); } }); }; // Product loop hover razzi.productLoopFormAJAX = function () { if (typeof razziData.product_loop_layout === 'undefined') { return; } if (typeof razziData.product_loop_variation_ajax === 'undefined') { return; } if (razziData.product_loop_layout !== '9') { return; } if (razziData.product_loop_variation_ajax !== '1') { return; } razzi.$body.on('click', '.product-quick-shop-button', function (e) { e.preventDefault(); if ($(this).hasClass('has-content')) { return; } $(this).addClass('has-content'); var $product_id = $(this).data('product_id'), $product_inner = $(this).closest('li.product').find('.product-inner'), $product_form = $(this).closest('li.product').find('.product-loop__form'); $product_inner.addClass('loading'); $.ajax({ url: razziData.ajax_url.toString().replace('%%endpoint%%', 'razzi_product_loop_form'), type: 'POST', data: { nonce: razziData.nonce, product_id: $product_id }, success: function (response) { if (!response || response.data === '') { return; } $product_form.prepend(response.data); var $variations = $product_form.find('.variations_form'); if (typeof $.fn.wc_variation_form !== 'undefined') { $variations.each(function () { $(this).wc_variation_form(); }); } $( document.body ).trigger( 'init_variation_swatches'); setTimeout(function () { $product_inner.removeClass('loading').addClass('show-variations_form'); }, 400); } }) }); }; razzi.productLoopATCForm = function () { if (typeof razziData.product_loop_variation === 'undefined') { return; } if (razziData.product_loop_variation !== '1') { return; } razzi.$body.on('click', '.product-close-variations-form', function (e) { e.preventDefault(); $(this).closest('.product-inner').removeClass('show-variations_form'); }); razzi.$body.on('click', '.product-quick-shop-button', function (e) { e.preventDefault(); if (typeof razziData.product_loop_variation_ajax === 'undefined') { $(this).closest('.product-inner').addClass('show-variations_form'); } else if ($(this).hasClass('has-content')) { $(this).closest('.product-inner').addClass('show-variations_form'); } }); razzi.$body.on('click', 'a.product_type_variable', function (e) { e.preventDefault(); $(this).closest('li.product').find('.variations_form .single_add_to_cart_button').trigger('click'); }); razzi.$body.on('click', 'li.product .variations_form .single_add_to_cart_button', function (e) { e.preventDefault(); var $this = $(this), $cartForm = $this.closest('.variations_form'), $cartButtonLoading = $this.closest('li.product').find('a.product_type_variable'); if ($(this).is('.disabled')) { return; } razzi.addToCartFormAJAX($this, $cartForm, $cartButtonLoading); return false; }); }; razzi.addToCartSingleAjax = function () { var $selector = $('div.product, .razzi-sticky-add-to-cart'); if ($selector.length < 1) { return; } if (!$selector.hasClass('product-add-to-cart-ajax')) { return; } $selector.find('form.cart').on('click', '.single_add_to_cart_button', function (e) { var $el = $(this), $cartForm = $el.closest('form.cart'); if ($el.closest('.product').hasClass('product-type-external')) { return; } if ($cartForm.hasClass('buy-now-clicked')) { return; } if ($el.is('.disabled')) { return; } if ($cartForm.length > 0) { e.preventDefault(); } else { return; } razzi.addToCartFormAJAX($el, $cartForm, $el); }); }; razzi.addToCartFormAJAX = function ($cartButton, $cartForm, $cartButtonLoading) { if ($cartButton.data('requestRunning')) { return; } $cartButton.data('requestRunning', true); var found = false; $cartButtonLoading.addClass('loading'); if (found) { return; } found = true; var formData = $cartForm.serializeArray(), formAction = $cartForm.attr('action'); if ($cartButton.val() != '') { formData.push({name: $cartButton.attr('name'), value: $cartButton.val()}); } $(document.body).trigger('adding_to_cart', [$cartButton, formData]); $.ajax({ url: formAction, method: 'post', data: formData, error: function (response) { window.location = formAction; }, success: function (response) { if (!response) { window.location = formAction; } if (typeof wc_add_to_cart_params !== 'undefined') { if (wc_add_to_cart_params.cart_redirect_after_add === 'yes') { window.location = wc_add_to_cart_params.cart_url; return; } } var $message = '', className = 'info'; if ($(response).find('.woocommerce-message').length > 0) { $(document.body).trigger('wc_fragment_refresh'); } else { if (!$.fn.notify) { return; } var $checkIcon = '', $closeIcon = ''; if ($(response).find('.woocommerce-error').length > 0) { $message = $(response).find('.woocommerce-error').html(); className = 'error'; $checkIcon = ''; } else if ($(response).find('.woocommerce-info').length > 0) { $message = $(response).find('.woocommerce-info').html(); } $.notify.addStyle('razzi', { html: '