PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.2.7
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.2.7
2.3.2 2.3.1 2.3.0 2.2.8 2.2.7 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.11.0 1.11.1 1.11.2 1.6 1.7 1.8 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 1.9.10 1.9.11 All 60 releases
merchant / assets / js / modules / volume-discounts / admin / preview.js

preview.js in Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant 2.2.7, at assets/js/modules/volume-discounts/admin/preview.js

184 lines 9.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 (function ($) {
4 'use strict';
5
6 $(document).on('click', '.merchant-flexible-content-control.volume-discounts-style .layout', function () {
7 var $this = $(this),
8 $parent = $this.closest('.merchant-flexible-content-control.volume-discounts-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.volume-discounts-style').find('.layout.active'),
18 displayStyle = $('.merchant-field-offers_display_style input:checked').val(),
19 titleText = layout.find('.merchant-field-table_title input').val(),
20 titleTextColor = layout.find('.merchant-field-title_text_color input').val(),
21 titleTextFontSize = layout.find('.merchant-field-title_font_size input').val(),
22 titleTextFontWeight = layout.find('.merchant-field-title_font_weight select').val(),
23 bgColor = layout.find('.merchant-field-table_item_bg_color input').val(),
24 bgColorHover = layout.find('.merchant-field-table_item_bg_color_hover input').val(),
25 borderColor = layout.find('.merchant-field-table_item_border_color input').val(),
26 borderColorHover = layout.find('.merchant-field-table_item_border_color_hover input').val(),
27 textColor = layout.find('.merchant-field-table_item_text_color input').val(),
28 textColorHover = layout.find('.merchant-field-table_item_text_color_hover input').val(),
29 labelBgColor = layout.find('.merchant-field-table_label_bg_color input').val(),
30 labelTextColor = layout.find('.merchant-field-table_label_text_color input').val(),
31 discountType = layout.find('.merchant-field-discount_type input:checked').val(),
32 discountAmount = +layout.find('.merchant-field-discount input').val(),
33 discountAmountField = layout.find('.merchant-field-discount input'),
34 saveLabelValue = layout.find('.merchant-field-save_label input').val(),
35 buyLabelValue = layout.find('.merchant-field-buy_text input').val(),
36 quantityValue = +layout.find('.merchant-field-quantity input').val(),
37 cartOfferTitle = layout.find('.merchant-group-field-cart_page .merchant-field-title input').val(),
38 checkoutTitle = layout.find('.merchant-group-field-checkout_page .merchant-field-title input').val(),
39 checkoutDiscountText = layout.find('.merchant-group-field-checkout_page .merchant-field-discount_text input').val(),
40 checkoutButtonText = layout.find('.merchant-group-field-checkout_page .merchant-field-button_text input').val(),
41 thankYouTitle = layout.find('.merchant-group-field-thank_you_page .merchant-field-title input').val(),
42 thankYouDiscountText = layout.find('.merchant-group-field-thank_you_page .merchant-field-discount_text input').val(),
43 thankYouButtonText = layout.find('.merchant-group-field-thank_you_page .merchant-field-button_text input').val(),
44 cartBundleButtonText = layout.find('.merchant-group-field-cart_page .merchant-field-button_text input').val();
45 console.log(displayStyle);
46 if (displayStyle === 'standard') {
47 $('.tiered-radio,.standard-style').removeClass('show');
48 $('.standard-style').addClass('show');
49 } else if (displayStyle === 'radio') {
50 $('.tiered-radio,.standard-style').removeClass('show');
51 $('.tiered-radio').addClass('show');
52 }
53 $('.merchant-volume-discounts-title').css({
54 'color': titleTextColor,
55 'font-size': titleTextFontSize + 'px',
56 'font-weight': titleTextFontWeight
57 }).html(titleText);
58 $('.merchant-volume-discounts-item').css({
59 '--merchant-item-text-color': textColor,
60 '--merchant-item-text-color-hover': textColorHover || textColor,
61 '--merchant-item-bg-color': bgColor,
62 '--merchant-item-bg-color-hover': bgColorHover || bgColor,
63 '--merchant-item-border-color': borderColor,
64 '--merchant-item-border-color-hover': borderColorHover || borderColor
65 });
66 var $saveLabelPreview = $('.merchant-volume-discounts-item-label');
67 var $buyLabelPreview = $('.merchant-volume-discounts-buy-label .inner-text');
68 $saveLabelPreview.find('span:first').css({
69 '--merchant-label-text-color': labelTextColor,
70 '--merchant-label-bg-color': labelBgColor
71 });
72 var currency = $saveLabelPreview.closest('.mrc-preview-right-column').attr('data-currency');
73 var discountEach = discountType === 'fixed_discount' ? "".concat(currency).concat(discountAmount) : "".concat(discountAmount, "%");
74 var discountTotal = discountType === 'fixed_discount' ? "".concat(currency).concat(discountAmount * quantityValue) : "".concat(discountAmount, "%");
75
76 // Update Save label content
77 saveLabelValue = saveLabelValue.replace(/{amount}|{percent}/g, discountTotal);
78 $saveLabelPreview.find('span:first').text(saveLabelValue);
79
80 // Update Tier format text content
81 buyLabelValue = buyLabelValue.replace(/{discount}|{percent}/g, "<strong>".concat(discountEach, "</strong>")).replace(/{quantity}|{amount}/g, "<strong>".concat(quantityValue, "</strong>"));
82 $buyLabelPreview.html(buyLabelValue);
83 $('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-offer').text(cartOfferTitle.replace('{quantity}', '3').replace('{discount}', '20%'));
84 $('.merchant-cart-preview .my-cart .cart-table .cart-item .product .product-info .upsell-product .upsell-info .add-to-cart').text(cartBundleButtonText);
85 $('.merchant-checkout-preview .offer-title').text(checkoutTitle.replace('{quantity}', '3').replace('{discount}', '10%'));
86 $('.merchant-checkout-preview .product-details .product-info p').html(checkoutDiscountText.replace('{discount}', '10%').replace('{product_price}', merchant_volume_discounts.mock_item_price));
87 $('.merchant-checkout-preview .product-details .product-info .add-to-order').text(checkoutButtonText);
88 $('.merchant-thank-you-preview .offer-title').text(thankYouTitle.replace('{quantity}', '3').replace('{discount}', '15%').replace('{total_quantity}', '5'));
89 $('.merchant-thank-you-preview .product-details .product-info p').html(thankYouDiscountText.replace('{product_price}', merchant_volume_discounts.mock_item_price).replace('{discount}', '10%'));
90 $('.merchant-thank-you-preview .product-details .product-info .add-to-order').text(thankYouButtonText);
91 if (discountType === 'percentage_discount') {
92 discountAmountField.attr('max', 100);
93 if (discountAmountField.val() > 100) {
94 discountAmountField.val(100);
95 }
96 } else {
97 // remove attribute
98 discountAmountField.removeAttr('max');
99 }
100 }
101 $('.merchant-flexible-content-control.volume-discounts-style .layout:first-child').addClass('active').trigger('click');
102 $(document).on('change', 'input[type="radio"]', function () {
103 var value = $(this).val();
104 if (value !== 'percentage_discount' && value !== 'fixed_discount') {
105 return;
106 }
107 var $layout = $(this).closest('.layout');
108 $layout.find('input[type="text"], textarea').each(function () {
109 // Define the replacement string based on the radio button value
110 var replacement = value === 'percentage_discount' ? '{percent}' : '{amount}';
111 var currentValue = $(this).val();
112
113 /**
114 * Previously wrong variable `{amount}` was used for this field. Correct one is `{quantity}`.
115 * So fix it as soon as Discount type is changed.
116 * Keep it for backward compatibility
117 */
118 if ($(this).attr('name').includes('buy_text')) {
119 replacement = '{quantity}';
120 }
121
122 // Replace occurrences of {amount} or {percent} with the appropriate replacement
123 var newValue = currentValue.replace(/{amount}|{percent}/g, replacement);
124 $(this).val(newValue);
125 });
126 });
127 function show_single_product_preview() {
128 var element = $('.merchant-single-product-preview');
129 element.addClass('show');
130 }
131 function hide_single_product_preview() {
132 var element = $('.merchant-single-product-preview');
133 element.removeClass('show');
134 }
135 function show_cart_page_preview() {
136 var element = $('.merchant-cart-preview');
137 element.addClass('show');
138 }
139 function hide_cart_page_preview() {
140 var element = $('.merchant-cart-preview');
141 element.removeClass('show');
142 }
143 function show_thank_you_page_preview() {
144 var element = $('.merchant-thank-you-preview');
145 element.addClass('show');
146 }
147 function hide_thank_you_page_preview() {
148 var element = $('.merchant-thank-you-preview');
149 element.removeClass('show');
150 }
151 function show_checkout_page_preview() {
152 var element = $('.merchant-checkout-preview');
153 element.addClass('show');
154 }
155 function hide_checkout_page_preview() {
156 var element = $('.merchant-checkout-preview');
157 element.removeClass('show');
158 }
159 $('.merchant-module-page-setting-box').on('click', function (e) {
160 var clickedElement = $(e.target);
161 if (clickedElement.closest('.merchant-group-field-cart_page').length > 0 || clickedElement.hasClass('merchant-group-field-cart_page')) {
162 show_cart_page_preview();
163 hide_single_product_preview();
164 hide_thank_you_page_preview();
165 hide_checkout_page_preview();
166 } else if (clickedElement.closest('.merchant-group-field-thank_you_page').length > 0 || clickedElement.hasClass('merchant-group-field-thank_you_page')) {
167 show_thank_you_page_preview();
168 hide_single_product_preview();
169 hide_cart_page_preview();
170 hide_checkout_page_preview();
171 } else if (clickedElement.closest('.merchant-group-field-checkout_page').length > 0 || clickedElement.hasClass('merchant-group-field-checkout_page')) {
172 show_checkout_page_preview();
173 hide_single_product_preview();
174 hide_cart_page_preview();
175 hide_thank_you_page_preview();
176 } else {
177 show_single_product_preview();
178 hide_cart_page_preview();
179 hide_thank_you_page_preview();
180 hide_checkout_page_preview();
181 }
182 });
183 show_single_product_preview();
184 })(jQuery);