PageSourceSearch

https://oeekit.ai/wp-content/plugins/wpc-grouped-product-premium/assets/js/frontend.js?ver=3.1.1

js oeekit.ai collected 2026-10-05 15:23:55 UTC 17,285 bytes, 582 lines download raw bytes

1'use strict';
2
3(function($) {
4  $(function() {
5    if (!$('.woosg-wrap').length) {
6      return;
7    }
8
9    $('.woosg-wrap').each(function() {
10      woosg_init($(this));
11    });
12  });
13
14  $(document).on('woosq_loaded', function() {
15    // WPC Smart Quick View
16    woosg_init($('#woosq-popup .woosg-wrap'));
17  });
18
19  $(document).on('woovr_selected', function(e, selected, variations) {
20    // WPC Variations Radio Buttons
21    var $wrap = variations.closest('.woosg-wrap');
22    var $product = variations.closest('.woosg-product');
23
24    if ($product.length) {
25      var _id = selected.attr('data-id');
26      var _price = selected.attr('data-price');
27      var _regular_price = selected.attr('data-regular-price');
28      var _price_html = selected.attr('data-pricehtml');
29      var _image_src = selected.attr('data-imagesrc');
30      var _purchasable = selected.attr('data-purchasable');
31
32      if (_purchasable === 'yes') {
33        // change data
34        $product.attr('data-id', _id);
35        $product.attr('data-price', _price);
36        $product.attr('data-regular-price', _regular_price);
37
38        // change image
39        $product.find('.woosg-thumb-ori').hide();
40        $product.find('.woosg-thumb-new').
41            html('<img src="' + _image_src + '"/>').show();
42
43        // change price
44        $product.find('.woosg-price-ori').hide();
45        $product.find('.woosg-price-new').html(_price_html).show();
46
47        // change attributes
48        var attrs = {};
49
50        $product.find('select[name^="attribute_"]').each(function() {
51          var name = $(this).attr('name');
52
53          attrs[name] = $(this).val();
54        });
55
56        $product.attr('data-attrs', JSON.stringify(attrs));
57      } else {
58        // reset data
59        $product.attr('data-id', 0);
60        $product.attr('data-price', 0);
61        $product.attr('data-regular-price', 0);
62        $product.attr('data-attrs', '');
63
64        // reset image
65        $product.find('.woosg-thumb-new').html('').hide();
66        $product.find('.woosg-thumb-ori').show();
67
68        // reset price
69        $product.find('.woosg-price-ori').show();
70        $product.find('.woosg-price-new').html('').hide();
71
72        // reset availability
73        $product.find('.woosg-availability').html('').hide();
74      }
75
76      // reset sku, weight & dimensions
77      $('.product_meta .sku').wc_reset_content();
78      $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').
79          wc_reset_content();
80      $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').
81          wc_reset_content();
82    }
83
84    if ($wrap.length) {
85      woosg_init($wrap);
86    }
87  });
88
89  $(document).on('found_variation', function(e, t) {
90    var $wrap = $(e['target']).closest('.woosg-wrap');
91    var $products = $(e['target']).closest('.woosg-products');
92    var $product = $(e['target']).closest('.woosg-product');
93
94    if ($product.length) {
95      if (t['image']['url'] && t['image']['srcset']) {
96        // change image
97        $product.find('.woosg-thumb-ori').hide();
98        $product.find('.woosg-thumb-new').
99            html('<img src="' + t['image']['url'] + '" srcset="' +
100                t['image']['srcset'] + '"/>').
101            show();
102      }
103
104      if (t['price_html']) {
105        // change price
106        $product.find('.woosg-price-ori').hide();
107        $product.find('.woosg-price-new').html(t['price_html']).show();
108      }
109
110      if (t['is_purchasable']) {
111        // change stock notice
112        if (t['is_in_stock']) {
113          $products.next('p.stock').show();
114          $product.attr('data-id', t['variation_id']);
115          $product.attr('data-price', t['display_price']);
116          $product.attr('data-regular-price', t['display_regular_price']);
117
118          // change add to cart button
119          $product.find('.add_to_cart_button').
120              attr('data-product_id', t['variation_id']).
121              attr('data-product_sku', t['sku']).
122              attr('data-quantity', $product.attr('data-qty')).
123              removeClass('product_type_variable').
124              addClass('product_type_simple ajax_add_to_cart').
125              html(woosg_vars.add_to_cart);
126        } else {
127          $products.next('p.stock').hide();
128          $product.attr('data-id', 0);
129          $product.attr('data-price', 0);
130          $product.attr('data-regular-price', 0);
131
132          // reset add to cart button
133          $product.find('.add_to_cart_button').
134              attr('data-product_id', 0).attr('data-product_sku', '').
135              removeClass('product_type_simple ajax_add_to_cart').
136              addClass('product_type_variable').
137              html(woosg_vars.select_options);
138        }
139
140        // change availability text
141        if (t['availability_html'] && t['availability_html'] !== '') {
142          $product.find('.woosg-availability').
143              html(t['availability_html']).
144              show();
145        } else {
146          $product.find('.woosg-availability').html('').hide();
147        }
148      }
149
150      if (t['variation_description'] !== '') {
151        $product.find('.woosg-variation-description').
152            html(t['variation_description']).
153            show();
154      } else {
155        $product.find('.woosg-variation-description').html('').hide();
156      }
157
158      // change attributes
159      var attrs = {};
160
161      $product.find('select[name^="attribute_"]').each(function() {
162        var name = $(this).attr('name');
163
164        attrs[name] = $(this).val();
165      });
166
167      $product.attr('data-attrs', JSON.stringify(attrs));
168
169      if (woosg_vars.change_image === 'no') {
170        // prevent changing the main image
171        $(e['target']).closest('.variations_form').trigger('reset_image');
172      }
173
174      // reset sku, weight & dimensions
175      $('.product_meta .sku').wc_reset_content();
176      $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').
177          wc_reset_content();
178      $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').
179          wc_reset_content();
180
181      if ($wrap.length) {
182        woosg_init($wrap);
183      }
184    }
185  });
186
187  $(document).on('reset_data', function(e) {
188    var $wrap = $(e['target']).closest('.woosg-wrap');
189    var $product = $(e['target']).closest('.woosg-product');
190
191    if ($product.length) {
192      // reset image
193      $product.find('.woosg-thumb-new').html('').hide();
194      $product.find('.woosg-thumb-ori').show();
195
196      // reset price
197      $product.find('.woosg-price-new').html('').hide();
198      $product.find('.woosg-price-ori').show();
199
200      // reset availability
201      $product.find('.woosg-availability').html('').hide();
202
203      // reset desc
204      $product.find('.woosg-variation-description').html('').hide();
205
206      // reset data
207      $product.attr('data-id', 0);
208      $product.attr('data-price', 0);
209      $product.attr('data-regular-price', 0);
210      $product.attr('data-attrs', '');
211
212      // reset add to cart button
213      $product.find('.add_to_cart_button').
214          attr('data-product_id', 0).attr('data-product_sku', '').
215          removeClass('product_type_simple ajax_add_to_cart').
216          addClass('product_type_variable').
217          html(woosg_vars.select_options);
218
219      if ($wrap.length) {
220        woosg_init($wrap);
221      }
222    }
223  });
224
225  $(document).on('click touch', '.single_add_to_cart_button', function(e) {
226    var $this = $(this);
227
228    if ($this.hasClass('woosg-disabled')) {
229      e.preventDefault();
230    }
231  });
232
233  $(document).on('change', '.woosg-checkbox', function() {
234    var $this = $(this);
235    var $wrap = $this.closest('.woosg-wrap');
236
237    if ($this.prop('checked')) {
238      $this.closest('.woosg-product').attr('data-qty', 1);
239    } else {
240      $this.closest('.woosg-product').attr('data-qty', 0);
241    }
242
243    woosg_init($wrap);
244  });
245
246  $(document).on('keyup change', '.woosg-quantity .woosg-qty', function() {
247    var $this = $(this);
248    var $wrap = $this.closest('.woosg-wrap');
249    var qty = parseFloat($this.val());
250    var min = parseFloat($this.closest('.woosg-quantity').attr('data-min'));
251    var max = parseFloat($this.closest('.woosg-quantity').attr('data-max'));
252
253    if ((
254        qty > 0
255    ) && (
256        qty < min
257    )) {
258      qty = min;
259      $this.val(qty);
260    }
261
262    if ((
263        max > 0
264    ) && (
265        qty > max
266    )) {
267      qty = max;
268      $this.val(qty);
269    }
270
271    $this.closest('.woosg-product').attr('data-qty', qty);
272    $this.closest('.woosg-product').
273        find('.add_to_cart_button').
274        attr('data-quantity', qty);
275
276    woosg_init($wrap);
277  });
278
279  $(document).on('change', '.woosg-quantity input[type=radio]', function() {
280    var $this = $(this);
281    var $wrap = $this.closest('.woosg-wrap');
282    var qty = parseFloat($this.val());
283    var min = parseFloat($this.closest('.woosg-quantity').attr('data-min'));
284
285    if ((
286        qty > 0
287    ) && (
288        qty < min
289    )) {
290      qty = min;
291      $this.val(qty);
292    }
293
294    $this.closest('.woosg-product').attr('data-qty', qty);
295
296    woosg_init($wrap);
297  });
298
299  $(document).
300      on('click touch', '.woosg-quantity-plus, .woosg-quantity-minus',
301          function() {
302            // get values
303            var $qty = $(this).
304                    closest('.woosg-quantity').
305                    find('.woosg-qty'),
306                val = parseFloat($qty.val()),
307                max = parseFloat($qty.attr('max')),
308                min = parseFloat($qty.attr('min')),
309                step = $qty.attr('step');
310
311            // format values
312            if (!val || val === '' || val === 'NaN') {
313              val = 0;
314            }
315
316            if (max === '' || max === 'NaN') {
317              max = '';
318            }
319
320            if (min === '' || min === 'NaN') {
321              min = 0;
322            }
323
324            if (step === 'any' || step === '' || step === undefined ||
325                parseFloat(step) === 'NaN') {
326              step = 1;
327            } else {
328              step = parseFloat(step);
329            }
330
331            // change the value
332            if ($(this).is('.woosg-quantity-plus')) {
333              if (max && (
334                  max == val || val > max
335              )) {
336                $qty.val(max);
337              } else {
338                $qty.val((val + step).toFixed(woosg_decimal_places(step)));
339              }
340            } else {
341              if (min && (
342                  min == val || val < min
343              )) {
344                $qty.val(min);
345              } else if (val > 0) {
346                $qty.val((val - step).toFixed(woosg_decimal_places(step)));
347              }
348            }
349
350            // trigger change event
351            $qty.trigger('change');
352          });
353})(jQuery);
354
355function woosg_init($wrap) {
356  var wid = $wrap.attr('data-id');
357  var is_selection = false;
358  var selection_name = '';
359  var is_empty = true;
360  var $products = $wrap.find('.woosg-products');
361  var $alert = $wrap.find('.woosg-alert');
362  var $ids = jQuery('.woosg-ids-' + wid);
363  var $btn = $ids.closest('form.cart').find('.single_add_to_cart_button');
364
365  $products.find('.woosg-product').each(function() {
366    var $this = jQuery(this);
367
368    if ((
369        $this.attr('data-qty') > 0
370    ) && (
371        $this.attr('data-id') == 0
372    )) {
373      is_selection = true;
374
375      if (selection_name === '') {
376        selection_name = $this.attr('data-name');
377      }
378    }
379
380    if ($this.attr('data-qty') > 0) {
381      is_empty = false;
382    }
383  });
384
385  if (is_selection || is_empty) {
386    $btn.addClass('woosg-disabled');
387
388    if (is_selection) {
389      $alert.
390          html(woosg_vars.alert_selection.replace('[name]',
391              '<strong>' + selection_name + '</strong>')).
392          slideDown();
393    } else if (is_empty) {
394      $alert.html(woosg_vars.alert_empty).slideDown();
395    }
396
397    jQuery(document).
398        trigger('woosg_check_ready', [false, is_selection, is_empty, $wrap]);
399  } else {
400    $alert.html('').slideUp();
401    $btn.removeClass('woosg-disabled');
402
403    // ready
404    jQuery(document).
405        trigger('woosg_check_ready', [true, is_selection, is_empty, $wrap]);
406  }
407
408  woosg_calc_price($wrap);
409  woosg_save_ids($wrap);
410
411  jQuery(document).trigger('woosg_init', [$wrap]);
412}
413
414function woosg_calc_price($wrap) {
415  var total = 0;
416  var total_regular = 0;
417  var wid = $wrap.attr('data-id');
418  var $woobt = jQuery('.woobt-wrap-' + wid);
419  var $price = jQuery('.woosg-price-' + wid);
420  var $products = $wrap.find('.woosg-products');
421  var $total = $wrap.find('.woosg-total');
422
423  $products.find('.woosg-product').each(function() {
424    var $this = jQuery(this);
425
426    if ((
427        parseFloat($this.attr('data-price')) > 0
428    ) && (
429        parseFloat($this.attr('data-regular-price')) > 0
430    ) && (
431        parseFloat($this.attr('data-qty')) > 0
432    )) {
433      total += parseFloat($this.attr('data-price')) *
434          parseFloat($this.attr('data-qty'));
435      total_regular += parseFloat($this.attr('data-regular-price')) *
436          parseFloat($this.attr('data-qty'));
437    }
438  });
439
440  var total_html = woosg_price_html(total_regular, total);
441
442  $total.html(woosg_vars.total_text + ' ' + total_html).slideDown();
443
444  if (woosg_vars.change_price !== 'no') {
445    // change the main price
446    if ((woosg_vars.change_price === 'yes_custom') &&
447        (woosg_vars.price_selector !== null) &&
448        (woosg_vars.price_selector !== '')) {
449      $price = jQuery(woosg_vars.price_selector);
450    }
451
452    $price.html(total_html);
453  }
454
455  if ($woobt.length) {
456    $woobt.find('.woobt-products').attr('data-product-price-html', total_html);
457    $woobt.find('.woobt-product-this').
458        attr('data-price', total).
459        attr('data-regular-price', total_regular);
460
461    woobt_init($woobt);
462  }
463
464  jQuery(document).
465      trigger('woosg_calc_price', [total, total_regular, total_html, $wrap]);
466}
467
468function woosg_save_ids($wrap) {
469  var ids = Array();
470  var wid = $wrap.attr('data-id');
471  var $products = $wrap.find('.woosg-products');
472  var $ids = jQuery('.woosg-ids-' + wid);
473
474  $products.find('.woosg-product').each(function() {
475    var $this = jQuery(this);
476    var id = parseInt($this.attr('data-id'));
477    var qty = parseFloat($this.attr('data-qty'));
478    var attrs = $this.attr('data-attrs');
479
480    if ((id > 0) && (qty > 0)) {
481      if (attrs != undefined) {
482        attrs = encodeURIComponent(attrs);
483      } else {
484        attrs = '';
485      }
486
487      ids.push(id + '/' + qty + '/' + attrs);
488    }
489  });
490
491  $ids.val(ids.join(','));
492  jQuery(document).trigger('woosg_save_ids', [ids, $wrap]);
493}
494
495function woosg_decimal_places(num) {
496  var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
497
498  if (!match) {
499    return 0;
500  }
501
502  return Math.max(
503      0,
504      // Number of digits right of decimal point.
505      (match[1] ? match[1].length : 0)
506      // Adjust for scientific notation.
507      - (match[2] ? +match[2] : 0));
508}
509
510function woosg_format_money(number, places, symbol, thousand, decimal) {
511  number = number || 0;
512  places = !isNaN(places = Math.abs(places)) ? places : 2;
513  symbol = symbol !== undefined ? symbol : '$';
514  thousand = thousand || ',';
515  decimal = decimal || '.';
516
517  var negative = number < 0 ? '-' : '',
518      i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '',
519      j = 0;
520
521  if (i.length > 3) {
522    j = i.length % 3;
523  }
524
525  return symbol + negative + (
526      j ? i.substr(0, j) + thousand : ''
527  ) + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (
528      places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : ''
529  );
530}
531
532function woosg_format_price(price) {
533  var price_html = '<span class="woocommerce-Price-amount amount">';
534  var price_formatted = woosg_format_money(price, woosg_vars.price_decimals, '',
535      woosg_vars.price_thousand_separator, woosg_vars.price_decimal_separator);
536
537  switch (woosg_vars.price_format) {
538    case '%1$s%2$s':
539      //left
540      price_html += '<span class="woocommerce-Price-currencySymbol">' +
541          woosg_vars.currency_symbol + '</span>' + price_formatted;
542      break;
543    case '%1$s %2$s':
544      //left with space
545      price_html += '<span class="woocommerce-Price-currencySymbol">' +
546          woosg_vars.currency_symbol + '</span> ' + price_formatted;
547      break;
548    case '%2$s%1$s':
549      //right
550      price_html += price_formatted +
551          '<span class="woocommerce-Price-currencySymbol">' +
552          woosg_vars.currency_symbol + '</span>';
553      break;
554    case '%2$s %1$s':
555      //right with space
556      price_html += price_formatted +
557          ' <span class="woocommerce-Price-currencySymbol">' +
558          woosg_vars.currency_symbol + '</span>';
559      break;
560    default:
561      //default
562      price_html += '<span class="woocommerce-Price-currencySymbol">' +
563          woosg_vars.currency_symbol + '</span>' + price_formatted;
564  }
565
566  price_html += '</span>';
567
568  return price_html;
569}
570
571function woosg_price_html(regular_price, sale_price) {
572  var price_html = '';
573
574  if (sale_price < regular_price) {
575    price_html = '<del>' + woosg_format_price(regular_price) + '</del> <ins>' +
576        woosg_format_price(sale_price) + '</ins>';
577  } else {
578    price_html = woosg_format_price(regular_price);
579  }
580
581  return price_html;
582}

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.