! function( $ ) {
"use strict";
if ( typeof Codevz_Plus != 'object' ) {
var Codevz_Plus = {};
}
Codevz_Plus.woocommerce = function( quantity, timeout ) {
var body = $( document.body ),
adminBar = $( '#wpadminbar' ).length ? 32 : 0,
cartForm = $( '.woocommerce-cart-form__contents' );
// Fix WC message button.
$( '.button.wc-forward' ).removeClass( 'wc-forward' );
// Compare.
if ( cartForm.length && ! $( '.xtra-cart-td-prefix' ).length ) {
var cartItem = $( '.cart_item' ),
productText = cartForm.find( 'th.product-name' ).text(),
priceText = cartForm.find( 'th.product-price' ).text(),
quantityText = cartForm.find( 'th.product-quantity' ).text(),
subTotalText = cartForm.find( 'th.product-subtotal' ).text();
cartItem.find( 'td.product-name' ).prepend( '
' ).css({
'height': tabs.outerHeight(),
'margin': tabs.css( 'margin' )
}).insertBefore( tabs );
$( window ).on( 'scroll', function() {
if ( Codevz.inview( woot, 100 ) ) {
requestAnimationFrame(function() {
scrollTop = $(window).scrollTop() + adminBar;
isFixed = scrollTop > tabsOffset;
tabs.toggleClass( 'fixed-tabs', isFixed );
placeholder[ isFixed ? 'show' : 'hide' ]();
// Determine which tab content is currently in view
panels.each( function() {
var tabContent = $(this);
var topOffset = tabContent.offset().top - 150;
var bottomOffset = topOffset + tabContent.outerHeight();
// Check if the tab content is within the viewport
if ( topOffset <= ( scrollTop + tabs.outerHeight()) && bottomOffset >= scrollTop ) {
activeTabId = tabContent.attr('id');
return false;
}
});
// Set active class on corresponding tab link
tabs.find('li').removeClass('active');
if ( activeTabId ) {
tabs.find('a[href="#' + activeTabId + '"]').closest('li').addClass('active');
} else if ( scrollTop <= tabsOffset ) { // If at top of page, set first tab as active
tabs.find('li:first').addClass('active');
}
// Last tab out of viewport, hide sticky.
tabs.toggle( ( lastTab.offset().top + lastTab.outerHeight() - tabs.outerHeight() ) >= scrollTop );
});
}
});
}
// Tabs scroll to.
body.on( 'click', '.wc-tabs a', function() {
var $page = $( 'html, body' ),
tabs = $( 'body:not(.woo-product-tabs-vertical) .wc-tabs' ),
tab = $( this ).attr( 'href' ).replace( '#', '' ),
sticky = $( '.header_is_sticky' ).not( '.smart_sticky,.header_4' );
$page.animate({
scrollTop: $( '#' + tab ).offset().top - ( tabs.outerHeight() || 0 ) - ( sticky.outerHeight() || 0 ) - adminBar - ( $( '.xtra-preview-header' ).outerHeight() || 0 ) - 50
}, 1000, 'easeInOutCodevz', function() {
$page.stop();
});
});
}, 1000 );
// Disable product page lightbox
$( '.woo-disable-lightbox .woocommerce-product-gallery__wrapper > div:first-child a' ).removeAttr( 'href' ).css( 'cursor', 'default' );
// Move single onSale badge to sticky.
$( '.xtra-single-product' ).prev( '.onsale' ).prependTo( $( '.xtra-single-product > div:first-child' ) );
// Woo sticky column.
$( '.woocommerce-product-gallery' ).addClass( 'cz_sticky_col' );
// Edit reviews count in tab and add span.
$( '.wc-tabs [href="#tab-reviews"]' ).html( function( i, html ) {
return html.replace( '(', '
' ).replace( ')', '' );
});
// Single add to cart fake loading.
body.on( 'click', '.cart .button.single_add_to_cart_button', function() {
$( this ).addClass( 'loading' );
});
// Out of stock message.
var outofstock_p = $( 'p.stock.out-of-stock' );
// Add error class to outofstock p tag.
outofstock_p.addClass( 'woocommerce-error' );
// Sticky add to cart.
if ( $( '.cz-sticky-add-to-cart' ).length && ! outofstock_p.length ) {
var sticky = $( '.cz-sticky-add-to-cart .row' ),
product = $( '.xtra-single-product' ),
cart = product.find( '.cart' ),
footer = $( '#site_footer' );
// Set product details in sticky bar.
sticky.append( '
' + product.find( '.product_title' ).html() + '
' );
sticky.append( product.find( '.cart' ).clone() );
sticky.find( 'h3' ).append( product.find( '.price' ).clone() );
// Change add to cart to select options for variation products.
if ( sticky.find( '.variations_form' ).length && ! $( '.codevz-select-options' ).length ) {
sticky.find( '.single_add_to_cart_button' ).hide().after( '
' + xtra_strings.select_options + '' );
body.on( 'click', '.codevz-select-options', function() {
var targetOffsetTop = $( '.summary .variations_form' ).offset().top - 100;
$( 'html, body' ).animate( { scrollTop: targetOffsetTop }, 1200, 'easeInOutCodevz' );
return false;
});
}
// Product image.
var image = product.find( '.woocommerce-product-gallery__image' ).attr( 'data-thumb' ),
offset;
if ( image ) {
sticky.prepend( '

' );
}
// Show/hide sticky on scroll.
$( window ).on( 'scroll.sticky_add_to_cart', function() {
clearTimeout( timeout );
timeout = setTimeout( function() {
offset = $( window ).scrollTop() > cart.offset().top + cart.outerHeight();
sticky.parent()[ offset ? 'addClass' : 'removeClass' ]( 'cz-sticky-add-to-cart-show' );
// Fix footer margin.
!footer.hasClass( 'woo-sticky-footer-done' ) && footer.addClass( 'woo-sticky-footer-done' ).css( 'margin-bottom', sticky.parent().outerHeight() );
// Fix fixed icons.
$( 'i.backtotop,i.fixed_contact' ).css( 'bottom', ( offset ? ( $( window ).width() > 769 ? $( '.cz-sticky-add-to-cart' ).outerHeight() + 20 : '' ) : '' ) );
}, 100 );
});
} // Sticky add to cart.
// After gallery carousel init.
Codevz.heightChanged( $( '.woocommerce-product-gallery' ), function() {
if ( ! $( '.codevz-woo-zoom' ).length ) {
// Add title to product image zoom icon.
$( '.woocommerce-product-gallery__trigger' ).html( '
' + xtra_strings.zoom_text + '' );
// Append onsale badge to parent.
$( 'div.product, .xtra-single-product' ).find( '> .onsale' ).appendTo( $( '.woocommerce-product-gallery__trigger' ).parent() );
}
});
} // Single product page.
};
Codevz_Plus.woocommerce();
}( jQuery );