PluginProbe
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant / 1.10.4
Product Labels, Quick View, Buy Now, Pre-Orders, Frequently Bought Together & More for WooCommerce – Merchant v1.10.4
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 / side-cart / admin / preview.js

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

203 lines 8.4 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(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4 function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
5 function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
6 function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
7 function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8 function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9 (function ($) {
10 'use strict';
11
12 /**
13 * MerchantSideCartAdminPreview
14 * Add tweaks to control the side cart upsell groups label in the module settings page.
15 */
16 var MerchantSideCartAdminPreview = /*#__PURE__*/function () {
17 function MerchantSideCartAdminPreview() {
18 _classCallCheck(this, MerchantSideCartAdminPreview);
19 this.init();
20 }
21
22 /**
23 * Initialize the logic.
24 */
25 _createClass(MerchantSideCartAdminPreview, [{
26 key: "init",
27 value: function init() {
28 this.preview();
29 this.events();
30 this.flexibleContentLabel();
31 }
32 }, {
33 key: "preview",
34 value: function preview() {
35 $(document).on('change', '.merchant-field-slide_direction input', function () {
36 if ($(this).is(':checked')) {
37 $('.merchant-side-cart').removeClass('slide-left slide-right').addClass('slide-' + $(this).val());
38 }
39 });
40 }
41
42 /**
43 * Events.
44 */
45 }, {
46 key: "events",
47 value: function events() {
48 $(document).on('change keyup merchant.change', '.merchant-module-page-setting-fields', this.flexibleContentLabel.bind(this));
49 }
50
51 /**
52 * Update the label of the upsell groups in the side cart settings page based on the selected options.
53 */
54 }, {
55 key: "flexibleContentLabel",
56 value: function flexibleContentLabel() {
57 var self = this;
58 if (this.cartUpsellsToggleState() && this.cartUpsellType() === 'custom_upsell') {
59 var upsellsGroups = $('.merchant-field-custom_upsells .merchant-flexible-content .layout');
60 upsellsGroups.each(function () {
61 var group = $(this),
62 trigger = self.customUpsellTrigger(group),
63 categories = self.customUpsellCategories(group),
64 products = self.customUpsellProducts(group);
65 if ('categories' === trigger) {
66 self.updateGroupLabel(group, 'categories', categories.length, categories);
67 }
68 if ('products' === trigger) {
69 self.updateGroupLabel(group, 'products', products.length, products);
70 }
71 if ('all' === trigger) {
72 self.updateGroupLabel(group, 'all', 10, []);
73 }
74 });
75 }
76 }
77
78 /**
79 * Get the upsells count label badge.
80 * @param group {jQuery} The upsell group.
81 * @returns {string}
82 */
83 }, {
84 key: "upsellsLabelBadge",
85 value: function upsellsLabelBadge(group) {
86 var upsellsType = group.find('.merchant-field-custom_upsell_type select').val();
87 if ('products' === upsellsType) {
88 var products = group.find('.merchant-field-upsells_product_ids .merchant-selected-products-preview li');
89 if (products.length) {
90 return "<span class=\"merchant-upsells-badge\">Upsells: ".concat(products.length, "</span>");
91 }
92 }
93 return '';
94 }
95
96 /**
97 * Update the group label based on the selected options.
98 * @param group {jQuery} The upsell group.
99 * @param type {string} The type of the upsell group
100 * @param count {number} The count of the selected items
101 * @param data {Array} The selected items data
102 */
103 }, {
104 key: "updateGroupLabel",
105 value: function updateGroupLabel(group, type, count, data) {
106 var groupLabel = group.find('.layout-title');
107 if ('categories' === type) {
108 if (count > 1) {
109 groupLabel.html(merchant_side_cart_params.keywords.multi_categories + this.upsellsLabelBadge(group));
110 } else if (count === 1) {
111 groupLabel.html(merchant_side_cart_params.keywords.category_trigger + ' ' + data[0] + this.upsellsLabelBadge(group));
112 } else {
113 groupLabel.html(merchant_side_cart_params.keywords.no_cats_selected + this.upsellsLabelBadge(group));
114 }
115 }
116 if ('products' === type) {
117 if (count > 1) {
118 groupLabel.html(merchant_side_cart_params.keywords.multi_products + this.upsellsLabelBadge(group));
119 } else if (count === 1) {
120 groupLabel.html(data[0].name + ' (#' + data[0].id + ')' + this.upsellsLabelBadge(group));
121 } else {
122 groupLabel.html(merchant_side_cart_params.keywords.no_products_selected + this.upsellsLabelBadge(group));
123 }
124 }
125 if ('all' === type) {
126 groupLabel.html(merchant_side_cart_params.keywords.all_products + this.upsellsLabelBadge(group));
127 }
128 }
129
130 /**
131 * Get the selected trigger for the upsell group.
132 * @param group {jQuery} The upsell group.
133 * @returns {string} The selected trigger value.
134 */
135 }, {
136 key: "customUpsellTrigger",
137 value: function customUpsellTrigger(group) {
138 return group.find('.merchant-field-upsell_based_on select').val();
139 }
140
141 /**
142 * Get the selected products for the upsell group.
143 * @param group {jQuery} The upsell group.
144 * @returns {Array} The selected products data.
145 */
146 }, {
147 key: "customUpsellProducts",
148 value: function customUpsellProducts(group) {
149 var foundProducts = group.find('.merchant-field-product_ids .merchant-selected-products-preview li');
150 var products = [];
151 foundProducts.each(function () {
152 products.push({
153 id: $(this).data('id'),
154 name: $(this).data('name'),
155 element: $(this)
156 });
157 });
158 return products;
159 }
160
161 /**
162 * Get the selected categories for the upsell group.
163 * @param group {jQuery} The upsell group.
164 * @returns {Array} The selected categories.
165 */
166 }, {
167 key: "customUpsellCategories",
168 value: function customUpsellCategories(group) {
169 var upsellDropdown = group.find('.merchant-field-category_slugs select');
170 return upsellDropdown.find('option:selected').map(function () {
171 return $(this).text().trim();
172 }).get();
173 }
174
175 /**
176 * Check the state of the upsells main toggle.
177 * @returns {boolean} True if the toggle is checked otherwise false.
178 */
179 }, {
180 key: "cartUpsellsToggleState",
181 value: function cartUpsellsToggleState() {
182 var toggle = $('.merchant-field-use_upsells input');
183 return !!toggle.is(':checked');
184 }
185
186 /**
187 * Get the selected upsell type.
188 * @returns {string} The selected upsell type.
189 */
190 }, {
191 key: "cartUpsellType",
192 value: function cartUpsellType() {
193 // custom_upsell
194 var type = $('.merchant-field-upsells_type select');
195 return type.val();
196 }
197 }]);
198 return MerchantSideCartAdminPreview;
199 }(); // Instantiate the class when the DOM is ready
200 $(document).ready(function () {
201 new MerchantSideCartAdminPreview();
202 });
203 })(jQuery);