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

193 lines 8.0 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.events();
29 this.flexibleContentLabel();
30 }
31
32 /**
33 * Events.
34 */
35 }, {
36 key: "events",
37 value: function events() {
38 $(document).on('change keyup merchant.change', '.merchant-module-page-setting-fields', this.flexibleContentLabel.bind(this));
39 }
40
41 /**
42 * Update the label of the upsell groups in the side cart settings page based on the selected options.
43 */
44 }, {
45 key: "flexibleContentLabel",
46 value: function flexibleContentLabel() {
47 var self = this;
48 if (this.cartUpsellsToggleState() && this.cartUpsellType() === 'custom_upsell') {
49 var upsellsGroups = $('.merchant-field-custom_upsells .merchant-flexible-content .layout');
50 upsellsGroups.each(function () {
51 var group = $(this),
52 trigger = self.customUpsellTrigger(group),
53 categories = self.customUpsellCategories(group),
54 products = self.customUpsellProducts(group);
55 if ('categories' === trigger) {
56 self.updateGroupLabel(group, 'categories', categories.length, categories);
57 }
58 if ('products' === trigger) {
59 self.updateGroupLabel(group, 'products', products.length, products);
60 }
61 if ('all' === trigger) {
62 self.updateGroupLabel(group, 'all', 10, []);
63 }
64 });
65 }
66 }
67
68 /**
69 * Get the upsells count label badge.
70 * @param group {jQuery} The upsell group.
71 * @returns {string}
72 */
73 }, {
74 key: "upsellsLabelBadge",
75 value: function upsellsLabelBadge(group) {
76 var upsellsType = group.find('.merchant-field-custom_upsell_type select').val();
77 if ('products' === upsellsType) {
78 var products = group.find('.merchant-field-upsells_product_ids .merchant-selected-products-preview li');
79 if (products.length) {
80 return "<span class=\"merchant-upsells-badge\">Upsells: ".concat(products.length, "</span>");
81 }
82 }
83 return '';
84 }
85
86 /**
87 * Update the group label based on the selected options.
88 * @param group {jQuery} The upsell group.
89 * @param type {string} The type of the upsell group
90 * @param count {number} The count of the selected items
91 * @param data {Array} The selected items data
92 */
93 }, {
94 key: "updateGroupLabel",
95 value: function updateGroupLabel(group, type, count, data) {
96 var groupLabel = group.find('.layout-title');
97 if ('categories' === type) {
98 if (count > 1) {
99 groupLabel.html(merchant_side_cart_params.keywords.multi_categories + this.upsellsLabelBadge(group));
100 } else if (count === 1) {
101 groupLabel.html(merchant_side_cart_params.keywords.category_trigger + ' ' + data[0] + this.upsellsLabelBadge(group));
102 } else {
103 groupLabel.html(merchant_side_cart_params.keywords.no_cats_selected + this.upsellsLabelBadge(group));
104 }
105 }
106 if ('products' === type) {
107 if (count > 1) {
108 groupLabel.html(merchant_side_cart_params.keywords.multi_products + this.upsellsLabelBadge(group));
109 } else if (count === 1) {
110 groupLabel.html(data[0].name + ' (#' + data[0].id + ')' + this.upsellsLabelBadge(group));
111 } else {
112 groupLabel.html(merchant_side_cart_params.keywords.no_products_selected + this.upsellsLabelBadge(group));
113 }
114 }
115 if ('all' === type) {
116 groupLabel.html(merchant_side_cart_params.keywords.all_products + this.upsellsLabelBadge(group));
117 }
118 }
119
120 /**
121 * Get the selected trigger for the upsell group.
122 * @param group {jQuery} The upsell group.
123 * @returns {string} The selected trigger value.
124 */
125 }, {
126 key: "customUpsellTrigger",
127 value: function customUpsellTrigger(group) {
128 return group.find('.merchant-field-upsell_based_on select').val();
129 }
130
131 /**
132 * Get the selected products for the upsell group.
133 * @param group {jQuery} The upsell group.
134 * @returns {Array} The selected products data.
135 */
136 }, {
137 key: "customUpsellProducts",
138 value: function customUpsellProducts(group) {
139 var foundProducts = group.find('.merchant-field-product_ids .merchant-selected-products-preview li');
140 var products = [];
141 foundProducts.each(function () {
142 products.push({
143 id: $(this).data('id'),
144 name: $(this).data('name'),
145 element: $(this)
146 });
147 });
148 return products;
149 }
150
151 /**
152 * Get the selected categories for the upsell group.
153 * @param group {jQuery} The upsell group.
154 * @returns {Array} The selected categories.
155 */
156 }, {
157 key: "customUpsellCategories",
158 value: function customUpsellCategories(group) {
159 var upsellDropdown = group.find('.merchant-field-category_slugs select');
160 return upsellDropdown.find('option:selected').map(function () {
161 return $(this).text().trim();
162 }).get();
163 }
164
165 /**
166 * Check the state of the upsells main toggle.
167 * @returns {boolean} True if the toggle is checked otherwise false.
168 */
169 }, {
170 key: "cartUpsellsToggleState",
171 value: function cartUpsellsToggleState() {
172 var toggle = $('.merchant-field-use_upsells input');
173 return !!toggle.is(':checked');
174 }
175
176 /**
177 * Get the selected upsell type.
178 * @returns {string} The selected upsell type.
179 */
180 }, {
181 key: "cartUpsellType",
182 value: function cartUpsellType() {
183 // custom_upsell
184 var type = $('.merchant-field-upsells_type select');
185 return type.val();
186 }
187 }]);
188 return MerchantSideCartAdminPreview;
189 }(); // Instantiate the class when the DOM is ready
190 $(document).ready(function () {
191 new MerchantSideCartAdminPreview();
192 });
193 })(jQuery);