| 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 |
function initPreview() { |
| 17 |
var layout = $('.merchant-flexible-content-control.frequently-bought-together-style').find('.layout.active'), |
| 18 |
titleTextColor = layout.find('.merchant-field-title input').val(), |
| 19 |
totalText = layout.find('.merchant-field-price_label input').val(), |
| 20 |
addToCartText = layout.find('.merchant-field-button_text input').val(), |
| 21 |
plusSignBgColor = layout.find('.merchant-field-plus_bg_color input').val(), |
| 22 |
plusSignTextColor = layout.find('.merchant-field-plus_text_color input').val(), |
| 23 |
offerBorderColor = layout.find('.merchant-field-bundle_border_color input').val(), |
| 24 |
offerBorderRadius = layout.find('.merchant-field-bundle_border_radius input.merchant-range-number-input').val(), |
| 25 |
cartBundleTitle = layout.find('.merchant-group-field-cart_page .merchant-field-title input').val(), |
| 26 |
cartSaveLabel = layout.find('.merchant-group-field-cart_page .merchant-field-save_label input').val(), |
| 27 |
checkoutTitle = layout.find('.merchant-group-field-checkout_page .merchant-field-title input').val(), |
| 28 |
checkoutDiscountText = layout.find('.merchant-group-field-checkout_page .merchant-field-discount_text input').val(), |
| 29 |
checkoutButtonText = layout.find('.merchant-group-field-checkout_page .merchant-field-button_text input').val(), |
| 30 |
thankYouTitle = layout.find('.merchant-group-field-thank_you_page .merchant-field-title input').val(), |
| 31 |
thankYouDiscountText = layout.find('.merchant-group-field-thank_you_page .merchant-field-discount_text input').val(), |
| 32 |
thankYouButtonText = layout.find('.merchant-group-field-thank_you_page .merchant-field-button_text input').val(), |
| 33 |
thankYouBonusTipText = layout.find('.merchant-group-field-thank_you_page .merchant-field-bonus_tip_text textarea').val(), |
| 34 |
cartBundleButtonText = layout.find('.merchant-group-field-cart_page .merchant-field-button_text input').val(); |
| 35 |
$('.merchant-frequently-bought-together-bundle-product-plus').css({ |
| 36 |
'background-color': plusSignBgColor, |
| 37 |
'color': plusSignTextColor |
| 38 |
}); |
| 39 |
$('.merchant-frequently-bought-together-bundle-product:not(:first-child)').css({ |
| 40 |
'border-color': offerBorderColor, |
| 41 |
'border-radius': offerBorderRadius + 'px' |
| 42 |
}); |
| 43 |
$('.merchant-frequently-bought-together-title').html(titleTextColor); |
| 44 |
$('.merchant-frequently-bought-together-bundle-total').html(totalText); |
| 45 |
$('.merchant-frequently-bought-together-bundles .merchant-add-bundle-to-cart').html(addToCartText); |
| 46 |
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-offer').text(cartBundleTitle); |
| 47 |
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-product .upsell-info p').text(cartSaveLabel.replace('{amount}', '10%')); |
| 48 |
$('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-product .upsell-info .add-to-cart').text(cartBundleButtonText); |
| 49 |
$('.merchant-checkout-preview .offer-title').text(checkoutTitle.replace('{offer_quantity}', '3')); |
| 50 |
$('.merchant-checkout-preview .product-details .product-info p').text(checkoutDiscountText.replace('{discount}', '10%').replace('{fbt_products}', fbt_object.product_names)); |
| 51 |
$('.merchant-checkout-preview .product-details .product-info .add-to-order').text(checkoutButtonText); |
| 52 |
$('.merchant-thank-you-preview .offer-title').text(thankYouTitle.replace('{offer_quantity}', '3').replace('{discount}', '10%')); |
| 53 |
$('.merchant-thank-you-preview .product-details .product-info p').text(thankYouDiscountText.replace('{discount}', '10%').replace('{fbt_products}', fbt_object.product_names)); |
| 54 |
$('.merchant-thank-you-preview .merchant-tooltip .tooltip-text').html(thankYouBonusTipText.replace('{discount}', '10%').replace('{fbt_products}', fbt_object.product_names)); |
| 55 |
$('.merchant-thank-you-preview .product-details .product-info .add-to-order').text(thankYouButtonText); |
| 56 |
} |
| 57 |
$('.merchant-flexible-content-control .layout:first-child').addClass('active').trigger('click'); |
| 58 |
function show_single_product_preview() { |
| 59 |
var element = $('.merchant-single-product-preview'); |
| 60 |
element.addClass('show'); |
| 61 |
} |
| 62 |
function hide_single_product_preview() { |
| 63 |
var element = $('.merchant-single-product-preview'); |
| 64 |
element.removeClass('show'); |
| 65 |
} |
| 66 |
function show_cart_page_preview() { |
| 67 |
var element = $('.merchant-cart-preview'); |
| 68 |
element.addClass('show'); |
| 69 |
} |
| 70 |
function hide_cart_page_preview() { |
| 71 |
var element = $('.merchant-cart-preview'); |
| 72 |
element.removeClass('show'); |
| 73 |
} |
| 74 |
function show_thank_you_page_preview() { |
| 75 |
var element = $('.merchant-thank-you-preview'); |
| 76 |
element.addClass('show'); |
| 77 |
} |
| 78 |
function hide_thank_you_page_preview() { |
| 79 |
var element = $('.merchant-thank-you-preview'); |
| 80 |
element.removeClass('show'); |
| 81 |
} |
| 82 |
function show_checkout_page_preview() { |
| 83 |
var element = $('.merchant-checkout-preview'); |
| 84 |
element.addClass('show'); |
| 85 |
} |
| 86 |
function hide_checkout_page_preview() { |
| 87 |
var element = $('.merchant-checkout-preview'); |
| 88 |
element.removeClass('show'); |
| 89 |
} |
| 90 |
$('.merchant-module-page-setting-box').on('click', function (e) { |
| 91 |
var clickedElement = $(e.target); |
| 92 |
if (clickedElement.closest('.merchant-group-field-cart_page').length > 0 || clickedElement.hasClass('merchant-group-field-cart_page')) { |
| 93 |
show_cart_page_preview(); |
| 94 |
hide_single_product_preview(); |
| 95 |
hide_thank_you_page_preview(); |
| 96 |
hide_checkout_page_preview(); |
| 97 |
} else if (clickedElement.closest('.merchant-group-field-thank_you_page').length > 0 || clickedElement.hasClass('merchant-group-field-thank_you_page')) { |
| 98 |
show_thank_you_page_preview(); |
| 99 |
hide_single_product_preview(); |
| 100 |
hide_cart_page_preview(); |
| 101 |
hide_checkout_page_preview(); |
| 102 |
} else if (clickedElement.closest('.merchant-group-field-checkout_page').length > 0 || clickedElement.hasClass('merchant-group-field-checkout_page')) { |
| 103 |
show_checkout_page_preview(); |
| 104 |
hide_single_product_preview(); |
| 105 |
hide_cart_page_preview(); |
| 106 |
hide_thank_you_page_preview(); |
| 107 |
} else { |
| 108 |
show_single_product_preview(); |
| 109 |
hide_cart_page_preview(); |
| 110 |
hide_thank_you_page_preview(); |
| 111 |
hide_checkout_page_preview(); |
| 112 |
} |
| 113 |
}); |
| 114 |
show_single_product_preview(); |
| 115 |
})(jQuery); |