| 1 |
"use strict"; |
| 2 |
|
| 3 |
(function ($) { |
| 4 |
'use strict'; |
| 5 |
|
| 6 |
$(document).on('click', '.merchant-flexible-content-control.complementary-products-style .layout', function () { |
| 7 |
var $this = $(this); |
| 8 |
var $parent = $this.closest('.merchant-flexible-content-control.complementary-products-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.complementary-products-style').find('.layout.active'), |
| 18 |
singleBundleTitle = layout.find('.merchant-group-field-product_single_page .merchant-field-offer-title input').val(), |
| 19 |
singleBundleDescription = layout.find('.merchant-group-field-product_single_page .merchant-field-offer-description textarea').val(), |
| 20 |
singleTitleDescAlignment = $('.merchant-field-title_description_alignment input:checked').val(), |
| 21 |
singleLayout = $('.merchant-field-layout input:checked').val(), |
| 22 |
headingSize = $('.merchant-field-title_heading_size select').val(), |
| 23 |
bundleDescFontSize = $('.merchant-field-description_font_size input').val(), |
| 24 |
productBorderRadius = $('.merchant-field-border_radius input').val(), |
| 25 |
productImageBorderRadius = $('.merchant-field-image_border_radius input').val(), |
| 26 |
bundleCheckboxStyle = $('.merchant-field-checkbox_style input:checked').val(), |
| 27 |
bundleCheckboxColor = $('.merchant-field-checkbox_color input').val(), |
| 28 |
bundleTitleColor = $('.merchant-field-title_color input').val(), |
| 29 |
bundleDescColor = $('.merchant-field-description_color input').val(), |
| 30 |
borderColor = $('.merchant-field-border_color input').val(), |
| 31 |
productImageBorderColor = $('.merchant-field-image_border_color input').val(), |
| 32 |
cartBundleTitle = layout.find('.merchant-group-field-cart_page .merchant-field-title input').val(), |
| 33 |
cartBundleBtnTitle = layout.find('.merchant-group-field-cart_page .merchant-field-button_text input').val(), |
| 34 |
checkoutBundleBtnTitle = layout.find('.merchant-group-field-checkout_page .merchant-field-button_text input').val(), |
| 35 |
checkoutBundleTitle = layout.find('.merchant-group-field-checkout_page .merchant-field-title input').val(), |
| 36 |
checkoutBundleDesc = layout.find('.merchant-group-field-checkout_page .merchant-field-offer_description textarea').val(), |
| 37 |
thankYouBundleBtnTitle = layout.find('.merchant-group-field-thank_you_page .merchant-field-button_text input').val(), |
| 38 |
thankYouBundleTitle = layout.find('.merchant-group-field-thank_you_page .merchant-field-title input').val(), |
| 39 |
thankYouDiscountText = layout.find('.merchant-group-field-thank_you_page .merchant-field-discount_text input').val(); |
| 40 |
var title = $('.mrc-preview-bundle-title'); |
| 41 |
title.replaceWith("<".concat(headingSize, " class=\"mrc-preview-bundle-title\">").concat(title.text(), "</").concat(headingSize, ">")); |
| 42 |
title.text(singleBundleTitle); |
| 43 |
$('.mrc-preview-bundle-wrapper').removeClass('slider compact classic').addClass(singleLayout); |
| 44 |
$('.mrc-preview-bundle-description').text(singleBundleDescription.replace('{discount_amount}', '10%')); |
| 45 |
$(":root").css({ |
| 46 |
"--merchant-cp-product-border-color": borderColor, |
| 47 |
"--merchant-cp-bundle-title-desc-align": singleTitleDescAlignment, |
| 48 |
"--merchant-cp-product-border-radius": productBorderRadius + 'px', |
| 49 |
"--merchant-cp-product-image-border-radius": productImageBorderRadius + 'px', |
| 50 |
"--merchant-cp-bundle-desc-font-size": bundleDescFontSize + 'px', |
| 51 |
"--merchant-cp-product-image-border-color": productImageBorderColor, |
| 52 |
"--merchant-cp-bundle-title-color": bundleTitleColor, |
| 53 |
"--merchant-cp-bundle-desc-text-color": bundleDescColor, |
| 54 |
"--merchant-cp-checkbox-color": bundleCheckboxColor, |
| 55 |
"--merchant-cp-product-checkbox-radius": bundleCheckboxStyle === 'rounded' ? '5px' : '0px' |
| 56 |
}); |
| 57 |
$('.merchant-cart-preview .upsell-offer').text(cartBundleTitle.replace('{discount_amount}', '10%')); |
| 58 |
$('.merchant-cart-preview .add-to-cart').text(cartBundleBtnTitle); |
| 59 |
$('.merchant-checkout-preview .offer-title').text(checkoutBundleTitle.replace('{discount_amount}', '10%')); |
| 60 |
$('.merchant-checkout-preview .offer-desc').text(checkoutBundleDesc.replace('{discount_amount}', '10%')); |
| 61 |
$('.merchant-checkout-preview .add-to-order').text(checkoutBundleBtnTitle); |
| 62 |
$('.merchant-thank-you-preview .offer-title').text(thankYouBundleTitle.replace('{discount_amount}', '10%')); |
| 63 |
$('.merchant-thank-you-preview .add-to-order').text(thankYouBundleBtnTitle); |
| 64 |
$('.merchant-thank-you-preview .discount-text').text(thankYouDiscountText.replace('{discount_amount}', '10%')); |
| 65 |
} |
| 66 |
$('.merchant-flexible-content-control .layout:first-child').addClass('active').trigger('click'); |
| 67 |
function show_single_product_preview() { |
| 68 |
var element = $('.merchant-single-product-preview'); |
| 69 |
element.addClass('show'); |
| 70 |
} |
| 71 |
function hide_single_product_preview() { |
| 72 |
var element = $('.merchant-single-product-preview'); |
| 73 |
element.removeClass('show'); |
| 74 |
} |
| 75 |
function show_cart_page_preview() { |
| 76 |
var element = $('.merchant-cart-preview'); |
| 77 |
element.addClass('show'); |
| 78 |
} |
| 79 |
function hide_cart_page_preview() { |
| 80 |
var element = $('.merchant-cart-preview'); |
| 81 |
element.removeClass('show'); |
| 82 |
} |
| 83 |
function show_thank_you_page_preview() { |
| 84 |
var element = $('.merchant-thank-you-preview'); |
| 85 |
element.addClass('show'); |
| 86 |
} |
| 87 |
function hide_thank_you_page_preview() { |
| 88 |
var element = $('.merchant-thank-you-preview'); |
| 89 |
element.removeClass('show'); |
| 90 |
} |
| 91 |
function show_checkout_page_preview() { |
| 92 |
var element = $('.merchant-checkout-preview'); |
| 93 |
element.addClass('show'); |
| 94 |
} |
| 95 |
function hide_checkout_page_preview() { |
| 96 |
var element = $('.merchant-checkout-preview'); |
| 97 |
element.removeClass('show'); |
| 98 |
} |
| 99 |
$.fn.dragScroll = function () { |
| 100 |
return this.each(function () { |
| 101 |
var $element = $(this); |
| 102 |
var isDown = false; |
| 103 |
var startX; |
| 104 |
var scrollLeft; |
| 105 |
$element.css('cursor', 'grab').on('mousedown', function (e) { |
| 106 |
isDown = true; |
| 107 |
$(this).addClass('active').css('cursor', 'grabbing'); |
| 108 |
startX = e.pageX - $(this).offset().left; |
| 109 |
scrollLeft = $(this).scrollLeft(); |
| 110 |
}).on('mouseleave mouseup', function () { |
| 111 |
isDown = false; |
| 112 |
$(this).removeClass('active').css('cursor', 'grab'); |
| 113 |
}).on('mousemove', function (e) { |
| 114 |
if (!isDown) return; |
| 115 |
e.preventDefault(); |
| 116 |
var x = e.pageX - $(this).offset().left; |
| 117 |
var walk = (x - startX) * 2; |
| 118 |
$(this).scrollLeft(scrollLeft - walk); |
| 119 |
}); |
| 120 |
}); |
| 121 |
}; |
| 122 |
$('.merchant-module-page-setting-box').on('click', function (e) { |
| 123 |
var clickedElement = $(e.target); |
| 124 |
if (clickedElement.closest('.merchant-group-field-cart_page').length > 0 || clickedElement.hasClass('merchant-group-field-cart_page')) { |
| 125 |
show_cart_page_preview(); |
| 126 |
hide_single_product_preview(); |
| 127 |
hide_thank_you_page_preview(); |
| 128 |
hide_checkout_page_preview(); |
| 129 |
} else if (clickedElement.closest('.merchant-group-field-thank_you_page').length > 0 || clickedElement.hasClass('merchant-group-field-thank_you_page')) { |
| 130 |
show_thank_you_page_preview(); |
| 131 |
hide_single_product_preview(); |
| 132 |
hide_cart_page_preview(); |
| 133 |
hide_checkout_page_preview(); |
| 134 |
} else if (clickedElement.closest('.merchant-group-field-checkout_page').length > 0 || clickedElement.hasClass('merchant-group-field-checkout_page')) { |
| 135 |
show_checkout_page_preview(); |
| 136 |
hide_single_product_preview(); |
| 137 |
hide_cart_page_preview(); |
| 138 |
hide_thank_you_page_preview(); |
| 139 |
} else { |
| 140 |
show_single_product_preview(); |
| 141 |
hide_cart_page_preview(); |
| 142 |
hide_thank_you_page_preview(); |
| 143 |
hide_checkout_page_preview(); |
| 144 |
} |
| 145 |
}); |
| 146 |
show_single_product_preview(); |
| 147 |
$('.products').dragScroll(); |
| 148 |
})(jQuery); |