| 1 |
(function ($) { |
| 2 |
'use strict'; |
| 3 |
$(function () { |
| 4 |
if (typeof wc_add_to_cart_variation_params !== 'undefined') { |
| 5 |
$('.variations_form').each(function () { |
| 6 |
$(this).wc_variation_form(); |
| 7 |
}); |
| 8 |
} |
| 9 |
|
| 10 |
function init_custom_gallery() { |
| 11 |
$('.ob-modal .woocommerce-product-gallery__image').on('click', function(e) { |
| 12 |
e.preventDefault(); |
| 13 |
}); |
| 14 |
|
| 15 |
$('.ob-modal .flex-control-thumbs img').on('click', function() { |
| 16 |
var $this = $(this); |
| 17 |
var $gallery = $this.closest('.woocommerce-product-gallery'); |
| 18 |
var $main_image = $gallery.find('.wp-post-image'); |
| 19 |
var src = $this.data('full_src'); |
| 20 |
|
| 21 |
$main_image.attr('src', src); |
| 22 |
$main_image.attr('srcset', ''); |
| 23 |
$main_image.attr('sizes', ''); |
| 24 |
|
| 25 |
$gallery.find('.flex-control-thumbs img').removeClass('flex-active'); |
| 26 |
$this.addClass('flex-active'); |
| 27 |
}); |
| 28 |
} |
| 29 |
|
| 30 |
$('.option-selector').on('click', function() { |
| 31 |
var modalId = '#ob-modal-' + $(this).attr('id').replace('option-selector-', ''); |
| 32 |
$(modalId).show(); |
| 33 |
init_custom_gallery(); |
| 34 |
}); |
| 35 |
|
| 36 |
$('.ob-close').on('click', function() { |
| 37 |
$(this).closest('.ob-modal').hide(); |
| 38 |
}); |
| 39 |
|
| 40 |
$(window).on('click', function(event) { |
| 41 |
if ($(event.target).is('.ob-modal')) { |
| 42 |
$(event.target).hide(); |
| 43 |
} |
| 44 |
}); |
| 45 |
|
| 46 |
$('.variations_form').on('show_variation', function (event, variation) { |
| 47 |
var $product = $(this).closest('.product'); |
| 48 |
var $price = $product.find('.price'); |
| 49 |
if (variation.price_html) { |
| 50 |
$price.html(variation.price_html); |
| 51 |
} |
| 52 |
$(this).find('.single_add_to_cart_button').removeClass('disabled'); |
| 53 |
|
| 54 |
var $gallery = $product.find('.woocommerce-product-gallery'); |
| 55 |
if (variation.image && variation.image.src) { |
| 56 |
$gallery.find('.wp-post-image').attr('src', variation.image.src); |
| 57 |
$gallery.find('.wp-post-image').attr('srcset', variation.image.srcset); |
| 58 |
$gallery.find('.wp-post-image').attr('sizes', variation.image.sizes); |
| 59 |
} |
| 60 |
}); |
| 61 |
|
| 62 |
$('.variations_form').on('hide_variation', function (event) { |
| 63 |
var $product = $(this).closest('.product'); |
| 64 |
var $price = $product.find('.price'); |
| 65 |
var $regular_price = $product.data('regular-price'); |
| 66 |
if ($regular_price) { |
| 67 |
$price.html($regular_price); |
| 68 |
} |
| 69 |
$(this).find('.single_add_to_cart_button').addClass('disabled'); |
| 70 |
}); |
| 71 |
|
| 72 |
$('.single_add_to_cart_button').on('click', function (e) { |
| 73 |
e.preventDefault(); |
| 74 |
if ($(this).hasClass('disabled')) { |
| 75 |
return; |
| 76 |
} |
| 77 |
var $form = $(this).closest('form.cart'); |
| 78 |
var $this = $(this); |
| 79 |
|
| 80 |
// Don't post to WooCommerce - let the order bump handler do the cart management |
| 81 |
// Just close modal and trigger the order bump change event |
| 82 |
var key = $this.closest('.ob-modal').attr('id').replace('ob-modal-', ''); |
| 83 |
$form.closest('.ob-modal').hide(); |
| 84 |
$('#wpfnl-order-bump-cb-' + key).prop('checked', true).trigger('change'); |
| 85 |
}); |
| 86 |
|
| 87 |
$('.wpfnl-order-bump-cb').on('click', function(e) { |
| 88 |
var $this = $(this); |
| 89 |
if ($this.data('is-variable') && $this.is(':checked')) { |
| 90 |
e.preventDefault(); |
| 91 |
var key = $this.data('key'); |
| 92 |
$('#option-selector-' + key).trigger('click'); |
| 93 |
} |
| 94 |
}); |
| 95 |
}); |
| 96 |
})(jQuery); |