' ).attr( 'id', 'yith-wcwl-popup-message' ).html( '
' ).hide() );
}*/
// shop horizontal filter
$( document ).on( 'click', '.porto-product-filters-toggle a', function( e ) {
e.preventDefault();
$( this ).closest( '.porto-product-filters-toggle' ).toggleClass( 'opened' );
var $products_wrapper = $( this ).closest( '#main' ).find( '.main-content' ).find( 'ul.products' ), offset, $main = $( this ).closest( '#main' ).find( '.main-content-wrap' );
$main.toggleClass( 'opened' );
if ( $main.hasClass( 'opened' ) ) {
offset = -1;
} else {
offset = 1;
}
if ( $products_wrapper.hasClass( 'grid' ) ) {
var cols_lg_index = 0, cols_md_index = 0, width_lg_index = 0, width_md_index = 0;
for ( var i = 1; i <= 8; i++ ) {
if ( !cols_lg_index && $products_wrapper.hasClass( 'pcols-lg-' + i ) ) {
cols_lg_index = i;
if ( i + offset >= 1 ) {
$products_wrapper.removeClass( 'pcols-lg-' + i );
$products_wrapper.addClass( 'pcols-lg-' + ( i + offset ) );
}
}
if ( !cols_md_index && $products_wrapper.hasClass( 'pcols-md-' + i ) ) {
cols_md_index = i;
if ( i + offset >= 1 ) {
$products_wrapper.removeClass( 'pcols-md-' + i );
if ( offset === -1 ) {
$products_wrapper.addClass( 'pcols-sm-' + i );
}
$products_wrapper.addClass( 'pcols-md-' + ( i + offset ) );
}
}
if ( !width_lg_index && $products_wrapper.hasClass( 'pwidth-lg-' + i ) ) {
width_lg_index = i;
if ( i + offset >= 1 ) {
$products_wrapper.removeClass( 'pwidth-lg-' + i );
$products_wrapper.addClass( 'pwidth-lg-' + ( i + offset ) );
}
}
if ( !width_md_index && $products_wrapper.hasClass( 'pwidth-md-' + i ) ) {
width_md_index = i;
if ( i + offset >= 1 ) {
$products_wrapper.removeClass( 'pwidth-md-' + i );
$products_wrapper.addClass( 'pwidth-md-' + ( i + offset ) );
}
}
}
}
theme.requestTimeout( function() {
$( window ).trigger( 'scroll' );
// Update Carousel
$( document ).find( '.owl-carousel' ).each( function( e ) {
var $this = $( this );
if ( $this.data( 'owl.carousel' ) ) {
$this.trigger( 'refresh.owl.carousel' );
}
} );
// Update Swiper
$( document ).find( '.swiper-container' ).each( function( e ) {
var $this = $( this ),
$instance = $this.data( 'swiper' );
if ( $instance ) {
$instance.update();
}
} );
}, 300 );
if ( $main.hasClass( 'opened' ) ) {
$.cookie( 'porto_horizontal_filter', 'opened' );
} else {
$.cookie( 'porto_horizontal_filter', 'closed' );
}
theme.refreshStickySidebar( true );
return false;
} );
if ( $.cookie && 'opened' == $.cookie( 'porto_horizontal_filter' ) && $( '#main .porto-products-filter-body' ).length && !theme.isTablet() ) {
$( '.porto-product-filters-toggle a' ).trigger( 'click' );
$( '#main .porto-products-filter-body [data-plugin-sticky]:not(.manual)' ).addClass( 'manual' );
setTimeout( function() {
var $obj = $( '#main .porto-products-filter-body [data-plugin-sticky].manual' ),
pluginOptions = $obj.data( 'plugin-options' );
$obj.removeClass( 'manual' ).themeSticky( pluginOptions );
theme.requestTimeout( function() {
$( window ).trigger( 'scroll' );
}, 100 );
}, 500 );
}
$( document ).on( 'click', '.porto-product-filters.style2 .widget-title', function( e ) {
e.preventDefault();
if ( $( this ).next().is( ':hidden' ) ) {
$( '.porto-product-filters.style2 .widget-title' ).next().hide();
$( '.porto-product-filters.style2 .widget' ).removeClass( 'opened' );
$( this ).next().show();
$( this ).next().find( 'input[type="text"]:first-child' ).focus();
} else {
$( this ).next().hide();
}
$( this ).parent().toggleClass( 'opened' );
return false;
} );
$( 'body' ).on( 'click', function( e ) {
if ( !$( e.target ).is( '.porto-product-filters' ) && !$( e.target ).is( '.porto-product-filters *' ) ) {
$( '.porto-product-filters.style2 .widget-title' ).next().hide();
$( '.porto-product-filters.style2 .widget' ).removeClass( 'opened' );
}
} );
// Perform AJAX login on form submit
$( 'body' ).on( 'click', '#login-form-popup form .woocommerce-Button', function( e ) {
var $this = $( this ),
$form = $this.closest( 'form' ),
isLogin = $this.hasClass( 'login-btn' );
if ( !isLogin && !$this.hasClass( 'register-btn' ) ) {
isLogin = $form.hasClass( 'login' );
}
$form.find( '#email' ).val( $form.find( '#username' ).val() );
$form.find( 'p.status' ).show().text( 'Please wait...' ).addClass( 'loading' );
$form.find( 'button[type=submit]' ).attr( 'disabled', 'disabled' );
$.ajax( {
type: 'POST',
dataType: 'json',
url: theme.ajax_url,
data: $form.serialize() + '&action=porto_account_login_popup_' + ( isLogin ? 'login' : 'register' ),
success: function( data ) {
$form.find( 'p.status' ).html( data.message.replace( '/
/s', '' ) ).removeClass( 'loading' );
$form.find( 'button[type=submit]' ).removeAttr( 'disabled' );
if ( data.loggedin === true ) {
window.location.reload();
}
}
} );
e.preventDefault();
} );
// shortcodes
var $ajax_tab_cache = {};
$( document ).on( 'click', '.porto-products.show-category .product-categories a', function( e ) {
e.preventDefault();
var $this = $( this ), $form = $this.closest( '.porto-products' ).find( '.pagination-form' ), id = $this.closest( '.porto-products' ).attr( 'id' ), group = [];
$( this ).parent().siblings().removeClass( 'current' );
$( this ).parent().addClass( 'current' );
if ( typeof $this.data( 'sort_id' ) != 'undefined' ) {
$form.find( 'input[name="orderby"]' ).val( $this.data( 'sort_id' ) );
group = $this.data( 'sort_id' );
$form.find( 'input[name="category"]' ).val( '' );
}
if ( typeof $this.data( 'cat_id' ) != 'undefined' ) {
if ( typeof $this.data( 'sort_id' ) == 'undefined' ) {
$form.find( 'input[name="orderby"]' ).val( $form.find( 'input[name="original_orderby"]' ).val() );
group = $form.find( 'input[name="original_orderby"]' ).val();
}
if ( typeof $form.data( 'original_cat_id' ) == 'undefined' ) {
$form.data( 'original_cat_id', $form.find( 'input[name="category"]' ).val() );
group = $form.find( 'input[name="category"]' ).val();
}
if ( $this.data( 'cat_id' ) ) {
$form.find( 'input[name="category"]' ).val( $this.data( 'cat_id' ) );
group = $this.data( 'cat_id' );
} else {
if ( $form.data( 'original_cat_id' ) ) {
$form.find( 'input[name="category"]' ).val( $form.data( 'original_cat_id' ) );
group = $form.data( 'original_cat_id' );
} else {
$form.find( 'input[name="category"]' ).val( '' );
group = '';
}
}
}
var data = $form.serialize() + '&product-page=1&action=porto_woocommerce_shortcodes_products&nonce=' + js_porto_vars.porto_nonce;
$this.closest( '.porto-products' ).find( 'ul.products' ).trigger( 'porto_update_products', [data, '', $this, id, group] );
} );
$( document ).on( 'click', '.porto-products .page-numbers a', function( e ) {
var $this = $( this ), pagination_style,
$shop_container = $this.closest( '.porto-products' ).find( 'ul.products' ),
cur_page = $shop_container.data( 'cur_page' ),
max_page = $shop_container.data( 'max_page' ),
$form = $this.closest( '.porto-products' ).find( '.pagination-form' );
e.preventDefault();
if ( $this.closest( '.pagination' ).hasClass( 'load-more' ) ) {
if ( !cur_page || !max_page || ++cur_page > max_page ) {
return;
}
pagination_style = 'load_more';
$this.data( 'text', $this.text() );
$this.text( js_porto_vars.loader_text );
} else {
var url = new RegExp( "product-page(=|/)([^(&|/)]*)", "i" ).exec( this.href );
cur_page = url && unescape( url[2] ) || "";
pagination_style = 'default';
}
var page_var = cur_page ? '&product-page=' + escape( cur_page ) : '', data = $form.serialize() + page_var + '&action=porto_woocommerce_shortcodes_products&nonce=' + js_porto_vars.porto_nonce;
$shop_container.trigger( 'porto_update_products', [data, pagination_style, $this] );
if ( 'default' == pagination_style ) {
theme.scrolltoContainer( $shop_container );
}
} );
$( document ).on( 'porto_update_products', 'ul.products', function( e, data, pagination_style, $obj, id, group ) {
var $this = $( this );
// ajax tab
if ( undefined == $ajax_tab_cache[id] || -1 == Object.keys( $ajax_tab_cache[id] ).indexOf( group ) ) {
porto_ajax_load_products( $this, data, pagination_style, $ajax_tab_cache, id, group );
} else {
var response = $ajax_tab_cache[id][group];
//animation
$this.css( 'opacity', 0 );
$this.animate(
{
'opacity': 1,
},
400,
function() {
$this.css( 'opacity', '' );
}
);
porto_ajax_load_products_success( $this, response, pagination_style );
}
} );
// initialize woocommerce actions after skeleton loading
var skeletonLoadingTrigger;
$( '.skeleton-loading' ).on( 'skeleton-loaded', function() {
var $this = $( this );
if ( skeletonLoadingTrigger ) {
theme.deleteTimeout( skeletonLoadingTrigger );
}
porto_woocommerce_variations_init( $this );
// yith wishlist pro compatibility
if ( $this.hasClass( 'products' ) || $this.hasClass( 'product' ) ) {
$( document ).trigger( 'yith_infs_added_elem' );
}
skeletonLoadingTrigger = theme.requestTimeout( function() {
porto_woocommerce_init();
if ( $( 'body' ).hasClass( 'single-product' ) ) {
theme.WooVariationForm.init();
var $image_slider = $( '.product-image-slider' );
if ( $image_slider.length && $image_slider.data( 'owl.carousel' ) ) {
$image_slider.trigger( 'refresh.owl.carousel' );
} else {
theme.WooProductImageSlider.initialize();
}
$( '.wc-tabs-wrapper, .woocommerce-tabs, #rating' ).trigger( 'init' );
// compatibility issue with Yith WooCommerce Booking form
if ( $( document.body ).hasClass( 'yith-booking' ) ) {
$( document ).trigger( 'yith-wcbk-init-booking-form' );
}
}
// refresh cart content
if ( $this.find( '.widget_shopping_cart_content' ).length ) {
$( document.body ).trigger( 'wc_fragment_refresh' );
}
}, 100 );
} );
} );
$( document ).on( 'porto_theme_init', function() {
// sticky add to cart
var $sticky_product_obj = $( '.single-product .sticky-product' ),
is_elementor_editor = $( document.body ).hasClass( 'elementor-editor-active' ),
$sticky_product_form;
var init_sticky_add_to_cart_fn = function( $sticky_product_obj, is_elementor_editor ) {
if ( is_elementor_editor && elementorFrontend && elementorFrontend.hooks ) {
elementorFrontend.hooks.addAction( 'frontend/element_ready/porto_cp_addcart_sticky.default', function( $obj ) {
$sticky_product_obj = $( '.single-product .sticky-product' );
window.dispatchEvent( new Event( 'scroll' ) );
} );
}
$sticky_product_form = $( 'form.cart:visible' ).eq(0);
window.addEventListener( 'scroll', function() {
var scrollTop = $( window ).scrollTop(),
offset = theme.adminBarHeight() + ( theme.StickyHeader.sticky_height > 1 ? theme.StickyHeader.sticky_height : 0 ),
prevScrollPos = $sticky_product_obj.data('prev-pos') ? $sticky_product_obj.data('prev-pos') : 0;
if ( $sticky_product_form.length && $sticky_product_form.offset().top + $sticky_product_form.height() / 2 <= scrollTop + offset ) {
if ( $( '.page-wrapper' ).hasClass( 'sticky-scroll-up' ) && ! $( 'html' ).hasClass( 'porto-search-opened' ) && $sticky_product_obj.hasClass( 'pos-top' ) ) {
if ( scrollTop >= prevScrollPos ) {
$sticky_product_obj.addClass('scroll-down');
} else {
$sticky_product_obj.removeClass('scroll-down');
}
var scrollUpOffset = - theme.StickyHeader.sticky_height;
if ( 'undefined' == typeof ( theme.StickyHeader.sticky_height ) ) {
$sticky_product_obj.data( 'prev-pos', 0 );
} else {
// The transition of Sticky isn't working in this area
var $transitionOffset = ( offset > 100 ) ? offset : 100;
if ( $( 'form.cart' ).offset().top + $sticky_product_obj.outerHeight() + $transitionOffset < scrollTop + offset + scrollUpOffset ) {
$sticky_product_obj.addClass( 'sticky-ready' );
} else {
$sticky_product_obj.removeClass( 'sticky-ready' );
}
$sticky_product_obj.data( 'prev-pos', scrollTop );
}
}
var porto_progress_obj = $( '.porto-scroll-progress.fixed-top.fixed-under-header' );
if ( porto_progress_obj.length > 0 ) {
offset += porto_progress_obj.height();
}
$sticky_product_obj.removeClass( 'hide' );
if ( !$sticky_product_obj.hasClass( 'pos-bottom' ) ) {
$sticky_product_obj.css( 'top', offset );
} else if ( $sticky_product_obj.hasClass( 'show-mobile' ) || ( ! $sticky_product_obj.hasClass( 'show-mobile' ) && $( window ).width() >= 768 ) ) {
$( 'body' ).css( 'padding-bottom', $sticky_product_obj.outerHeight() );
}
} else {
$sticky_product_obj.addClass( 'hide' );
if ( $sticky_product_obj.hasClass( 'pos-bottom' ) && ( $sticky_product_obj.hasClass( 'show-mobile' ) || ( ! $sticky_product_obj.hasClass( 'show-mobile' ) && $( window ).width() >= 768 ) ) ) {
$( 'body' ).css( 'padding-bottom', '' );
}
}
}, { passive: true } );
$sticky_product_obj.find( '.add-to-cart .button' ).on( 'click', function( e ) {
e.preventDefault();
if ( $sticky_product_obj.find( '.add-to-cart .qty' ).length ) {
$( '.single-product form .quantity .qty' ).filter(function() {
if ( $( this ).closest( '.product-col' ).length ) {
return false;
}
return true;
}).val( $sticky_product_obj.find( '.add-to-cart .qty' ).val() );
}
$( '.single-product form .single_add_to_cart_button' ).filter(function() {
if ( $( this ).closest( '.product-col' ).length ) {
return false;
}
return true;
}).eq(0).trigger( 'click' );
} );
$( '.single-product .entry-summary .quantity' ).clone().prependTo( '.single-product .sticky-product .add-to-cart' );
var origin_img = $sticky_product_obj.find( '.sticky-image img' ).data( 'oi' ) ? $sticky_product_obj.find( '.sticky-image img' ).data( 'oi' ) : $sticky_product_obj.find( '.sticky-image img' ).attr( 'src' ),
origin_price = $sticky_product_obj.find( '.price' ).html(),
origin_stock = $sticky_product_obj.find( '.availability' ).html(),
is_variation = false;
$( document ).on( 'found_variation reset_data', '.variations_form', function( e, obj ) {
if ( $( e.currentTarget ).closest( '.product-col' ).length == 0 ) {
if ( obj ) {
is_variation = true;
$sticky_product_obj.find( '.sticky-image img' ).attr( 'src', obj.image_thumb ? obj.image_thumb : origin_img );
$sticky_product_obj.find( '.price' ).replaceWith( obj.price_html );
$sticky_product_obj.find( '.availability' ).html( obj.availability_html ? obj.availability_html : origin_stock );
} else if ( is_variation ) {
is_variation = false;
$sticky_product_obj.find( '.sticky-image img' ).attr( 'src', origin_img );
$sticky_product_obj.find( '.price' ).html( origin_price );
$sticky_product_obj.find( '.availability' ).html( origin_stock );
}
}
} );
};
if ( $sticky_product_obj.length || is_elementor_editor ) {
init_sticky_add_to_cart_fn( $sticky_product_obj, is_elementor_editor );
} else {
$( document.body ).on( 'porto_elementor_editor_init', function() {
var $sticky_product_obj = $( '.single-product .sticky-product' ),
is_elementor_editor = $( document.body ).hasClass( 'elementor-editor-active' );
if ( $sticky_product_obj.length || is_elementor_editor ) {
init_sticky_add_to_cart_fn( $sticky_product_obj, is_elementor_editor );
}
} );
}
// sticky filter on mobile
if ( 1 === $( '.shop-loop-before' ).length && $( '.mobile-sidebar' ).length ) {
var porto_progress_obj = $( '.porto-scroll-progress.fixed-top.fixed-under-header' ),
porto_progress_height = 0;
if ( porto_progress_obj.length > 0 ) {
var flag = false;
if ( porto_progress_obj.is( ':hidden' ) ) {
porto_progress_obj.show();
flag = true;
}
porto_progress_height = porto_progress_obj.height();
if ( flag ) {
porto_progress_obj.hide();
}
} else {
porto_progress_height = 0;
}
var init_filter_sticky = function() {
var $obj = $( '.shop-loop-before' ),
prevScrollPos = $obj.data('prev-pos') ? $obj.data('prev-pos') : 0,
scrollUpOffset = 0,
$pageWrapper = $( '.page-wrapper' );
if ( 'none' == $obj.css( 'display' ) ) {
// Found Nothing
return;
}
if ( !$obj.prev( '.filter-placeholder' ).length ) {
$( '' ).insertBefore( $obj );
}
var $ph = $obj.prev( '.filter-placeholder' ),
scrollTop = $( window ).scrollTop(),
offset = theme.adminBarHeight() + theme.StickyHeader.sticky_height + porto_progress_height - 1,
objHeight = $obj.outerHeight() + parseInt( $obj.css( 'margin-bottom' ) );
if ( $( '.page-wrapper' ).hasClass( 'sticky-scroll-up' ) ) {
if ( scrollTop >= prevScrollPos ) {
$obj.addClass('scroll-down');
} else {
$obj.removeClass('scroll-down');
}
// Header is scroll-up Sticky Type
scrollUpOffset = - theme.StickyHeader.sticky_height;
if ( 'undefined' == typeof ( theme.StickyHeader.sticky_height ) ) {
$obj.data( 'prev-pos', 0 );
} else {
// The transition of Sticky isn't working in this area
var $transitionOffset = ( offset > 100 ) ? offset : 100;
if ( $ph.offset().top + objHeight + $transitionOffset < scrollTop + offset + scrollUpOffset ) {
$obj.addClass( 'sticky-ready' );
} else {
$obj.removeClass( 'sticky-ready' );
}
$obj.data( 'prev-pos', scrollTop );
}
}
// if ( $( 'html.filter-sidebar-opened' ).length ) {
// $ph.css( 'height', '' );
// return;
// }
if ( ( $ph.offset().top + objHeight < scrollTop + offset + scrollUpOffset ) ) {
if ( ! $pageWrapper.hasClass( 'sticky-scroll-up' ) || ( $pageWrapper.hasClass( 'sticky-scroll-up' ) && 0 !== prevScrollPos ) ) {
$ph.css( 'height', objHeight );
$obj.css( 'top', offset );
$obj.addClass( 'sticky' );
}
} else {
$ph.css( 'height', '' );
$obj.removeClass( 'sticky' ).css( 'top', '' );
}
};
if ( window.innerWidth < 992 ) {
window.removeEventListener( 'scroll', init_filter_sticky );
window.addEventListener( 'scroll', init_filter_sticky, { passive: true } );
init_filter_sticky();
}
var request_timer = null,
old_win_width = window.innerWidth;
$( window ).on( 'resize', function() {
if ( old_win_width != window.innerWidth ) {
if ( request_timer ) {
theme.deleteTimeout( request_timer );
request_timer = false;
}
if ( window.innerWidth < 992 ) {
request_timer = theme.requestTimeout( function() {
window.removeEventListener( 'scroll', init_filter_sticky );
window.addEventListener( 'scroll', init_filter_sticky, { passive: true } );
$( window ).trigger( 'scroll' );
}, 100 );
} else {
window.removeEventListener( 'scroll', init_filter_sticky );
$( '.shop-loop-before' ).removeClass( 'sticky' ).css( 'top', '' ).prev( '.filter-placeholder' ).css( 'height', '' );
}
if ( $sticky_product_obj.length ) {
$sticky_product_form = $( 'form.cart:visible' ).eq(0);
}
old_win_width = window.innerWidth;
}
} );
}
} );
// cart page accordion
$( '.cart-v2 .cart_totals .accordion-toggle.out' ).removeClass( 'out' );
$( document ).ajaxComplete( function( event, xhr, options ) {
$( '.cart-v2 .cart_totals .accordion-toggle.out' ).each( function() {
if ( $( $( this ).attr( 'href' ) ).length && $( $( this ).attr( 'href' ) ).is( ':hidden' ) ) {
$( this ).removeClass( 'collapsed' );
$( $( this ).attr( 'href' ) ).addClass( 'show' );
}
} );
} );
// porto products filter element
$( '.porto_products_filter_form .btn-submit' ).on( 'click', function( e ) {
e.preventDefault();
var data = $( this ).closest( 'form' ).serializeArray(),
submit_data = '';
for ( var i in data ) {
var param = data[i];
if ( param.value ) {
if ( submit_data ) {
submit_data += '&';
}
submit_data += param.name + '=' + param.value;
if ( 'min_price' == param.name ) {
var max_price = $( this ).closest( 'form' ).find( '.porto_dropdown_price_range option:selected' ).data( 'maxprice' );
if ( max_price ) {
submit_data += '&max_price=' + max_price;
}
}
}
}
var action_url = $( this ).closest( 'form' ).attr( 'action' );
location.href = action_url + ( -1 === action_url.indexOf( '?' ) ? '?' : '&' ) + submit_data;
} );
// yith wishlist
if ( $( '.wishlist_table.responsive' ).length ) {
$( window ).on( 'resize', function() {
var media = window.matchMedia( '(max-width: 768px)' ),
$wishlist_table = $( '.wishlist_table.responsive' );
if ( $wishlist_table.hasClass( 'traditional' ) ) {
if ( media.matches ) {
$wishlist_table.addClass( 'mobile' );
} else {
$wishlist_table.removeClass( 'mobile' );
}
}
} );
}
// pre-order
if ( js_porto_vars.pre_order ) {
var porto_pre_order = {
init: function() {
this.$add_to_cart_btn = $( '.product-summary-wrap .single_add_to_cart_button:not(.wpcbn-btn)' );
this.add_to_cart_label = this.$add_to_cart_btn.html();
$( '.product-summary-wrap form.variations_form' ).on( 'show_variation', function( e, v, p ) {
if ( v.porto_pre_order ) {
porto_pre_order.$add_to_cart_btn.html( v.porto_pre_order_label );
if ( v.porto_pre_order_date ) {
$( this ).find( '.woocommerce-variation-description' ).append( v.porto_pre_order_date );
}
} else {
porto_pre_order.$add_to_cart_btn.html( porto_pre_order.add_to_cart_label );
}
} ).on( 'hide_variation', function() {
porto_pre_order.$add_to_cart_btn.html( porto_pre_order.add_to_cart_label );
} );
}
};
if ( $( 'div.product.skeleton-loading' ).length ) {
$( 'div.product.skeleton-loading' ).on( 'skeleton-loaded', function() {
porto_pre_order.init();
} );
} else {
porto_pre_order.init();
}
}
// refresh yith wishlist
if ( $( '#header .my-wishlist .wishlist-count' ).length ) {
$( document.body ).on( 'added_to_wishlist removed_from_wishlist added_to_cart', function( e ) {
var $obj = $( '#header .my-wishlist .wishlist-count' );
if ( $obj.text() ) {
$.ajax( {
type: 'POST',
dataType: 'json',
url: theme.ajax_url,
data: {
action: 'porto_refresh_wishlist_count',
nonce: js_porto_vars.porto_nonce,
},
success: function( response ) {
if ( response || 0 === response ) {
$obj.addClass( 'count-updating' ).text( Number( response ) );
setTimeout( function() {
$obj.removeClass( 'count-updating' );
}, 1000 );
}
}
} );
}
} );
}
// fix contact form 7 role="alert" issue in cart page
if ( $( document.body ).hasClass( 'woocommerce-cart' ) && $( '.wpcf7 .screen-reader-response' ).length ) {
$( '.wpcf7 .screen-reader-response' ).attr( 'role', '' );
}
// fix dokan search vendor
$( '#dokan-store-listing-filter-form-wrap .store-search-input' ).on( 'keydown', function( e ) {
if ( e.which && event.which == 13 ) {
$( this ).closest( 'form' ).find( '#apply-filter-btn' ).trigger( 'click' );
e.preventDefault();
}
} );
// add spinner to block
if ( $.fn.block ) {
var funcBlock = $.fn.block;
$.fn.block = function( opts ) {
if ( this.hasClass( 'yith-wcwl-add-to-wishlist' ) ) {
this.children().addClass( 'pe-none opacity-6' );
return this;
}
if ( this.is( '.woocommerce-checkout' ) ) {
this.append( '' );
}
return funcBlock.call( this, opts );
}
var funcUnblock = $.fn.unblock;
$.fn.unblock = function( opts ) {
if ( this.hasClass( 'yith-wcwl-add-to-wishlist' ) ) {
this.children().removeClass( 'pe-none opacity-6' );
return this;
}
funcUnblock.call( this, opts );
this.is( '.processing' ) || ( this.is( '.woocommerce-checkout' ) && this.children( '.loader-container' ).remove() );
return this;
}
}
$( 'body' ).on( 'click', '.single_add_to_cart_button.scroll-to-sticky', function (e) {
$( 'html, body' ).animate(
{ scrollTop: $( 'form.cart' ).offset().top - 200 }
);
} )
} )( window.theme, jQuery );
// Compare
( function( theme, $ ) {
// remove margin-right
$( 'body' ).on( 'click', '.yith_woocompare_colorbox #cboxClose, #cboxOverlay', function() {
$( 'html' ).css( { 'overflow': '', 'margin-right': '' } );
} );
} )( window.theme, window.jQuery );
} )();
function porto_woocommerce_init( $wrap ) {
'use strict';
if ( !$wrap ) {
$wrap = jQuery( document.body );
}
// Woo Widget Toggle
( function( $ ) {
if ( $.fn.themeWooWidgetToggle ) {
$( function() {
$wrap.find( '.widget_filter_by_brand, .widget_product_categories, .widget_price_filter, .widget_layered_nav, .widget_layered_nav_filters, .widget_rating_filter, .widget-woof, .porto_widget_price_filter, #wcfmmp-store .widget.sidebar-box, #wcfmmp-store-lists-sidebar .sidebar-box' ).find( '.widget-title' ).each( function() {
var $this = $( this ),
opts;
var pluginOptions = $this.data( 'plugin-options' );
if ( pluginOptions )
opts = pluginOptions;
$this.themeWooWidgetToggle( opts );
} );
} );
}
// Woo Widget Accordion
if ( $.fn.themeWooWidgetAccordion ) {
$( function() {
$wrap.find( '.widget_filter_by_brand, .widget_product_categories, .widget_price_filter, .widget_layered_nav, .widget_layered_nav_filters, .widget_rating_filter, .widget-woof, #wcfmmp-store .widget.sidebar-box, #wcfmmp-store-lists-sidebar .sidebar-box' ).each( function() {
var $this = $( this ),
opts;
var pluginOptions = $this.data( 'plugin-options' );
if ( pluginOptions )
opts = pluginOptions;
$this.themeWooWidgetAccordion( opts );
} );
} );
}
// Woo Products Slider
if ( $.fn.themeWooProductsSlider ) {
$( function() {
var $direct_carousels = $wrap.find( '.products-slider:not(.manual)' ).filter( function() {
if ( $( this ).closest( '.porto-carousel:not(.owl-loaded)' ).length ) {
return false;
}
return true;
} );
var $parent_carousel = $wrap.find( '.porto-carousel:not(.owl-loaded)' ).filter( function() {
if ( $( this ).find( '.products-slider:not(.manual)' ).length ) {
return true;
}
return false;
} );
if ( $parent_carousel.length ) {
$parent_carousel.one( 'initialized.owl.carousel', function() {
$( this ).find( '.products-slider:not(.manual)' ).each( function() {
var $this = $( this );
$this.themeWooProductsSlider( $this.data( 'plugin-options' ) );
} );
} );
}
$direct_carousels.each( function() {
var $this = $( this ),
opts;
var pluginOptions = $this.data( 'plugin-options' );
if ( pluginOptions )
opts = pluginOptions;
setTimeout( function() {
$this.themeWooProductsSlider( opts );
}, 0 );
} );
} );
}
/*===================================================================================*/
/* TOOLTIP FOR YITH WISHLIST, COMPARE, ADD TO CART, QUICK VIEW
/*===================================================================================*/
if ( ! theme.isMobile() ) {
$wrap.find( '.product-col .quickview, .product-col .add_to_cart_read_more, .product-col .add_to_cart_button, .product-col a.compare, .product-col .add_to_wishlist, .product-col .yith-wcwl-wishlistaddedbrowse > a, .product-col .yith-wcwl-wishlistexistsbrowse > a' ).each( function() {
let _this = $( this );
// Exclude
let $productCol = _this.closest( '.product-col' );
if ( _this.closest( '.porto-tb-woo-link' ).hasClass( 'no-tooltip' ) ) {
return;
}
if ( _this.hasClass( 'add_to_cart_read_more' ) || _this.hasClass( 'add_to_cart_button' ) ) {
if ( $productCol.hasClass( 'product-wq_onimage' ) || $productCol.hasClass( 'product-onimage' ) || $productCol.hasClass( 'product-outimage' ) || $productCol.hasClass( 'product-default' ) ) {
return;
}
if ( _this.closest( 'ul.products' ).hasClass( 'list' ) ) {
return;
}
}
if ( _this.hasClass( 'quickview' ) ) {
if ( $productCol.hasClass( 'product-wq_onimage' ) || $productCol.hasClass( 'product-onimage3' ) || $productCol.hasClass( 'product-onimage2' ) || $productCol.hasClass( 'product-onimage' ) || $productCol.hasClass( 'product-outimage_aq_onimage' ) ) {
return;
}
}
if ( ! _this.attr( 'title' ) ) {
_this.attr( 'title', _this.text().trim() );
}
_this.tooltip();
} );
}
} )( jQuery );
}
function porto_woocommerce_variations_init( $parent_obj ) {
'use strict';
theme.requestTimeout( function() {
var form_variation = $parent_obj.find( 'form.variations_form:not(.vf_init)' );
if ( form_variation.length && jQuery.fn.wc_variation_form ) {
form_variation.each( function() {
var data_a = jQuery._data( this, 'events' );
if ( !data_a || !data_a['show_variation'] ) {
jQuery( this ).wc_variation_form();
}
} );
}
}, 100 );
}
function porto_ajax_load_products( $obj, data, pagination_style, $ajax_tab_cache, id, group ) {
'use strict';
( function( $ ) {
if ( $obj.hasClass( 'loading' ) ) {
return;
}
$obj.addClass( 'loading' );
if ( 'load_more' != pagination_style ) {
$obj.addClass( 'yith-wcan-loading' );
if ( !$obj.children( '.porto-loading-icon' ).length ) {
$obj.append( '' );
}
}
if ( $ajax_tab_cache[id] == undefined ) {
$ajax_tab_cache[id] = {};
}
$.ajax( {
url: theme.ajax_url,
data: data,
type: 'post',
success: function( response ) {
//cache
if ( $( response ).length ) {
$ajax_tab_cache[id][group] = $( response ).html();
} else {
$ajax_tab_cache[id][group] = '';
}
porto_ajax_load_products_success( $obj, response, pagination_style );
},
complete: function() {
$obj.removeClass( 'loading' );
}
} );
} )( jQuery );
}
function porto_ajax_load_products_success( $obj, success, pagination_style ) {
'use strict';
( function( $ ) {
let _successProducts = $( success ).find( 'ul.products' );
if ( $obj.data( 'cur_page' ) && _successProducts.data( 'cur_page' ) ) {
$obj.data( 'cur_page', _successProducts.data( 'cur_page' ) );
}
if ( ! ( $obj.hasClass( 'grid-creative' ) && typeof $obj.attr( 'data-plugin-masonry' ) != 'undefined' ) ) {
_successProducts.children( ':not(.grid-col-sizer)' ).addClass( 'fadeInUp animated' );
}
if ( 'load_more' == pagination_style ) {
$obj.append( _successProducts.html() );
} else {
if ( $obj.hasClass( 'owl-carousel' ) ) {
$obj.parent().css( 'min-height', $obj.parent().height() );
}
if ( $obj.hasClass( 'grid-creative' ) && typeof $obj.attr( 'data-plugin-masonry' ) != 'undefined' ) {
$obj.isotope( 'remove', $obj.children() );
$obj.find( '.grid-col-sizer' ).remove();
var newItems = _successProducts.children();
$obj.append( newItems );
$obj.isotope( 'appended', newItems );
$obj.imagesLoaded( function() {
$obj.isotope( 'layout' );
} );
} else {
if ( $( success ).length ) {
$obj.html( _successProducts.html() );
} else {
$obj.html( '' );
}
}
}
if ( $obj.hasClass( 'owl-carousel' ) && $.fn.themeWooProductsSlider ) {
$obj.trigger( 'destroy.owl.carousel' );
theme.requestTimeout( function() {
var pluginOptions = $obj.data( 'plugin-options' ), opts;
if ( pluginOptions )
opts = pluginOptions;
$obj.data( '__wooProductsSlider', '' ).themeWooProductsSlider( opts );
$obj.parent().css( 'min-height', '' );
}, 100 );
}
if ( $obj.closest( '.porto-products' ).find( '.shop-loop-after' ).length ) {
if ( $( success ).find( '.shop-loop-after' ).length ) {
$obj.closest( '.porto-products' ).find( '.shop-loop-after' ).replaceWith( $( success ).find( '.shop-loop-after' ) );
} else {
$obj.closest( '.porto-products' ).find( '.shop-loop-after' ).remove();
}
}
if ( typeof $obj.data( 'infinitescroll' ) != 'undefined' ) {
var infinitescrollData = $obj.data( 'infinitescroll' );
infinitescrollData.options.state.currPage = 1;
$obj.data( 'infinitescroll', infinitescrollData );
}
$obj.removeClass( 'yith-wcan-loading' );
if ( 'load_more' == pagination_style && typeof $obj != 'undefined' && typeof $obj.data( 'text' ) != 'undefined' ) {
$obj.text( $obj.data( 'text' ) );
}
$( document ).trigger( "yith-wcan-ajax-filtered" );
} )( jQuery );
}