PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 2.3.2
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v2.3.2
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 / pre-orders / admin / preview.js

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

154 lines 8.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 "use strict";
2
3 function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4 function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5 function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6 function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
7 function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
8 function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
9 (function ($) {
10 'use strict';
11
12 var merchant_pre_order_object = {
13 init: function init() {
14 // Initialize events
15 this.initEvents();
16 this.initPreview();
17 this.datePickers = [];
18 },
19 initEvents: function initEvents() {
20 var self = this;
21 $(document).on('change.merchant keyup', this.initPreview.bind(this));
22 $(document).on('click', '.merchant-flexible-content-control.pre-orders-style .layout', this.updateActiveLayout.bind(this));
23 $('.merchant-flexible-content-control .layout:first-child').addClass('active').trigger('click');
24
25 // Remove datepicker form pre-order start & end fields if associated Shipping fields is empty on Page load.
26 $(document).on('initiated.merchant-datepicker', function (e, datePicker, $input, options, index) {
27 if (!$input.closest('.merchant-flexible-content').length) {
28 return;
29 }
30 var $preOrderStartField = $input.closest('.merchant-field-pre_order_start');
31 var $preOrderEndField = $input.closest('.merchant-field-pre_order_end');
32 var $shippingField = $input.closest('.layout-body').find('.merchant-field-shipping_date input');
33
34 // Process only if the current input is a pre-order start or end field
35 if ($preOrderStartField.length || $preOrderEndField.length) {
36 // Add the same index to all related fields
37 $shippingField.add($input.closest('.layout-body').find('.merchant-field-pre_order_start input')).add($input.closest('.layout-body').find('.merchant-field-pre_order_end input')).attr('data-datepicker-index', index);
38 if ($shippingField.length) {
39 var datepickerIndex = $shippingField.data('datepicker-index');
40
41 // Check if a group with this index already exists
42 var existingGroup = self.datePickers.find(function (group) {
43 return group.id === datepickerIndex;
44 });
45 if (existingGroup) {
46 existingGroup.datePickers.push(datePicker);
47 } else {
48 self.datePickers.push({
49 id: datepickerIndex,
50 datePickers: [datePicker]
51 });
52 }
53
54 // If the shipping field has no value, destroy the datePicker
55 if (!$shippingField.val()) {
56 datePicker === null || datePicker === void 0 || datePicker.destroy();
57
58 // To prevent console error
59 datePicker.opts = {};
60 datePicker.$datepicker = '';
61 }
62 }
63 }
64 });
65
66 // Based on Shipping field selection, initiate or destroy pre-order start & end date fields
67 $(document).on('change.merchant-datepicker', function (e, formattedDate, $input, options) {
68 if (!($input !== null && $input !== void 0 && $input.closest('.merchant-field-shipping_date').length)) {
69 return;
70 }
71 $input.css('borderColor', '');
72 var $shippingField = $input.closest('.layout-body').find('.merchant-field-shipping_date input');
73 var $preOrderFields = $input.closest('.layout-body').find('.merchant-field-pre_order_start input, .merchant-field-pre_order_end input');
74 if ($shippingField.length) {
75 var datepickerIndex = $shippingField.data('datepicker-index');
76 if ($shippingField.val()) {
77 var newDatePickers = [];
78
79 // Create new date picker instances for pre-order fields
80 $preOrderFields.each(function () {
81 var datePickerInstance = new AirDatepicker($(this).getPath(), _objectSpread(_objectSpread({}, options), {}, {
82 selectedDates: '' // Ensure no pre-selected dates
83 }));
84 newDatePickers.push(datePickerInstance);
85 });
86
87 // Push the new group into `self.datePickers`
88 self.datePickers.push({
89 id: datepickerIndex,
90 datePickers: newDatePickers
91 });
92 } else {
93 // Destroy and remove date pickers for this index when shipping field is cleared
94 self.datePickers = self.datePickers.filter(function (datePickerGroup) {
95 // Destroy all date picker instances in the group
96 if (datePickerGroup.id === datepickerIndex) {
97 datePickerGroup.datePickers.forEach(function (datePickerInstance) {
98 datePickerInstance === null || datePickerInstance === void 0 || datePickerInstance.destroy();
99 datePickerInstance === null || datePickerInstance === void 0 || datePickerInstance.clear(); // Clear selected dates
100
101 // Prevent console errors by resetting internal properties
102 datePickerInstance.opts = {};
103 datePickerInstance.$datepicker = '';
104 });
105 return false; // Remove this group from the array
106 }
107 return true; // Retain other groups
108 });
109 }
110 }
111 });
112
113 // Show alert if Shipping date not selected
114 $(document).on('click', '.merchant-field-pre_order_start input, .merchant-field-pre_order_end input', function () {
115 var $shippingDateField = $(this).closest('.layout-body').find('.merchant-field-shipping_date input');
116 if ($shippingDateField.length && !$shippingDateField.val()) {
117 var _merchant;
118 $shippingDateField.css('borderColor', '#f00');
119 alert(((_merchant = merchant) === null || _merchant === void 0 ? void 0 : _merchant.shipping_date_missing_text) || 'Please set a shipping date first');
120 }
121 });
122 },
123 initPreview: function initPreview() {
124 var layout = $('.merchant-flexible-content-control.pre-orders-style').find('.layout.active'),
125 btnText = layout.find('.merchant-field-button_text input').val(),
126 btnTextColor = layout.find('.merchant-field-text-color input').val(),
127 btnTextColorHover = layout.find('.merchant-field-text-hover-color input').val(),
128 btnBorderColor = layout.find('.merchant-field-border-color input').val(),
129 btnBorderColorHover = layout.find('.merchant-field-border-hover-color input').val(),
130 btnBgColor = layout.find('.merchant-field-background-color input').val(),
131 btnBgColorHover = layout.find('.merchant-field-background-hover-color input').val(),
132 btn = $('.merchant-pre-ordered-product .add_to_cart_button');
133 btn.text(btnText);
134
135 // Set the CSS variables
136 $('.merchant-pre-ordered-product').css({
137 '--mrc-po-text-color': btnTextColor,
138 '--mrc-po-text-hover-color': btnTextColorHover,
139 '--mrc-po-border-color': btnBorderColor,
140 '--mrc-po-border-hover-color': btnBorderColorHover,
141 '--mrc-po-background-color': btnBgColor,
142 '--mrc-po-background-hover-color': btnBgColorHover
143 });
144 },
145 updateActiveLayout: function updateActiveLayout(e) {
146 var $this = $(e.currentTarget);
147 var $parent = $this.closest('.merchant-flexible-content-control.pre-orders-style');
148 $parent.find('.layout').removeClass('active');
149 $this.addClass('active');
150 this.initPreview();
151 }
152 };
153 merchant_pre_order_object.init();
154 })(jQuery);