PageSourceSearch

https://blackparakeetztoo.com/wp-content/plugins/woo-variation-swatches/assets/js/frontend.js?ver=2.5.0

js blackparakeetztoo.com collected 2026-10-08 08:09:58 UTC 37,499 bytes, 761 lines download raw bytes

vendor: 4,126 bytes, lines 1-26
1/*!
2 * Variation Swatches for WooCommerce
3 *
4 * Author: Emran Ahmed ( [email protected] )
5 * Date: 9/17/2026, 7:21:24 PM
6 * Released under the GPLv3 license.
7 */
8/******/ (function() { // webpackBootstrap
9// This entry needs to be wrapped in an IIFE because it needs to be isolated against other entry modules.
10!function() {
11function _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); }
12function 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; }
13function _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; }
14function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
15function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
16function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
17function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
18function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
19function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); }
20function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } }
21function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; }
22function _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; }
23function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
24function _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); }
25function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
26function _nonIterableRest() { throw new TypeError("Invalid attempt to de
26structure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
27function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
28function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
29function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
30function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
31// ================================================================
32// WooCommerce Variation Swatches
33// ================================================================
34/*global wp, _, wc_add_to_cart_variation_params, woo_variation_swatches_options */
35
36(function (window) {
37  'use strict';
38
39  /**
40   * Converts various string/number/boolean inputs to their boolean equivalent
41   * Mimics PHP's filter_var($var, FILTER_VALIDATE_BOOLEAN) behavior
42   *
43   * Returns true for:
44   * - true
45   * - "true", "yes", "on", "1" (case-insensitive)
46   * - 1, "1"
47   *
48   * Returns false for:
49   * - false
50   * - "false", "no", "off", "0" (case-insensitive)
51   * - 0, "0"
52   * - null, undefined
53   * - empty string
54   * - any other value
55   *
56   * @param {*} value - The value to convert to boolean
57   * @returns {boolean} - The boolean equivalent of the input
58   */
59  function filterBoolean(value) {
60    // Handle null, undefined, and empty string
61    if (!value) {
62      return false;
63    }
64
65    // Handle actual boolean values
66    if (typeof value === 'boolean') {
67      return value;
68    }
69
70    // Convert to string and lowercase for consistent comparison
71    var strValue = String(value).toLowerCase().trim();
72
73    // Values that should return true
74    var trueValues = ['1', 'true', 'yes', 'on'];
75    if (trueValues.includes(strValue)) {
76      return true;
77    }
78
79    // Handle numeric 1
80    if (value === 1) {
81      return true;
82    }
83
84    // All other values return false
85    return false;
86  }
87  function isWooVariationSwatchesAPIRequest(options) {
88    return !!options.path && options.path.indexOf('woo-variation-swatches') !== -1 || !!options.url && options.url.indexOf('woo-variation-swatches') !== -1;
89  }
90  window.createMiddlewareForExtraQueryParams = function () {
91    var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
92    return function (options, next) {
93      if (isWooVariationSwatchesAPIRequest(options) && Object.keys(args).length > 0) {
94        for (var _i = 0, _Object$entries = Object.entries(args); _i < _Object$entries.length; _i++) {
95          var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
96            key = _Object$entries$_i[0],
97            value = _Object$entries$_i[1];
98          if (typeof options.url === 'string' && !wp.url.hasQueryArg(options.url, key)) {
99            options.url = wp.url.addQueryArgs(options.url, _defineProperty({}, key, value));
100          }
101          if (typeof options.path === 'string' && !wp.url.hasQueryArg(options.path, key)) {
102            options.path = wp.url.addQueryArgs(options.path, _defineProperty({}, key, value));
103          }
104        }
105      }
106      return next(options);
107    };
108  };
109
110  /*
111  wp.apiFetch.use((options, next) =>  createMiddlewareForExtraQueryParams({'lang':'en'}));
112  */
113
114  var Plugin = function ($) {
115    return /*#__PURE__*/function () {
116      function _class(element, options, name) {
117        _classCallCheck(this, _class);
118        _defineProperty(this, "defaults", {});
119        // Assign
120        this.name = name;
121        this.element = element;
122        this.$element = $(element);
123        this.settings = $.extend(true, {}, this.defaults, options);
124        this.product_variations = this.$element.data('product_variations') || [];
125        this.is_ajax_variation = this.product_variations.length < 1;
126        this.product_id = this.$element.data('product_id');
127        this.reset_variations = this.$element.find('.reset_variations');
128        this.attributeFields = this.$element.find('.variations select');
129        this.attributeSwatchesFields = this.$element.find('ul.variable-items-wrapper');
130        this.selected_item_template = "<span class=\"woo-selected-variation-item-name\" data-default=\"\"></span>";
131        this.$element.addClass('wvs-loaded');
132
133        // Call
134        this.init();
135        this.update();
136
137        // Trigger
138        $(document).trigger('woo_variation_swatches_loaded', this);
139      }
140      return _createClass(_class, [{
141        key: "isAjaxVariation",
142        value: function isAjaxVariation() {
143          //this.product_variations = this.$element.data('product_variations') || []
144          return this.is_ajax_variation; // = this.product_variations.length < 1
145        }
146      }, {
147        key: "init",
148        value: function init() {
149          this.prepareLabel();
150          this.prepareItems();
151          this.setupItems();
152          this.setupEvents();
153          this.setUpStockInfo();
154          this.deselectNonAvailable();
155        }
156      }, {
157        key: "prepareLabel",
158        value: function prepareLabel() {
159          var _this = this;
160          // Append Selected Item Template
161          if (filterBoolean(woo_variation_swatches_options.show_variation_label)) {
162            this.$element.find('.variations .label').each(function (index, el) {
163              // To fix Composite product re insert label issue.
164              if ($(el).find('.woo-selected-variation-item-name').length === 0) {
165                $(el).append(_this.selected_item_template);
166              }
167            });
168          }
169        }
170      }, {
171        key: "prepareItems",
172        value: function prepareItems() {
173          this.attributeSwatchesFields.each(function (i, el) {
174            $(el).parent().addClass('woo-variation-items-wrapper');
175          });
176        }
177      }, {
178        key: "setupItems",
179        value: function setupItems() {
180          var _this2 = this;
181          var self = this;
182          this.attributeSwatchesFields.each(function (i, element) {
183            var selected = '';
184            var select = $(element).parent().find('select.woo-variation-raw-select');
185            var available_options = select.find('option');
186            var disabled_out_of_stock_options = select.find('option:disabled');
187            var enabled_out_of_stock_options = select.find('option.enabled.out-of-stock');
188            var current = select.find('option:selected');
189            var eq = select.find('option').eq(1);
190            var attribute_name = $(element).data('attribute_name');
191            var all_options = $(element).data('attribute_values');
192            var current_options = [];
193            var available_out_of_stocks = [];
194            var disabled_out_of_stocks = [];
195
196            // Available Options
197            available_options.each(function () {
198              if ($(this).val() !== '') {
199                current_options.push($(this).val());
200                selected = current.length === 0 ? eq.val() : current.val();
201              }
202            });
203
204            // Settings: Disabled Out Of Stock Item
205            disabled_out_of_stock_options.each(function () {
206              if ($(this).val() !== '') {
207                disabled_out_of_stocks.push($(this).val());
208              }
209            });
210
211            // Settings: Enabled Out Of Stock Item
212            enabled_out_of_stock_options.each(function () {
213              if ($(this).val() !== '') {
214                available_out_of_stocks.push($(this).val());
215              }
216            });
217            var in_stocks = _.difference(current_options, disabled_out_of_stocks);
218            var disabled_values = [].concat(_toConsumableArray(_.difference(all_options, current_options)), disabled_out_of_stocks);
219            _this2.setupItem(element, selected, in_stocks, available_out_of_stocks, disabled_values);
220          });
221        }
222      }, {
223        key: "setupItem",
224        value: function setupItem(element, selected, in_stocks, out_of_stocks, disabled_values) {
225          var _this3 = this;
226          var $selected_variation_item = $(element).parent().prev().find('.woo-selected-variation-item-name');
227
228          // Mark Selected
229          $(element).find('li.variable-item').each(function (index, el) {
230            var attribute_value = $(el).attr('data-value');
231            var attribute_title = $(el).attr('data-title');
232
233            // Resetting LI
234            $(el).removeClass('selected disabled no-stock').addClass('disabled');
235            $(el).attr('aria-checked', 'false');
236            $(el).attr('tabindex', '-1');
237            $(el).attr('data-wvstooltip-out-of-stock', '');
238            $(el).find('input.variable-item-radio-input:radio').prop('disabled', true).prop('checked', false);
239
240            // To Prevent blink
241            if (selected.length < 1 && filterBoolean(woo_variation_swatches_options.show_variation_label)) {
242              $selected_variation_item.text('');
243            }
244
245            // Ajax variation
246            if (_this3.isAjaxVariation()) {
247              $(el).find('input.variable-item-radio-input:radio').prop('disabled', false);
248              $(el).removeClass('selected disabled no-stock');
249
250              // Selected
251              if (attribute_value === selected) {
252                $(el).addClass('selected');
253                $(el).attr('aria-checked', 'true');
254                $(el).attr('tabindex', '0');
255                $(el).find('input.variable-item-radio-input:radio').prop('disabled', false).prop('checked', true);
256                if (filterBoolean(woo_variation_swatches_options.show_variation_label)) {
257                  $selected_variation_item.text("".concat(woo_variation_swatches_options.variation_label_separator, " ").concat(attribute_title));
258                }
259                $(el).trigger('wvs-item-updated', [selected, attribute_value]);
260              }
261            } else {
262              // Default Selected
263              // We can't use es6 includes for IE11
264              // in_stocks.includes(attribute_value)
265              // _.contains(in_stocks, attribute_value)
266              // _.includes(in_stocks, attribute_value)
267
268              if (_.includes(in_stocks, attribute_value)) {
269                $(el).removeClass('selected disabled');
270                $(el).removeAttr('aria-hidden');
271                $(el).attr('tabindex', '0');
272                $(el).find('input.variable-item-radio-input:radio').prop('disabled', false);
273
274                // Selected
275                if (attribute_value === selected) {
276                  $(el).addClass('selected');
277                  $(el).attr('aria-checked', 'true');
278                  $(el).find('input.variable-item-radio-input:radio').prop('checked', true);
279                  if (filterBoolean(woo_variation_swatches_options.show_variation_label)) {
280                    $selected_variation_item.text("".concat(woo_variation_swatches_options.variation_label_separator, " ").concat(attribute_title));
281                  }
282                  $(el).trigger('wvs-item-updated', [selected, attribute_value]);
283                }
284              }
285
286              // Out of Stock
287              if (_.includes(out_of_stocks, attribute_value)) {
288                $(el).attr('data-wvstooltip-out-of-stock', woo_variation_swatches_options.out_of_stock_tooltip_text);
289                if (filterBoolean(woo_variation_swatches_options.clickable_out_of_stock)) {
290                  $(el).removeClass('disabled').addClass('no-stock');
291                }
292              }
293
294              // Disabled
295              if (_.includes(disabled_values, attribute_value)) {
296                $(el).attr('data-wvstooltip-out-of-stock', woo_variation_swatches_options.unavailable_tooltip_text);
297              }
298            }
299          });
300        }
301      }, {
302        key: "setupEvents",
303        value: function setupEvents() {
304          var $element = this.$element;
305          this.attributeSwatchesFields.each(function (i, element) {
306            var select = $(element).parent().find('select.woo-variation-raw-select');
307
308            // Trigger Select event based on list
309            if (filterBoolean(woo_variation_swatches_options.clear_on_reselect)) {
310              // Non Selected Item Should Select
311              $(element).on('click.wvs', 'li.variable-item:not(.selected):not(.radio-variable-item)', function (event) {
312                event.preventDefault();
313                event.stopPropagation();
314                var attribute_name = $(this).data('attribute_name');
315                var attribute_value = $(this).data('value');
316                select.val(attribute_value).trigger('change');
317                select.trigger('click');
318                $(this).trigger('wvs-selected-item', [attribute_name, attribute_value, select, $element]); // Custom Event for li
319              });
320
321              // Selected Item Should un Select
322              $(element).on('click.wvs', 'li.variable-item.selected:not(.radio-variable-item)', function (event) {
323                event.preventDefault();
324                event.stopPropagation();
325                var attribute_name = $(this).data('attribute_name');
326                var attribute_value = $(this).data('value');
327                select.val('').trigger('change');
328                select.trigger('click');
329                $(this).trigger('wvs-unselected-item', [attribute_name, attribute_value, select, $element]); // Custom Event for li
330              });
331
332              // RADIO
333
334              // On Click trigger change event on Radio button
335              $(element).on('click.wvs', 'input.variable-item-radio-input:radio', function (event) {
336                event.stopPropagation();
337                $(this).trigger('change.wvs', {
338                  radioChange: true
339                });
340              });
341              $(element).on('change.wvs', 'input.variable-item-radio-input:radio', function (event, params) {
342                event.preventDefault();
343                event.stopPropagation();
344                if (params && params.radioChange) {
345                  var attribute_name = $(this).data('attribute_name');
346                  var attribute_value = $(this).val();
347                  var is_selected = $(this).parent('li.radio-variable-item').hasClass('selected');
348                  if (is_selected) {
349                    select.val('').trigger('change');
350                    $(this).closest('li.radio-variable-item').trigger('wvs-unselected-item', [attribute_name, attribute_value, select, $element]); // Custom Event for li
351                  } else {
352                    select.val(attribute_value).trigger('change');
353                    $(this).closest('li.radio-variable-item').trigger('wvs-selected-item', [attribute_name, attribute_value, select, $element]); // Custom Event for li
354                  }
355                  select.trigger('click');
356                }
357              });
358            } else {
359              $(element).on('click.wvs', 'li.variable-item:not(.radio-variable-item)', function (event) {
360                event.preventDefault();
361                event.stopPropagation();
362                var attribute_name = $(this).data('attribute_name');
363                var attribute_value = $(this).data('value');
364                select.val(attribute_value).trigger('change');
365                select.trigger('click');
366                $(this).trigger('wvs-selected-item', [attribute_name, attribute_value, select, $element]); // Custom Event for li
367              });
368
369              // Radio
370              $(element).on('change.wvs', 'input.variable-item-radio-input:radio', function (event) {
371                event.preventDefault();
372                event.stopPropagation();
373                var attribute_name = $(this).data('attribute_name');
374                var attribute_value = $(this).val();
375                select.val(attribute_value).trigger('change');
376                select.trigger('click');
377
378                // Radio
379                $(this).closest('li.radio-variable-item').removeClass('selected disabled no-stock').addClass('selected');
380                $(this).closest('li.radio-variable-item').trigger('wvs-selected-item', [attribute_name, attribute_value, select, $element]); // Custom Event for li
381              });
382            }
383
384            // Keyboard Access
385            $(element).on('keydown.wvs', 'li.variable-item:not(.disabled)', function (event) {
386              if (event.keyCode && 32 === event.keyCode || event.key && ' ' === event.key || event.keyCode && 13 === event.keyCode || event.key && 'enter' === event.key.toLowerCase()) {
387                event.preventDefault();
388                $(this).trigger('click');
389              }
390            });
391          });
392          this.$element.on('click.wvs', '.woo-variation-swatches-variable-item-more', function (event) {
393            event.preventDefault();
394            $(this).parent().removeClass('enabled-display-limit-mode enabled-catalog-display-limit-mode');
395            $(this).remove();
396          });
397          this.$element.find('[data-wvstooltip]').each(function (i, element) {
398            $(element).on('mouseenter', function (event) {
399              var rect = element.getBoundingClientRect();
400              var tooltip = window.getComputedStyle(element, ':before');
401              var arrow = window.getComputedStyle(element, ':after');
402              var arrowHeight = parseInt(arrow.getPropertyValue('border-top-width'), 10);
403              var tooltipHeight = parseInt(tooltip.getPropertyValue('height'), 10);
404              var tooltipWidth = parseInt(tooltip.getPropertyValue('width'), 10);
405              var offset = 2;
406              var calculateTooltipPosition = tooltipHeight + arrowHeight + offset;
407              element.classList.toggle('wvs-tooltip-position-bottom', rect.top < calculateTooltipPosition);
408              var width = tooltipWidth / 2;
409              var position = rect.left + rect.width / 2;
410
411              // Left
412              var left = width - position;
413              var isLeft = width > position;
414              var computedRight = width + position;
415              var isRight = document.body.clientWidth < computedRight;
416              var right = document.body.clientWidth - computedRight;
417              element.style.setProperty('--horizontal-position', "0px");
418              if (isLeft) {
419                element.style.setProperty('--horizontal-position', "".concat(left + offset, "px"));
420              }
421              if (isRight) {
422                element.style.setProperty('--horizontal-position', "".concat(right - offset, "px"));
423              }
424              //
425            });
426          });
427        }
428      }, {
429        key: "extractAttributes",
430        value: function extractAttributes(selected) {
431          var result = new Set();
432          var _iterator = _createForOfIteratorHelper(this.product_variations),
433            _step;
434          try {
435            for (_iterator.s();
435 !(_step = _iterator.n()).done;) {
436              var variation = _step.value;
437              var attributes = variation.attributes;
438              for (var attribute_name in attributes) {
439                if (attributes[attribute_name].length > 0) {
440                  result.add(attribute_name);
441                }
442              }
443            }
444          } catch (err) {
445            _iterator.e(err);
446          } finally {
447            _iterator.f();
448          }
449          result["delete"](selected);
450          return Array.from(result);
451        }
452      }, {
453        key: "getUnavailableAttributes",
454        value: function getUnavailableAttributes(currentChosen, selected) {
455          var availableVariations = this.findMatchingVariations(this.product_variations, currentChosen).filter(function (variation) {
456            if (filterBoolean(woo_variation_swatches_options.disable_out_of_stock)) {
457              return variation.is_in_stock;
458            }
459            return true;
460          });
461          if (availableVariations.length === 0) {
462            return this.extractAttributes(selected);
463          }
464          return [];
465        }
466      }, {
467        key: "deselectNonAvailable",
468        value: function deselectNonAvailable() {
469          var _this4 = this;
470          if (!filterBoolean(woo_variation_swatches_options.deselect_unavailable)) {
471            return;
472          }
473          this.$element.on('wvs-selected-item.wvs', function (event, attribute_name, attribute_value) {
474            var _this4$getChosenAttri = _this4.getChosenAttributes(),
475              data = _this4$getChosenAttri.data;
476            var currentAttribute = _objectSpread(_objectSpread({}, data), {}, _defineProperty({}, attribute_name, attribute_value.toString()));
477            var unavailableAttributes = _this4.getUnavailableAttributes(currentAttribute, attribute_name);
478            if (unavailableAttributes.length > 0) {
479              var _iterator2 = _createForOfIteratorHelper(unavailableAttributes),
480                _step2;
481              try {
482                for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
483                  var unavailable = _step2.value;
484                  // Unselect unmatched
485                  _this4.attributeSwatchesFields.find("li[data-attribute_name=\"".concat(unavailable, "\"]")).removeClass('selected');
486                  _this4.attributeFields.filter("[data-attribute_name=\"".concat(unavailable, "\"]")).each(function (i, el) {
487                    $(el).val('').trigger('change');
488                  });
489                }
490
491                // Select current
492              } catch (err) {
493                _iterator2.e(err);
494              } finally {
495                _iterator2.f();
496              }
497              _this4.attributeSwatchesFields.filter("[data-attribute_name=\"".concat(attribute_name, "\"]")).each(function () {
498                $(this).find("[data-value=\"".concat(attribute_value, "\"]")).removeClass('disabled').addClass('selected');
499              });
500              _this4.attributeFields.filter("[data-attribute_name=\"".concat(attribute_name, "\"]")).each(function (i, el) {
501                $(el).val(attribute_value).trigger('change');
502              });
503            }
504          });
505        }
506      }, {
507        key: "update",
508        value: function update() {
509          var _this5 = this;
510          // this.$element.off('woocommerce_variation_has_changed.wvs')
511          this.$element.on('woocommerce_variation_has_changed.wvs', function (event) {
512            // Don't use any propagation. It will disable composite product functionality
513            // event.stopPropagation();
514
515            _this5.setupItems();
516          });
517        }
518      }, {
519        key: "setUpStockInfo",
520        value: function setUpStockInfo() {
521          var _this6 = this;
522          if (filterBoolean(woo_variation_swatches_options.show_variation_stock)) {
523            var max_stock_label = parseInt(woo_variation_swatches_options.stock_label_threshold, 10);
524            this.$element.on('wvs-selected-item.wvs', function (event) {
525              var attributes = _this6.getChosenAttributes();
526              var variations = _this6.findStockVariations(_this6.product_variations, attributes);
527              if (attributes.count > 1 && attributes.count === attributes.chosenCount) {
528                _this6.resetStockInfo();
529              }
530              if (attributes.count > 1 && attributes.count === attributes.mayChosenCount) {
531                variations.forEach(function (data) {
532                  var stockInfoSelector = "[data-attribute_name=\"".concat(data.attribute_name, "\"] > [data-value=\"").concat(data.attribute_value, "\"]");
533                  if (data.variation.is_in_stock && data.variation.max_qty && data.variation.variation_stock_left && data.variation.max_qty <= max_stock_label) {
534                    _this6.$element.find("".concat(stockInfoSelector, " .wvs-stock-left-info")).attr('data-wvs-stock-info', data.variation.variation_stock_left);
535                    _this6.$element.find(stockInfoSelector).addClass('wvs-show-stock-left-info');
536                  } else {
537                    _this6.$element.find(stockInfoSelector).removeClass('wvs-show-stock-left-info');
538                    _this6.$element.find("".concat(stockInfoSelector, " .wvs-stock-left-info")).attr('data-wvs-stock-info', '');
539                  }
540                });
541              }
542            });
543            this.$element.on('hide_variation.wvs', function () {
544              _this6.resetStockInfo();
545            });
546          }
547        }
548      }, {
549        key: "resetStockInfo",
550        value: function resetStockInfo() {
551          this.$element.find('.variable-item').removeClass('wvs-show-stock-left-info');
552          this.$element.find('.wvs-stock-left-info').attr('data-wvs-stock-info', '');
553        }
554      }, {
555        key: "getChosenAttributes",
556        value: function getChosenAttributes() {
557          var data = {};
558          var count = 0;
559          var chosen = 0;
560          this.attributeFields.each(function () {
561            var attribute_name = $(this).data('attribute_name') || $(this).attr('name');
562            var value = $(this).val() || '';
563            if (value.length > 0) {
564              chosen++;
565            }
566            count++;
567            data[attribute_name] = value;
568          });
569          return {
570            'count': count,
571            'chosenCount': chosen,
572            'mayChosenCount': chosen + 1,
573            'data': data
574          };
575        }
576      }, {
577        key: "findStockVariations",
578        value: function findStockVariations(allVariations, selectedAttributes) {
579          var found = [];
580          for (var _i2 = 0, _Object$entries2 = Object.entries(selectedAttributes.data); _i2 < _Object$entries2.length; _i2++) {
581            var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
582              attribute_name = _Object$entries2$_i[0],
583              attribute_value = _Object$entries2$_i[1];
584            if (attribute_value.length === 0) {
585              var values = this.$element.find("ul[data-attribute_name='".concat(attribute_name, "']")).data('attribute_values') || [];
586              var _iterator3 = _createForOfIteratorHelper(values),
587                _step3;
588              try {
589                for (_iterator3.s();
589 !(_step3 = _iterator3.n()).done;) {
590                  var value = _step3.value;
591                  var compare = _.extend(selectedAttributes.data, _defineProperty({}, attribute_name, value));
592                  var matched_variation = this.findMatchingVariations(allVariations, compare);
593                  if (matched_variation.length > 0) {
594                    var variation = matched_variation.shift();
595                    var data = {};
596                    data['attribute_name'] = attribute_name;
597                    data['attribute_value'] = value;
598                    data['variation'] = variation;
599                    found.push(data);
600                  }
601                }
602              } catch (err) {
603                _iterator3.e(err);
604              } finally {
605                _iterator3.f();
606              }
607            }
608          }
609          return found;
610        }
611      }, {
612        key: "findMatchingVariations",
613        value: function findMatchingVariations(variations, attributes) {
614          var matching = [];
615          for (var i = 0; i < variations.length; i++) {
616            var variation = variations[i];
617            if (this.isMatch(variation.attributes, attributes)) {
618              matching.push(variation);
619            }
620          }
621          return matching;
622        }
623      }, {
624        key: "findMatchingVariations2",
625        value: function findMatchingVariations2(variations, attributes) {
626          return variations.filter(function (variation) {
627            return Object.entries(attributes).every(function (_ref) {
628              var _ref2 = _slicedToArray(_ref, 2),
629                attr_name = _ref2[0],
630                attr_value = _ref2[1];
631              var var_attr_value = variation.attributes[attr_name];
632              var notMatch = var_attr_value !== undefined && attr_value !== undefined && var_attr_value.length !== 0 && attr_value.length !== 0 && var_attr_value !== attr_value;
633              return !notMatch;
634            });
635          });
636        }
637      }, {
638        key: "isMatch",
639        value: function isMatch(variation_attributes, attributes) {
640          var match = true;
641          for (var attr_name in variation_attributes) {
642            if (variation_attributes.hasOwnProperty(attr_name)) {
643              var val1 = variation_attributes[attr_name];
644              var val2 = attributes[attr_name];
645              if (val1 !== undefined && val2 !== undefined && val1.length !== 0 && val2.length !== 0 && val1 !== val2) {
646                match = false;
647              }
648            }
649          }
650          return match;
651        }
652      }, {
653        key: "destroy",
654        value: function destroy() {
655          this.$element.removeClass('wvs-loaded');
656          this.$element.removeData(this.name);
657        }
658      }]);
659    }();
660  }(jQuery);
661  var jQueryPlugin = function ($) {
662    return function (PluginName, ClassName) {
663      $.fn[PluginName] = function (options) {
664        var _this7 = this;
665        for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
666          args[_key - 1] = arguments[_key];
667        }
668        return this.each(function (index, element) {
669          var $element = $(element);
670          // let $element = $(this)
671
672          var data = $element.data(PluginName);
673          if (!data) {
674            data = new ClassName($element, $.extend({}, options), PluginName);
675            $element.data(PluginName, data);
676          }
677          if (typeof options === 'string') {
678            if (_typeof(data[options]) === 'object') {
679              return data[options];
680            }
681            if (typeof data[options] === 'function') {
682              var _data;
683              return (_data = data)[options].apply(_data, args);
684            }
685          }
686          return _this7;
687        });
688      };
689
690      // Constructor
691      $.fn[PluginName].Constructor = ClassName;
692
693      // Short hand
694      $[PluginName] = function (options) {
695        var _$;
696        for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
697          args[_key2 - 1] = arguments[_key2];
698        }
699        return (_$ = $({}))[PluginName].apply(_$, [options].concat(args));
700      };
701
702      // No Conflict
703      $.fn[PluginName].noConflict = function () {
704        return $.fn[PluginName];
705      };
706    };
707  }(jQuery);
708  jQueryPlugin('WooVariationSwatches', Plugin);
709})(window);
710}();
711// This entry needs to be wrapped in an IIFE because it needs to be isolated against other entry modules.
712!function() {
713/*global wp, _, wc_add_to_cart_variation_params, woo_variation_swatches_options */
714
715jQuery(function ($) {
716  try {
717    $(document).on('woo_variation_swatches_init', function () {
718      $('.variations_form:not(.wvs-loaded)').WooVariationSwatches();
719
720      // Any custom product with .woo_variation_swatches_variations_form class to support
721      $('.woo_variation_swatches_variations_form:not(.wvs-loaded)').WooVariationSwatches();
722
723      // Yith Composite Product
724      $('.ywcp_inner_selected_container:not(.wvs-loaded)').WooVariationSwatches();
725    });
726    //.trigger('woo_variation_swatches_init')
727  } catch (err) {
728    // If failed (conflict?) log the error but don't stop other scripts breaking.
729    window.console.log('Variation Swatches:', err);
730  }
731
732  // Init WooVariationSwatches after wc_variation_form script loaded.
733  $(document).on('wc_variation_form.wvs', function (event) {
734    $(document).trigger('woo_variation_swatches_init');
735  });
736
737  // Try to cover global ajax data complete
738  $(document).ajaxComplete(function (event, request, settings) {
739    _.delay(function () {
740      $('.variations_form:not(.wvs-loaded)').each(function () {
741        $(this).wc_variation_form();
742      });
743    }, 1000);
744  });
745
746  // Composite Product Load
747  // JS API: https://docs.woocommerce.com/document/composite-products/composite-products-js-api-reference/
748  $(document.body).on('wc-composite-initializing', '.composite_data', function (event, composite) {
749    composite.actions.add_action('component_options_state_changed', function (self) {
750      $(self.$component_content).find('.variations_form').WooVariationSwatches('destroy');
751    });
752
753    /* composite.actions.add_action('active_scenarios_updated', (self) => {
754       console.log('active_scenarios_updated')
755       $(self.$component_content).find('.variations_form').removeClass('wvs-loaded wvs-pro-loaded')
756     })*/
757  });
758});
759}();
760/******/ })()
761;

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.