File: D:/HostingSpaces/Velosophe/dev.abloc.cc/wwwroot/app/themes/abloc/js/dev/ab-shop-quickview.js
(function($) {
'use strict';
// Extend core script
$.extend($.nmTheme, {
/**
* Initialize Quickview
*/
quickview_init: function() {
var self = this,
$qvContainer = $('#ab-quickview'),
$qvOverlay = $('<div id="ab-quickview-overlay" class="mfp-bg ab-mfp-fade-in"></div>'),
productId;
/* Bind: Quick view links */
self.$body.on('click', '.ab-quickview-btn', function(e) {
e.preventDefault();
productId = $(this).data('product_id');
if (productId) {
self.$html.css('width', 'auto');
$qvOverlay.appendTo(self.$body);
$qvOverlay.addClass('show mfp-ready ab-loader');
//$qvContainer.addClass('hide');
_qvLoadProduct();
}
});
/* Function: Load product with AJAX */
var _qvLoadProduct = function() {
var ajaxUrl,
data = {
product_id: productId
};
// Use new WooCommerce endpoint URL if available
if (typeof wc_add_to_cart_params !== 'undefined') {
ajaxUrl = wc_add_to_cart_params.wc_ajax_url.toString().replace('%%endpoint%%', 'ab_ajax_load_product'); // WooCommerce Ajax endpoint URL (available since 2.4)
} else {
ajaxUrl = ab_wp_vars.ajaxUrl;
data['action'] = 'ab_ajax_load_product';
}
window.ab_quickview_get_product = $.ajax({
type: 'POST',
url: ajaxUrl,
data: data,
dataType: 'html',
cache: false,
headers: {'cache-control': 'no-cache'},
beforeSend: function() {
// Check previous requests
if (typeof window.ab_quickview_get_product === 'object') {
window.ab_quickview_get_product.abort();
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
console.log('NM: AJAX error - _qvLoadProduct() - ' + errorThrown);
// Remove 'auto' width
self.$html.css('width', '');
// Remove overlay
$qvOverlay.removeClass('mfp-ready mfp-removing').remove();
},
success: function(data) {
$qvContainer.html(data);
// Get added elements
var $currentContainer = $qvContainer.children('#product-'+productId),
$productForm = $currentContainer.find('form.cart'),
$lastImg = $('#ab-quickview-slider').find('img').last();
$lastImg.one('load', function() { // Note: Using ".one()" to make sure the event is only fired once (buggy otherwise)
// Variable product
if ($currentContainer.hasClass('product-variable')) {
// Bind WooCommerce variation-form events
// Source: "../plugins/woocommerce/assets/js/frontend/add-to-cart-variation.js" (line 538)
$productForm.wc_variation_form().find('.variations select:eq(0)').change();
// Init custom select boxes
if (self.shopCustomSelect) {
$productForm.find('select').selectOrDie(self.shopSelectConfig);
}
// Variation details
//self.shopToggleVariationDetails(); // Show if not empty
/*$productForm.on('found_variation', function() { // Bind: WooCommerce "found_variation" event
self.shopToggleVariationDetails();
});*/
var $variationDetailsWrap = $productForm.children('.single_variation_wrap').children('.single_variation');
self.shopCheckVariationDetails($variationDetailsWrap); // Hide if empty
$variationDetailsWrap.on('show_variation', function() { // Bind: WooCommerce "show_variation" event
self.shopCheckVariationDetails($(this));
});
// WooCommerce event: Go to first slide when variation select changes
$productForm.on('woocommerce_variation_select_change', function() {
if (self.qvHasSlider) {
self.$qvSlider.slick('slickGoTo', 0, false); // Args: (event, slideIndex, skipAnimation)
}
});
}
// Add quantity buttons
self.quantityInputsBindButtons($('#ab-qv-product-summary'));
// Product form: Prevent double submission
// Note: This is now done in "ab-shop-add-to-cart.js" instead
/*$productForm.submit(function() {
$productForm.find(':submit').attr('disabled', 'disabled');
});*/
_qvShowModal();
});
}
});
},
/* Function: Show quick view modal */
_qvShowModal = function() {
// Open via API
$.magnificPopup.open({
mainClass: 'ab-mfp-quickview ab-mfp-fade-in',
closeMarkup: '<a class="mfp-close ab-font ab-font-close2"></a>',
removalDelay: 180,
items: {
src: $qvContainer,
type: 'inline'
},
callbacks: {
open: function() {
$qvOverlay.removeClass('ab-loader'); // Hide 'loader'
_qvInitSlider();
// Bind quick view overlay "touchstart" event
$qvOverlay.one('touchstart.qv', function() {
// Close quick view
$.magnificPopup.close();
});
},
beforeClose: function() {
$qvOverlay.addClass('mfp-removing'); // Fade-out overlay
},
close: function() {
self.$html.css('width', '');
$qvOverlay.removeClass('mfp-ready mfp-removing').remove(); // Remove overlay
}
}
});
},
/* Function: Initialize quick view slider */
_qvInitSlider = function() {
self.qvHasSlider = false;
self.$qvSlider = $('#ab-quickview-slider');
if (self.$qvSlider.children().length > 1) {
self.qvHasSlider = true;
self.$qvSlider.slick({
//adaptiveHeight: true,
prevArrow: '<a class="slick-prev"><i class="ab-font ab-font-angle-left"></i></a>',
nextArrow: '<a class="slick-next"><i class="ab-font ab-font-angle-right"></i></a>',
dots: false,
infinite: false,
speed: 350
});
// Event: Slick slide - Init
/*self.$qvSlider.on('init', function() {
$qvContainer.removeClass('hide');
});*/
}/* else {
$qvContainer.removeClass('hide');
}*/
};
}
});
// Add extension so it can be called from $.nmThemeExtensions
$.nmThemeExtensions.quickview = $.nmTheme.quickview_init;
})(jQuery);