| 1 |
'use strict'; |
| 2 |
|
| 3 |
var merchant = merchant || {}; |
| 4 |
merchant.modules = merchant.modules || {}; |
| 5 |
(function ($) { |
| 6 |
merchant.modules.quickView = { |
| 7 |
init: function init() { |
| 8 |
var self = this; |
| 9 |
var $modals = $('.merchant-quick-view-modal'); |
| 10 |
if (!$modals.length) { |
| 11 |
return; |
| 12 |
} |
| 13 |
$modals.each(function () { |
| 14 |
var $modal = $(this); |
| 15 |
var $openButton = $('.merchant-quick-view-button'); |
| 16 |
var $closeButton = $modal.find('.merchant-quick-view-close-button'); |
| 17 |
var $inner = $modal.find('.merchant-quick-view-inner'); |
| 18 |
var $content = $modal.find('.merchant-quick-view-content'); |
| 19 |
var $overlay = $modal.find('.merchant-quick-view-overlay'); |
| 20 |
var isOpen = false; |
| 21 |
$openButton.on('click', function (e) { |
| 22 |
e.preventDefault(); |
| 23 |
$content.empty(); |
| 24 |
$modal.addClass('merchant-show'); |
| 25 |
$modal.addClass('merchant-loading'); |
| 26 |
isOpen = true; |
| 27 |
$.post(window.merchant.setting.ajax_url, { |
| 28 |
action: 'merchant_quick_view_content', |
| 29 |
nonce: window.merchant.setting.nonce, |
| 30 |
product_id: $(this).data('product-id') |
| 31 |
}, function (response) { |
| 32 |
if (response.success && isOpen) { |
| 33 |
$content.html(response.data); |
| 34 |
$inner.addClass('merchant-show'); |
| 35 |
$modal.removeClass('merchant-loading'); |
| 36 |
var $gallery = $content.find('.woocommerce-product-gallery'); |
| 37 |
wc_single_product_params.zoom_enabled = window.merchant.setting.quick_view_zoom; |
| 38 |
if (typeof $.fn.wc_product_gallery === 'function' && $gallery.length) { |
| 39 |
$gallery.trigger('wc-product-gallery-before-init', [$gallery.get(0), wc_single_product_params]); |
| 40 |
$gallery.wc_product_gallery(wc_single_product_params); |
| 41 |
$gallery.trigger('wc-product-gallery-after-init', [$gallery.get(0), wc_single_product_params]); |
| 42 |
} |
| 43 |
var $variations = $content.find('.variations_form'); |
| 44 |
if (typeof $.fn.wc_variation_form === 'function' && $variations.length) { |
| 45 |
$variations.each(function () { |
| 46 |
$(this).wc_variation_form(); |
| 47 |
}); |
| 48 |
} |
| 49 |
if (window.botiga && window.botiga.productSwatch) { |
| 50 |
window.botiga.productSwatch.init(); |
| 51 |
} |
| 52 |
if (window.botiga && window.botiga.qtyButton) { |
| 53 |
window.botiga.qtyButton.init('quick-view'); |
| 54 |
} |
| 55 |
} else { |
| 56 |
$content.html(response.data); |
| 57 |
$inner.addClass('merchant-show'); |
| 58 |
$modal.removeClass('merchant-loading'); |
| 59 |
} |
| 60 |
}).fail(function (xhr, textStatus) { |
| 61 |
$content.html(textStatus); |
| 62 |
$inner.addClass('merchant-show'); |
| 63 |
$modal.removeClass('merchant-loading'); |
| 64 |
}); |
| 65 |
}); |
| 66 |
$overlay.on('click', function (e) { |
| 67 |
e.preventDefault(); |
| 68 |
$closeButton.trigger('click'); |
| 69 |
}); |
| 70 |
$closeButton.on('click', function (e) { |
| 71 |
e.preventDefault(); |
| 72 |
isOpen = false; |
| 73 |
$modal.removeClass('merchant-show'); |
| 74 |
$inner.removeClass('merchant-show'); |
| 75 |
}); |
| 76 |
}); |
| 77 |
} |
| 78 |
}; |
| 79 |
$(document).ready(function () { |
| 80 |
merchant.modules.quickView.init(); |
| 81 |
}); |
| 82 |
})(jQuery); |