PageSourceSearch

https://ares.lk/wp-content/plugins/woo-product-bundle-premium/assets/js/frontend.js?ver=6.0.9

js ares.lk collected 2026-10-07 10:30:13 UTC 21,822 bytes, 727 lines download raw bytes

1'use strict';
2
3(function($) {
4  var woosb_timeout = null;
5
6  $(function() {
7    if (!$('.woosb-wrap').length) {
8      return;
9    }
10
11    $('.woosb-wrap').each(function() {
12      woosb_init($(this));
13    });
14  });
15
16  $(document).on('woosq_loaded', function() {
17    // product bundles in quick view popup
18    woosb_init($('#woosq-popup .woosb-wrap'));
19  });
20
21  $(document).on('woovr_selected', function(e, selected, variations) {
22    var $wrap = variations.closest('.woosb-wrap');
23    var $product = variations.closest('.woosb-product');
24
25    if ($product.length) {
26      var _id = selected.attr('data-id');
27      var _price = selected.attr('data-price');
28      var _regular_price = selected.attr('data-regular-price');
29      var _price_html = selected.attr('data-pricehtml');
30      var _image_src = selected.attr('data-imagesrc');
31      var _purchasable = selected.attr('data-purchasable');
32      var _attrs = selected.attr('data-attrs');
33
34      if (_purchasable === 'yes' && _id >= 0) {
35        // change data
36        $product.attr('data-id', _id);
37        $product.attr('data-price', _price);
38
39        // change price
40        woosb_change_price($product, _price, _regular_price, _price_html);
41
42        // change image
43        if (_image_src && _image_src !== '') {
44          $product.find('.woosb-thumb-ori').hide();
45          $product.find('.woosb-thumb-new').
46              html('<img src="' + _image_src + '"/>').
47              show();
48        } else {
49          $product.find('.woosb-thumb-ori').show();
50          $product.find('.woosb-thumb-new').html('').hide();
51        }
52
53        // change attributes
54        $product.attr('data-attrs', _attrs.replace(/\/$/, ''));
55      } else {
56        // reset data
57        $product.attr('data-id', 0);
58        $product.attr('data-price', 0);
59        $product.attr('data-attrs', '');
60
61        // reset price
62        $product.find('.woosb-price-ori').show();
63        $product.find('.woosb-price-new').html('').hide();
64
65        // reset image
66        $product.find('.woosb-thumb-ori').show();
67        $product.find('.woosb-thumb-new').html('').hide();
68      }
69
70      // reset sku, weight & dimensions
71      $('.product_meta .sku').wc_reset_content();
72      $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').
73          wc_reset_content();
74      $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').
75          wc_reset_content();
76    }
77
78    woosb_init($wrap);
79  });
80
81  $(document).on('found_variation', function(e, t) {
82    var $wrap = $(e['target']).closest('.woosb-wrap');
83    var $product = $(e['target']).closest('.woosb-product');
84
85    if ($product.length) {
86      if (t['image']['url'] && t['image']['url'] !== '') {
87        var image_src = t['image']['url'];
88
89        if (t['image']['thumb_src'] && t['image']['thumb_src'] !== '') {
90          image_src = t['image']['thumb_src'];
91        }
92
93        // change image
94        $product.find('.woosb-thumb-ori').hide();
95
96        if (t['image']['srcset'] && t['image']['srcset'] !== '') {
97          $product.find('.woosb-thumb-new').
98              html('<img src="' + image_src + '" srcset="' +
99                  t['image']['srcset'] + '"/>').
100              show();
101        } else {
102          $product.find('.woosb-thumb-new').
103              html('<img src="' + image_src + '"/>').
104              show();
105        }
106      } else {
107        $product.find('.woosb-thumb-ori').show();
108        $product.find('.woosb-thumb-new').html('').hide();
109      }
110
111      if (t['price_html'] !== undefined && t['price_html'] !== '' &&
112          t['display_price'] !== undefined && t['display_price'] !== '') {
113        woosb_change_price($product, t['display_price'],
114            t['display_regular_price'], t['price_html']);
115      }
116
117      if (t['variation_description'] !== undefined) {
118        $product.find('.woosb-variation-description').
119            html(t['variation_description']).
120            show();
121      } else {
122        $product.find('.woosb-variation-description').html('').hide();
123      }
124
125      if (t['is_purchasable']) {
126        // change the price
127        if (woosb_vars.bundled_price_from === 'regular_price' &&
128            t['display_regular_price'] !== undefined) {
129          $product.attr('data-price', t['display_regular_price']);
130        } else {
131          $product.attr('data-price', t['display_price']);
132        }
133
134        // change stock notice
135        if (t['is_in_stock']) {
136          $wrap.next('p.stock').show();
137          $product.attr('data-id', t['variation_id']);
138        } else {
139          $wrap.next('p.stock').hide();
140          $product.attr('data-id', 0);
141        }
142
143        // change availability
144        if (t['availability_html'] && t['availability_html'] !== '') {
145          $product.find('.woosb-availability').
146              html(t['availability_html']).
147              show();
148        } else {
149          $product.find('.woosb-availability').html('').hide();
150        }
151
152        // change attributes
153        var attrs = {};
154
155        $product.find('select[name^="attribute_"]').each(function() {
156          var attr_name = $(this).attr('name');
157
158          attrs[attr_name] = $(this).val();
159        });
160
161        $product.attr('data-attrs', JSON.stringify(attrs));
162      }
163
164      if (woosb_vars.change_image === 'no') {
165        // prevent changing the main image
166        $(e['target']).closest('.variations_form').trigger('reset_image');
167      }
168
169      // reset sku, weight & dimensions
170      $('.product_meta .sku').wc_reset_content();
171      $('.product_weight, .woocommerce-product-attributes-item--weight .woocommerce-product-attributes-item__value').
172          wc_reset_content();
173      $('.product_dimensions, .woocommerce-product-attributes-item--dimensions .woocommerce-product-attributes-item__value').
174          wc_reset_content();
175
176      $(document).trigger('woosb_found_variation', [$product, t]);
177
178      woosb_init($wrap);
179    }
180  });
181
182  $(document).on('reset_data', function(e) {
183    var $wrap = $(e['target']).closest('.woosb-wrap');
184    var $products = $(e['target']).closest('.woosb-products');
185    var $product = $(e['target']).closest('.woosb-product');
186
187    if ($product.length) {
188      // reset thumb
189      $product.find('.woosb-thumb-new').hide();
190      $product.find('.woosb-thumb-ori').show();
191
192      // reset price
193      $product.find('.woosb-price-new').hide();
194      $product.find('.woosb-price-ori').show();
195
196      // reset availability
197      $product.find('.woosb-availability').html('').hide();
198
199      // reset desc
200      $product.find('.woosb-variation-description').html('').hide();
201
202      // reset data
203      $product.attr('data-id', 0);
204      $product.attr('data-price', 0);
205      $product.attr('data-attrs', '');
206
207      $(document).trigger('woosb_reset_data', [$product]);
208
209      woosb_init($wrap);
210    }
211  });
212
213  $(document).
214      on('click touch', '.woosb-qty-input-plus, .woosb-qty-input-minus',
215          function() {
216            // get values
217            var $qty = $(this).closest('.woosb-qty-input').find('.qty'),
218                val = parseFloat($qty.val()),
219                max = parseFloat($qty.attr('max')),
220                min = parseFloat($qty.attr('min')),
221                step = $qty.attr('step');
222
223            // format values
224            if (!val || val === '' || val === 'NaN') {
225              val = 0;
226            }
227
228            if (max === '' || max === 'NaN') {
229              max = '';
230            }
231
232            if (min === '' || min === 'NaN') {
233              min = 0;
234            }
235
236            if (step === 'any' || step === '' || step === undefined ||
237                parseFloat(step) === 'NaN') {
238              step = 1;
239            } else {
240              step = parseFloat(step);
241            }
242
243            // change the value
244            if ($(this).is('.woosb-qty-input-plus')) {
245              if (max && (
246                  max == val || val > max
247              )) {
248                $qty.val(max);
249              } else {
250                $qty.val((val + step).toFixed(woosb_decimal_places(step)));
251              }
252            } else {
253              if (min && (
254                  min == val || val < min
255              )) {
256                $qty.val(min);
257              } else if (val > 0) {
258                $qty.val((val - step).toFixed(woosb_decimal_places(step)));
259              }
260            }
261
262            // trigger change event
263            $qty.trigger('change');
264          });
265
266  $(document).on('click touch', '.single_add_to_cart_button', function(e) {
267    var $this = $(this);
268
269    if ($this.hasClass('woosb-disabled')) {
270      e.preventDefault();
271    }
272  });
273
274  $(document).on('change', '.woosb-qty .qty', function() {
275    var $this = $(this);
276
277    woosb_check_qty($this);
278  });
279
280  $(document).on('keyup', '.woosb-qty .qty', function() {
281    var $this = $(this);
282
283    if (woosb_timeout != null) clearTimeout(woosb_timeout);
284    woosb_timeout = setTimeout(woosb_check_qty, 1000, $this);
285  });
286})(jQuery);
287
288function woosb_init($wrap) {
289  woosb_check_ready($wrap);
290  woosb_calc_price($wrap);
291  woosb_save_ids($wrap);
292
293  jQuery(document).trigger('woosb_init', [$wrap]);
294}
295
296function woosb_check_ready($wrap) {
297  var total = 0;
298  var selection_name = '';
299  var is_selection = false;
300  var is_empty = true;
301  var is_min = false;
302  var is_max = false;
303  var wid = $wrap.attr('data-id');
304  var $products = $wrap.find('.woosb-products');
305  var $alert = $wrap.find('.woosb-alert');
306  var $ids = jQuery('.woosb-ids-' + wid);
307  var $btn = $ids.closest('form.cart').find('.single_add_to_cart_button');
308
309  // remove ajax add to cart
310  $btn.removeClass('ajax_add_to_cart');
311
312  if (!$products.length ||
313      (($products.attr('data-variables') === 'no') &&
314          ($products.attr('data-optional') === 'no'))) {
315    // don't need to do anything
316    return;
317  }
318
319  $products.find('.woosb-product').each(function() {
320    var $this = jQuery(this);
321
322    if ((
323        parseFloat($this.attr('data-qty')) > 0
324    ) && (
325        parseInt($this.attr('data-id')) === 0
326    )) {
327      is_selection = true;
328
329      if (selection_name === '') {
330        selection_name = $this.attr('data-name');
331      }
332    }
333
334    if (parseFloat($this.attr('data-qty')) > 0) {
335      is_empty = false;
336      total += parseFloat($this.attr('data-qty'));
337    }
338  });
339
340  // check min
341  if ((
342      $products.attr('data-optional') === 'yes'
343  ) && $products.attr('data-min') && (
344      total < parseFloat($products.attr('data-min'))
345  )) {
346    is_min = true;
347  }
348
349  // check max
350  if ((
351      $products.attr('data-optional') === 'yes'
352  ) && $products.attr('data-max') && (
353      total > parseFloat($products.attr('data-max'))
354  )) {
355    is_max = true;
356  }
357
358  if (is_selection || is_empty || is_min || is_max) {
359    $btn.addClass('woosb-disabled');
360
361    if (is_selection) {
362      $alert.
363          html(woosb_vars.alert_selection.replace('[name]',
364              '<strong>' + selection_name + '</strong>')).slideDown();
365    } else if (is_empty) {
366      $alert.html(woosb_vars.alert_empty).slideDown();
367    } else if (is_min) {
368      $alert.html(
369          woosb_vars.alert_min.replace('[min]', $products.attr('data-min')).
370              replace('[selected]', total)).slideDown();
371    } else if (is_max) {
372      $alert.html(
373          woosb_vars.alert_max.replace('[max]', $products.attr('data-max')).
374              replace('[selected]', total)).slideDown();
375    }
376
377    jQuery(document).
378        trigger('woosb_check_ready',
379            [false, is_selection, is_empty, is_min, is_max, $wrap]);
380  } else {
381    $alert.html('').slideUp();
382    $btn.removeClass('woosb-disabled');
383
384    // ready
385    jQuery(document).
386        trigger('woosb_check_ready',
387            [true, is_selection, is_empty, is_min, is_max, $wrap]);
388  }
389}
390
391function woosb_calc_price($wrap) {
392  var total = 0;
393  var total_sale = 0;
394  var wid = $wrap.attr('data-id');
395  var $products = $wrap.find('.woosb-products');
396  var price_suffix = $products.attr('data-price-suffix');
397  var $total = $wrap.find('.woosb-total');
398  var $price = jQuery('.woosb-price-' + wid);
399  var $woobt = jQuery('.woobt-wrap-' + wid);
400  var total_woobt = parseFloat($woobt.length ? $woobt.attr('data-total') : 0);
401  var discount = parseFloat($products.attr('data-discount'));
402  var discount_amount = parseFloat($products.attr('data-discount-amount'));
403  var fixed_price = $products.attr('data-fixed-price');
404  var saved = '';
405  var fix = Math.pow(10, Number(woosb_vars.price_decimals) + 1);
406  var is_discount = discount > 0 && discount < 100;
407  var is_discount_amount = discount_amount > 0;
408
409  $products.find('.woosb-product').each(function() {
410    var $this = jQuery(this);
411    if (parseFloat($this.attr('data-price')) > 0) {
412      var this_price = parseFloat($this.attr('data-price')) *
413          parseFloat($this.attr('data-qty'));
414      total += this_price;
415      if (!is_discount_amount && is_discount) {
416        this_price *= (100 - discount) / 100;
417        this_price = Math.round(this_price * fix) / fix;
418      }
419      total_sale += this_price;
420    }
421  });
422
423  // fix js number https://www.w3schools.com/js/js_numbers.asp
424  total = woosb_round(total, woosb_vars.price_decimals);
425
426  if (is_discount_amount && discount_amount < total) {
427    total_sale = total - discount_amount;
428    saved = woosb_format_price(discount_amount);
429  } else if (is_discount) {
430    saved = woosb_round(discount, 2) + '%';
431  } else {
432    total_sale = total;
433  }
434
435  if (fixed_price === 'yes') {
436    total_sale = parseFloat($products.attr('data-price'));
437  }
438
439  var total_html = woosb_price_html(total, total_sale);
440  var total_all_html = woosb_price_html(total + total_woobt,
441      total_sale + total_woobt);
442
443  if (saved !== '') {
444    total_html += ' <small class="woocommerce-price-suffix">' +
445        woosb_vars.saved_text.replace('[d]', saved) + '</small>';
446  }
447
448  // change the bundle total
449  $total.html(woosb_vars.price_text + ' ' + total_html + price_suffix
449).
450      slideDown();
451
452  if ((
453      woosb_vars.change_price !== 'no'
454  ) && (
455      $products.attr('data-fixed-price') === 'no'
456  ) && (
457      (
458          $products.attr('data-variables') === 'yes'
459      ) || (
460          $products.attr('data-optional') === 'yes'
461      )
462  )) {
463    if ((woosb_vars.change_price === 'yes_custom') &&
464        (woosb_vars.price_selector != null) &&
465        (woosb_vars.price_selector !== '')) {
466      $price = jQuery(woosb_vars.price_selector);
467    }
468
469    // change the main price
470    if ($woobt.length) {
471      // woobt
472      $price.html(total_all_html + price_suffix);
473    } else {
474      $price.html(total_html + price_suffix);
475    }
476  }
477
478  if ($woobt.length) {
479    // woobt
480    $woobt.find('.woobt-products').attr('data-product-price-html', total_html);
481    $woobt.find('.woobt-product-this').
482        attr('data-price', total_sale).
483        attr('data-regular-price', total);
484
485    woobt_init($woobt);
486  }
487
488  jQuery(document).
489      trigger('woosb_calc_price',
490          [total_sale, total, total_html, price_suffix, $wrap]);
491}
492
493function woosb_save_ids($wrap) {
494  var ids = Array();
495  var wid = $wrap.attr('data-id');
496  var $ids = jQuery('.woosb-ids-' + wid);
497  var $products = $wrap.find('.woosb-products');
498
499  $products.find('.woosb-product').each(function() {
500    var $this = jQuery(this);
501    var id = parseInt($this.attr('data-id'));
502    var qty = parseFloat($this.attr('data-qty'));
503    var attrs = $this.attr('data-attrs');
504
505    if ((id > 0) && (qty > 0)) {
506      if (attrs != undefined) {
507        attrs = encodeURIComponent(attrs);
508      } else {
509        attrs = '';
510      }
511
512      ids.push(id + '/' + qty + '/' + attrs);
513    }
514  });
515
516  $ids.val(ids.join(','));
517
518  jQuery(document).trigger('woosb_save_ids', [ids, $wrap]);
519}
520
521function woosb_check_qty($qty) {
522  var $wrap = $qty.closest('.woosb-wrap');
523  var qty = parseFloat($qty.val());
524  var min = parseFloat($qty.attr('min'));
525  var max = parseFloat($qty.attr('max'));
526
527  if ((qty === '') || isNaN(qty)) {
528    qty = 0;
529  }
530
531  if (!isNaN(min) && (
532      qty < min
533  )) {
534    qty = min;
535  }
536
537  if (!isNaN(max) && (
538      qty > max
539  )) {
540    qty = max;
541  }
542
543  $qty.val(qty);
544  $qty.closest('.woosb-product').attr('data-qty', qty);
545
546  // change subtotal
547  if (woosb_vars.bundled_price === 'subtotal') {
548    var $products = $wrap.find('.woosb-products');
549    var $product = $qty.closest('.woosb-product');
550    var price_suffix = $product.attr('data-price-suffix');
551    var ori_price = parseFloat($product.attr('data-price')) *
552        parseFloat($product.attr('data-qty'));
553
554    $product.find('.woosb-price-ori').hide();
555
556    if (parseFloat($products.attr('data-discount')) > 0 &&
557        $products.attr('data-fixed-price') === 'no') {
558      var new_price = ori_price *
559          (100 - parseFloat($products.attr('data-discount'))) / 100;
560
561      $product.find('.woosb-price-new').
562          html(woosb_price_html(ori_price, new_price) + price_suffix).show();
563    } else {
564      $product.find('.woosb-price-new').
565          html(woosb_price_html(ori_price) + price_suffix).
566          show();
567    }
568  }
569
570  jQuery(document).trigger('woosb_check_qty', [qty, $qty]);
571
572  woosb_init($wrap);
573}
574
575function woosb_change_price($product, price, regular_price, price_html) {
576  var $products = $product.closest('.woosb-products');
577  var price_suffix = $product.attr('data-price-suffix');
578
579  // hide ori price
580  $product.find('.woosb-price-ori').hide();
581
582  // calculate new price
583  if (woosb_vars.bundled_price === 'subtotal') {
584    var ori_price = parseFloat(price) *
585        parseFloat($product.attr('data-qty'));
586
587    if (woosb_vars.bundled_price_from === 'regular_price' &&
588        regular_price !== undefined) {
589      ori_price = parseFloat(regular_price) *
590          parseFloat($product.attr('data-qty'));
591    }
592
593    var new_price = ori_price;
594
595    if (parseFloat($products.attr('data-discount')) > 0) {
596      new_price = ori_price *
597          (100 - parseFloat($products.attr('data-discount'))) / 100;
598    }
599
600    $product.find('.woosb-price-new').
601        html(woosb_price_html(ori_price, new_price) + price_suffix
601).show();
602  } else {
603    if (parseFloat($products.attr('data-discount')) > 0) {
604      var ori_price = parseFloat(price);
605
606      if (woosb_vars.bundled_price_from === 'regular_price' &&
607          regular_price !== undefined) {
608        ori_price = parseFloat(regular_price);
609      }
610
611      var new_price = ori_price *
612          (100 - parseFloat($products.attr('data-discount'))) / 100;
613      $product.find('.woosb-price-new').
614          html(woosb_price_html(ori_price, new_price) + price_suffix).show();
615    } else {
616      if (woosb_vars.bundled_price_from === 'regular_price' &&
617          regular_price !== undefined) {
618        $product.find('.woosb-price-new').
619            html(woosb_price_html(regular_price) + price_suffix).
620            show();
621      } else if (price_html !== '') {
622        $product.find('.woosb-price-new').
623            html(price_html).
624            show();
625      }
626    }
627  }
628}
629
630function woosb_round(value, decimals) {
631  return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
632}
633
634function woosb_format_money(number, places, symbol, thousand, decimal) {
635  number = number || 0;
636  places = !isNaN(places = Math.abs(places)) ? places : 2;
637  symbol = symbol !== undefined ? symbol : '$';
638  thousand = thousand || ',';
639  decimal = decimal || '.';
640
641  var negative = number < 0 ? '-' : '',
642      i = parseInt(
643          number = woosb_round(Math.abs(+number || 0), places).toFixed(places),
644          10) + '',
645      j = 0;
646
647  if (i.length > 3) {
648    j = i.length % 3;
649  }
650
651  return symbol + negative + (
652      j ? i.substr(0, j) + thousand : ''
653  ) + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (
654      places ?
655          decimal +
656          woosb_round(Math.abs(number - i), places).toFixed(places).slice(2) :
657          ''
658  );
659}
660
661function woosb_format_price(price) {
662  var price_html = '<span class="woocommerce-Price-amount amount">';
663  var price_formatted = woosb_format_money(price, woosb_vars.price_decimals, '',
664      woosb_vars.price_thousand_separator, woosb_vars.price_decimal_separator);
665
666  switch (woosb_vars.price_format) {
667    case '%1$s%2$s':
668      //left
669      price_html += '<span class="woocommerce-Price-currencySymbol">' +
670          woosb_vars.currency_symbol + '</span>' + price_formatted;
671      break;
672    case '%1$s %2$s':
673      //left with space
674      price_html += '<span class="woocommerce-Price-currencySymbol">' +
675          woosb_vars.currency_symbol + '</span> ' + price_formatted;
676      break;
677    case '%2$s%1$s':
678      //right
679      price_html += price_formatted +
680          '<span class="woocommerce-Price-currencySymbol">' +
681          woosb_vars.currency_symbol + '</span>';
682      break;
683    case '%2$s %1$s':
684      //right with space
685      price_html += price_formatted +
686          ' <span class="woocommerce-Price-currencySymbol">' +
687          woosb_vars.currency_symbol + '</span>';
688      break;
689    default:
690      //default
691      price_html += '<span class="woocommerce-Price-currencySymbol">' +
692          woosb_vars.currency_symbol + '</span> ' + price_formatted;
693  }
694
695  price_html += '</span>';
696
697  return price_html;
698}
699
700function woosb_price_html(regular_price, sale_price) {
701  var price_html = '';
702
703  if (sale_price < regular_price) {
704    price_html = '<del>' + woosb_format_price(regular_price) + '</del> <ins>' +
705        woosb_format_price(sale_price) + '</ins>';
706  } else {
707    price_html = woosb_format_price(regular_price);
708  }
709
710  return price_html;
711}
712
713function woosb_decimal_places(num) {
714  var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
715
716  if (!match) {
717    return 0;
718  }
719
720  return Math.max(
721      0,
722      // Number of digits right of decimal point.
723      (match[1] ? match[1].length : 0)
724      // Adjust for scientific notation.
725      - (match[2] ? +match[2] : 0));
726}
727

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.