| 1 |
"use strict"; |
| 2 |
|
| 3 |
(function ($) { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
$(document).on('click', '.merchant-flexible-content-control.frequently-bought-together-style .layout', function () { |
| 7 |
var $this = $(this); |
| 8 |
var $parent = $this.closest('.merchant-flexible-content-control.frequently-bought-together-style'); |
| 9 |
$parent.find('.layout').removeClass('active'); |
| 10 |
$this.addClass('active'); |
| 11 |
initPreview(); |
| 12 |
}); |
| 13 |
$(document).on('change.merchant keyup', function () { |
| 14 |
initPreview(); |
| 15 |
}); |
| 16 |
$(document).on('change', '.merchant-module-page-setting-field-select select', function () { |
| 17 |
var _merchant; |
| 18 |
var selectedHook = $(this).val(); |
| 19 |
var priority = ((_merchant = merchant) === null || _merchant === void 0 || (_merchant = _merchant.fbt_object) === null || _merchant === void 0 ? void 0 : _merchant.hooks[selectedHook]) || 10; |
| 20 |
$(this).closest('.merchant-module-page-setting-field-hook_select').find('.merchant-module-page-setting-field-number input').val(priority); |
| 21 |
}); |
| 22 |
function initPreview() { |
| 23 |
var _merchant2, _merchant3, _merchant4; |
| 24 |
var layout = $('.merchant-flexible-content-control.frequently-bought-together-style').find('.layout.active'); |
| 25 |
|
| 26 |
// Skip preview update if the active layout is deferred (not yet hydrated). |
| 27 |
if (!layout.length || layout.attr('data-deferred') === '1') { |
| 28 |
return; |
| 29 |
} |
| 30 |
var titleTextColor = layout.find('.merchant-field-title input').val(), |
| 31 |
totalText = layout.find('.merchant-field-price_label input').val(), |
| 32 |
addToCartText = layout.find('.merchant-field-button_text input').val(), |
| 33 |
plusSignBgColor = layout.find('.merchant-field-plus_bg_color input').val(), |
| 34 |
plusSignTextColor = layout.find('.merchant-field-plus_text_color input').val(), |
| 35 |
optionalProducts = layout.find('.merchant-field-optional_offer_products input').is(':checked'), |
| 36 |
offerBorderColor = layout.find('.merchant-field-bundle_border_color input').val(), |
| 37 |
offerBorderRadius = layout.find('.merchant-field-bundle_border_radius input.merchant-range-number-input').val(), |
| 38 |
cartBundleTitle = layout.find('.merchant-group-field-cart_page .merchant-field-title input').val(), |
| 39 |
cartSaveLabel = layout.find('.merchant-group-field-cart_page .merchant-field-save_label input').val(), |
| 40 |
checkoutTitle = layout.find('.merchant-group-field-checkout_page .merchant-field-title input').val(), |
| 41 |
checkoutDiscountText = layout.find('.merchant-group-field-checkout_page .merchant-field-discount_text input').val(), |
| 42 |
checkoutButtonText = layout.find('.merchant-group-field-checkout_page .merchant-field-button_text input').val(), |
| 43 |
thankYouTitle = layout.find('.merchant-group-field-thank_you_page .merchant-field-title input').val(), |
| 44 |
thankYouDiscountText = layout.find('.merchant-group-field-thank_you_page .merchant-field-discount_text input').val(), |
| 45 |
thankYouButtonText = layout.find('.merchant-group-field-thank_you_page .merchant-field-button_text input').val(), |
| 46 |
thankYouBonusTipText = layout.find('.merchant-group-field-thank_you_page .merchant-field-bonus_tip_text textarea').val(), |
| 47 |
cartBundleButtonText = layout.find('.merchant-group-field-cart_page .merchant-field-button_text input').val(); |
| 48 |
$('.merchant-frequently-bought-together-bundle-product-plus').css({ |
| 49 |
'background-color': plusSignBgColor, |
| 50 |
'color': plusSignTextColor |
| 51 |
}); |
| 52 |
$('.merchant-frequently-bought-together-bundle-product:not(:first-child)').css({ |
| 53 |
'border-color': offerBorderColor, |
| 54 |
'border-radius': offerBorderRadius + 'px' |
| 55 |
}); |
| 56 |
if (optionalProducts) { |
| 57 |
$('.merchant-frequently-bought-together-bundle-product .optional-product').show(); |
| 58 |
} else { |
| 59 |
$('.merchant-frequently-bought-together-bundle-product .optional-product').hide(); |
| 60 |
} |
| 61 |
$('.merchant-frequently-bought-together-title').html(titleTextColor); |
| 62 |
$('.merchant-frequently-bought-together-bundle-total').html(totalText); |
| 63 |
$('.merchant-frequently-bought-together-bundles .merchant-add-bundle-to-cart').html(addToCartText); |
| 64 |
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-offer').text(cartBundleTitle); |
| 65 |
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-product .upsell-info p').text(cartSaveLabel.replace('{amount}', '10%')); |
| 66 |
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-product .upsell-info .add-to-cart').text(cartBundleButtonText); |
| 67 |
$('.merchant-checkout-preview .offer-title').text(checkoutTitle.replace('{offer_quantity}', '3')); |
| 68 |
$('.merchant-checkout-preview .product-details .product-info p').text(checkoutDiscountText.replace('{discount}', '10%').replace('{fbt_products}', (_merchant2 = merchant) === null || _merchant2 === void 0 ? void 0 : _merchant2.fbt_object.product_names)); |
| 69 |
$('.merchant-checkout-preview .product-details .product-info .add-to-order').text(checkoutButtonText); |
| 70 |
$('.merchant-thank-you-preview .offer-title').text(thankYouTitle.replace('{offer_quantity}', '3').replace('{discount}', '10%')); |
| 71 |
$('.merchant-thank-you-preview .product-details .product-info p').text(thankYouDiscountText.replace('{discount}', '10%').replace('{fbt_products}', (_merchant3 = merchant) === null || _merchant3 === void 0 ? void 0 : _merchant3.fbt_object.product_names)); |
| 72 |
$('.merchant-thank-you-preview .merchant-tooltip .tooltip-text').html(thankYouBonusTipText.replace('{discount}', '10%').replace('{fbt_products}', (_merchant4 = merchant) === null || _merchant4 === void 0 ? void 0 : _merchant4.fbt_object.product_names)); |
| 73 |
$('.merchant-thank-you-preview .product-details .product-info .add-to-order').text(thankYouButtonText); |
| 74 |
} |
| 75 |
$('.merchant-flexible-content-control .layout:first-child').addClass('active').trigger('click'); |
| 76 |
function show_single_product_preview() { |
| 77 |
var element = $('.merchant-single-product-preview'); |
| 78 |
element.addClass('show'); |
| 79 |
} |
| 80 |
function hide_single_product_preview() { |
| 81 |
var element = $('.merchant-single-product-preview'); |
| 82 |
element.removeClass('show'); |
| 83 |
} |
| 84 |
function show_cart_page_preview() { |
| 85 |
var element = $('.merchant-cart-preview'); |
| 86 |
element.addClass('show'); |
| 87 |
} |
| 88 |
function hide_cart_page_preview() { |
| 89 |
var element = $('.merchant-cart-preview'); |
| 90 |
element.removeClass('show'); |
| 91 |
} |
| 92 |
function show_thank_you_page_preview() { |
| 93 |
var element = $('.merchant-thank-you-preview'); |
| 94 |
element.addClass('show'); |
| 95 |
} |
| 96 |
function hide_thank_you_page_preview() { |
| 97 |
var element = $('.merchant-thank-you-preview'); |
| 98 |
element.removeClass('show'); |
| 99 |
} |
| 100 |
function show_checkout_page_preview() { |
| 101 |
var element = $('.merchant-checkout-preview'); |
| 102 |
element.addClass('show'); |
| 103 |
} |
| 104 |
function hide_checkout_page_preview() { |
| 105 |
var element = $('.merchant-checkout-preview'); |
| 106 |
element.removeClass('show'); |
| 107 |
} |
| 108 |
$('.merchant-module-page-setting-box').on('click', function (e) { |
| 109 |
var clickedElement = $(e.target); |
| 110 |
if (clickedElement.closest('.merchant-group-field-cart_page').length > 0 || clickedElement.hasClass('merchant-group-field-cart_page')) { |
| 111 |
show_cart_page_preview(); |
| 112 |
hide_single_product_preview(); |
| 113 |
hide_thank_you_page_preview(); |
| 114 |
hide_checkout_page_preview(); |
| 115 |
} else if (clickedElement.closest('.merchant-group-field-thank_you_page').length > 0 || clickedElement.hasClass('merchant-group-field-thank_you_page')) { |
| 116 |
show_thank_you_page_preview(); |
| 117 |
hide_single_product_preview(); |
| 118 |
hide_cart_page_preview(); |
| 119 |
hide_checkout_page_preview(); |
| 120 |
} else if (clickedElement.closest('.merchant-group-field-checkout_page').length > 0 || clickedElement.hasClass('merchant-group-field-checkout_page')) { |
| 121 |
show_checkout_page_preview(); |
| 122 |
hide_single_product_preview(); |
| 123 |
hide_cart_page_preview(); |
| 124 |
hide_thank_you_page_preview(); |
| 125 |
} else { |
| 126 |
show_single_product_preview(); |
| 127 |
hide_cart_page_preview(); |
| 128 |
hide_thank_you_page_preview(); |
| 129 |
hide_checkout_page_preview(); |
| 130 |
} |
| 131 |
}); |
| 132 |
show_single_product_preview(); |
| 133 |
})(jQuery); |