jQuery( document ).ready( function( $ ) {
"use strict";
var qvBO = false;
var latest_y = 0;
var qv_modal = $(document).find( '#yith-quick-view-modal' ),
qv_overlay = qv_modal.find( '.yith-quick-view-overlay'),
qv_content = qv_modal.find( '#yith-quick-view-content' ),
qv_close = qv_modal.find( '#yith-quick-view-close' );
/*==================
*MAIN BUTTON OPEN
==================*/
$.fn.yith_quick_view = function() {
var button = $(document).find( '.ico-view' );
// remove prev click event
button.off( 'click' );
button.on( 'click', function(e){
e.preventDefault();
var t = $(this),
product_id = t.parent().find( '.brnhmbx-product-id' ).text(),
is_blocked = false;
if ( typeof yith_qv.loader !== 'undefined' ) {
is_blocked = true;
t.block({
message: null,
overlayCSS : {
background: '#FFF',
'border-radius': '6px',
opacity : 1,
cursor : 'none'
}
});
}
ajax_call( t, product_id, is_blocked );
brnhmbx_quick_view_cws();
});
};
/*================
* MAIN AJAX CALL
================*/
var ajax_call = function( t, product_id, is_blocked ) {
$.post( yith_qv.ajaxurl, { action: 'yith_load_product_quick_view', product_id: product_id }, function( data ) {
qv_content.html( data );
// quantity fields for WC 2.2
if( yith_qv.is2_2 ) {
qv_content.find('div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)').addClass('buttons_added').append('').prepend('');
}
// Variation Form
var form_variation = qv_content.find( '.variations_form' );
form_variation.wc_variation_form();
if( typeof $.fn.yith_wccl !== 'undefined' ) {
form_variation.yith_wccl();
}
if( ! qv_modal.hasClass( 'open' ) ) {
qv_modal.addClass('open');
if( is_blocked )
t.unblock();
}
// stop loader
$(document).trigger( 'qv_loader_stop' );
/* Quick View Destroy for Image */
$( '#yith-quick-view-content' ).find( 'a.woocommerce-main-image' ).removeAttr( 'href' );
/* */
/* Remove Hover */
$( 'ul.products li.pif-has-gallery, ul.products li.pif-no-gallery' ).find( '.brnhmbx-hover-group' ).removeClass( 'fadeInDown' ).addClass( 'fadeOutUp' );
/* */
$( '#yith-quick-view-content form.cart button.single_add_to_cart_button.brnhmbx-button' ).append( '' );
});
};
/*===================
* CLOSE QUICK VIEW
===================*/
var close_modal_qv = function() {
// Close box by click overlay
qv_overlay.on( 'click', function(e){
close_qv();
});
// Close box with esc key
$(document).keyup(function(e){
if( e.keyCode === 27 )
close_qv();
});
// Close box by click close button
qv_close.on( 'click', function(e) {
e.preventDefault();
close_qv();
});
var close_qv = function() {
qv_modal.removeClass('open').removeClass('loading');
// Scroll to the latest scroll position for small screens
if ( $( window ).height() < 760 || $( window ).width() < 968 ) {
$( 'html, body' ).animate( { scrollTop: latest_y }, 500 );
}
setTimeout(function () {
qv_content.html('');
}, 1000);
}
};
close_modal_qv();
// START
$.fn.yith_quick_view();
/* */
/* Quick View Close Icon */
$( '.yith-wcqv-close' ).html( '' );
/* */
/* Check Window Size */
function brnhmbx_quick_view_cws() {
qvBO = true;
if ( $( window ).height() < 700 || $( window ).width() < 968 ) {
// Detect the latest scroll position for small screens
latest_y = $( window ).scrollTop();
brnhmbx_quick_view_sct();
}
}
// Scroll to top
function brnhmbx_quick_view_sct() {
$( 'html, body' ).animate( { scrollTop: 0 }, 500 );
return false;
}
// Resize
function brnhmbx_quick_view_resize() {
if ( ( $( window ).height() < 700 || $( window ).width() < 968 ) && qvBO ) {
$( 'html, body' ).scrollTop( 0 );
}
}
$( window ).resize( brnhmbx_quick_view_resize );
/* */
} );