PageSourceSearch

https://babmarrakesh.ae/wp-content/plugins/woo-product-bundle/assets/js/frontend.js?ver=8.5.6

js babmarrakesh.ae collected 2026-09-24 14:07:29 UTC 20,323 bytes, 565 lines download raw bytes

1'use strict';
2
3(function ($) {
4    var woosb_timeout = null;
5
6    $(function () {
7        if ($('.woosb-wrap').length) {
8            $('.woosb-wrap').each(function () {
9                woosb_init($(this), 'ready');
10            });
11        }
12    });
13
14    $(document).on('woosq_loaded', function () {
15        // product bundles in the quick view popup
16        woosb_init($('#woosq-popup .woosb-wrap'), 'woosq');
17    });
18
19    $(document).on('click touch', '.woosb-quantity-input-plus, .woosb-quantity-input-minus', function () {
20        // get values
21        var $qty = $(this).closest('.woosb-quantity').find('.woosb-qty');
22
23        if (!$qty.length) {
24            $qty = $(this).closest('.woosb-quantity').find('.qty');
25        }
26
27        var val = parseFloat($qty.val()), max = parseFloat($qty.attr('max')), min = parseFloat($qty.attr('min')),
28            step = $qty.attr('step');
29
30        // format values
31        if (!val || val === '' || val === 'NaN') {
32            val = 0;
33        }
34
35        if (max === '' || max === 'NaN') {
36            max = '';
37        }
38
39        if (min === '' || min === 'NaN') {
40            min = 0;
41        }
42
43        if (step === 'any' || step === '' || step === undefined || step === 'NaN') {
44            step = 1;
45        } else {
46            step = parseFloat(step);
47        }
48
49        // change the value
50        if ($(this).is('.woosb-quantity-input-plus')) {
51            if (max && (val >= max)) {
52                $qty.val(max);
53            } else {
54                $qty.val((val + step).toFixed(woosb_decimal_places(step)));
55            }
56        } else {
57            if (min && (val <= min)) {
58                $qty.val(min);
59            } else if (val > 0) {
60                $qty.val((val - step).toFixed(woosb_decimal_places(step)));
61            }
62        }
63
64        // trigger change event
65        $qty.trigger('change');
66    });
67
68    $(document).on('click touch', '.single_add_to_cart_button', function (e) {
69        var $this = $(this);
70
71        if ($this.hasClass('woosb-disabled')) {
72            e.preventDefault();
73        }
74    });
75
76    if ($('.woosb-qty').length) {
77        $(document).on('change', '.woosb-qty', function () {
78            var $this = $(this);
79
80            woosb_check_qty($this);
81        });
82
83        $(document).on('keyup', '.woosb-qty', function () {
84            var $this = $(this);
85
86            if (woosb_timeout != null) clearTimeout(woosb_timeout);
87            woosb_timeout = setTimeout(woosb_check_qty, 1000, $this);
88        });
89    } else {
90        $(document).on('change', '.woosb-quantity .qty', function () {
91            var $this = $(this);
92
93            woosb_check_qty($this);
94        });
95
96        $(document).on('keyup', '.woosb-quantity .qty', function () {
97            var $this = $(this);
98
99            if (woosb_timeout != null) clearTimeout(woosb_timeout);
100            woosb_timeout = setTimeout(woosb_check_qty, 1000, $this);
101        });
102    }
103})(jQuery);
104
105function woosb_init($wrap, context = null) {
106    woosb_check_ready($wrap, context);
107    woosb_check_stock($wrap, context);
108    woosb_save_ids($wrap, context);
109
110    jQuery(document).trigger('woosb_init', [$wrap, context]);
111}
112
113function woosb_check_ready($wrap, context = null) {
114    var qty = 0;
115    var total = 0;
116    var total_sale = 0;
117    var is_selection = false;
118    var selection_name = '';
119    var is_unpurchasable = false;
120    var unpurchasable_name = '';
121    var is_empty = true;
122    var is_min = false;
123    var is_max = false;
124    var is_total_min = false;
125    var is_total_max = false;
126    var wid = $wrap.attr('data-id');
127    var $products = $wrap.find('.woosb-products');
128    var $alert = $wrap.find('.woosb-alert');
129    var $ids = jQuery('.woosb-ids-' + wid);
130    var $btn = $ids.closest('form.cart').find('.single_add_to_cart_button');
131    var price_suffix = $products.attr('data-price-suffix');
132    var $total = $wrap.find('.woosb-total');
133    var $count = $wrap.find('.woosb-count');
134    var $price = jQuery('.woosb-price-' + wid);
135    var $woobt = jQuery('.woobt-wrap-' + wid);
136    var $woobt_products = $woobt.find('.woobt-products');
137    var woobt_total = parseFloat($woobt_products.length ? $woobt.attr('data-total') : 0);
138    var discount = parseFloat($products.attr('data-discount'));
139    var discount_amount = parseFloat($products.attr('data-discount-amount'));
140    var fixed_price = $products.attr('data-fixed-price') === 'yes';
141    var has_optional = $products.attr('data-optional') === 'yes';
142    var has_variables = $products.attr('data-variables') === 'yes';
143    var exclude_unpurchasable = $products.attr('data-exclude-unpurchasable') === 'yes';
144    var saved = '';
145    var is_discount = discount > 0 && discount < 100;
146    var is_discount_amount = discount_amount > 0;
147    var qty_min = parseFloat($products.attr('data-min'));
148    var qty_max = parseFloat($products.attr('data-max'));
149    var total_min = parseFloat($products.attr('data-total-min'));
150    var total_max = parseFloat($products.attr('data-total-max'));
151
152    if (!$products.length || (!has_variables && !has_optional && !woosb_vars.recalc_price)) {
153        // don't need to do anything - already calculated in PHP
154        return;
155    }
156
157    // calculate price
158
159    if (!fixed_price) {
160        $products.find('.woosb-product').each(function () {
161            var $this = jQuery(this);
162
163            if ($this.hasClass('woosb-product-unpurchasable') && exclude_unpurchasable) {
164                // don't count this product
165                return;
166            }
167
168            if (parseFloat($this.attr('data-price')) > 0) {
169                var _qty = parseFloat($this.attr('data-qty'));
170                var _price = parseFloat($this.attr('data-price'));
171
172                total += _price * _qty;
173
174                if (!is_discount_amount && is_discount && woosb_vars.roun
174d_price) {
175                    _price = woosb_round(_price * (100 - discount) / 100);
176                }
177
178                total_sale += _price * _qty;
179            }
180        });
181
182        if (is_discount_amount && discount_amount < total) {
183            total_sale = total - discount_amount;
184            saved = woosb_format_price(discount_amount);
185        } else if (is_discount) {
186            if (!woosb_vars.round_price) {
187                total_sale = woosb_round(total * (100 - discount) / 100);
188            }
189
190            saved = woosb_round(discount, 2) + '%';
191        } else {
192            total_sale = total;
193        }
194
195        var total_html = woosb_price_html(total, total_sale);
196        var total_all_html = woosb_price_html(total + woobt_total, total_sale + woobt_total);
197
198        if (saved !== '') {
199            total_html += ' <small class="woocommerce-price-suffix">' + woosb_vars.saved_text.replace('[d]', saved) + '</small>';
200        }
201
202        // change the bundle total
203        $total.html('<span class="woosb-total-label">' + woosb_vars.price_text + '</span> <span class="woosb-total-value">' + total_html + price_suffix + '</span>').slideDown();
204        jQuery(document).trigger('woosb_change_total', [$total, total_html, price_suffix]);
205
206        if (woosb_vars.change_price !== 'no') {
207            // change the main price
208
209            if (woosb_vars.change_price === 'yes_custom' && woosb_vars.price_selector != null && woosb_vars.price_selector !== '') {
210                $price = jQuery(woosb_vars.price_selector);
211            }
212
213            if ($woobt_products.length) {
214                // woobt
215                $price.html(total_all_html + price_suffix);
216            } else {
217                if (typeof $price.attr('data-o_price') === 'undefined') {
218                    $price.attr('data-o_price', woosb_encode_entities($price.html()));
219                }
220
221                $price.html(total_html + price_suffix);
222            }
223        }
224
225        if ($woobt_products.length) {
226            // woobt
227            $woobt_products.attr('data-product-price-html', total_html);
228            $woobt_products.find('.woobt-product-this').attr('data-price', total_sale).attr('data-regular-price', total);
229
230            woobt_init($woobt);
231        }
232
233        jQuery(document).trigger('woosb_calc_price', [total_sale, total, total_html, price_suffix, $wrap]);
234    }
235
236    // check ready
237
238    $products.find('.woosb-product').each(function () {
239        var $this = jQuery(this);
240
241        if (parseFloat($this.attr('data-qty')) > 0) {
242            is_empty = false;
243            qty += parseFloat($this.attr('data-qty'));
244
245            if (parseInt($this.attr('data-id')) === 0) {
246                is_selection = true;
247
248                if (selection_name === '') {
249                    selection_name = $this.attr('data-name');
250                }
251            }
252
253            if ($this.hasClass('woosb-product-optional') && $this.hasClass('woosb-product-unpurchasable')) {
254                is_unpurchasable = true;
255
256                if (unpurchasable_name === '') {
257                    unpurchasable_name = $this.attr('data-name');
258                }
259            }
260        }
261    });
262
263    if (has_optional) {
264        // check min
265        if (qty_min > 0 && qty < qty_min) {
266            is_min = true;
267        }
268
269        // check max
270        if (qty_max > 0 && qty > qty_max) {
271            is_max = true;
272        }
273
274        $count.html('<span class="woosb-count-label">' + woosb_vars.selected_text + '</span> <span class="woosb-count-value">' + qty + '</span>').slideDown();
275        jQuery(document).trigger('woosb_change_count', [$count, qty, qty_min, qty_max]);
276    }
277
278    if (!fixed_price) {
279        // check total min
280        if (total_min > 0 && total_sale < total_min) {
281            is_total_min = true;
282        }
283
284        // check total max
285        if (total_max > 0 && total_sale > total_max) {
286            is_total_max = true;
287        }
288    }
289
290    if (is_selection || is_unpurchasable || is_empty || is_min || is_max || is_total_min || is_total_max) {
291        $btn.addClass('woosb-disabled');
292
293        if (is_selection) {
294            $alert.html(woosb_vars.alert_selection.replace('[name]', '<strong>' + selection_name + '</strong>')).slideDown();
295        } else if (is_unpurchasable) {
296            $alert.html(woosb_vars.alert_unpurchasable.replace('[name]', '<strong>' + unpurchasable_name + '</strong>')).slideDown();
297        } else if (is_empty) {
298            $alert.html(woosb_vars.alert_empty).slideDown();
299        } else if (is_min) {
300            $alert.html(woosb_vars.alert_min.replace('[min]', qty_min).replace('[selected]', qty)).slideDown();
301        } else if (is_max) {
302            $alert.html(woosb_vars.alert_max.replace('[max]', qty_max).replace('[selected]', qty)).slideDown();
303        } else if (is_total_min) {
304            $alert.html(woosb_vars.alert_total_min.replace('[min]', woosb_format_price(total_min)).replace('[total]', wo
304osb_format_price(total_sale))).slideDown();
305        } else if (is_total_max) {
306            $alert.html(woosb_vars.alert_total_max.replace('[max]', woosb_format_price(total_max)).replace('[total]', woosb_format_price(total_sale))).slideDown();
307        }
308
309        jQuery(document).trigger('woosb_check_ready', [false, is_selection, is_unpurchasable, is_empty, is_min, is_max, is_total_min, is_total_max, $wrap]);
310    } else {
311        $alert.html('').slideUp();
312        $btn.removeClass('woosb-disabled');
313
314        // ready
315        jQuery(document).trigger('woosb_check_ready', [true, is_selection, is_unpurchasable, is_empty, is_min, is_max, is_total_min, is_total_max, $wrap]);
316    }
317}
318
319function woosb_check_stock($wrap, context = null) {
320    var wid = $wrap.attr('data-id');
321    var $ids = jQuery('.woosb-ids-' + wid);
322    var $products = $wrap.find('.woosb-products');
323    var $qty = $ids.closest('form.cart').find('[name="quantity"]');
324    var stock_arr = Array();
325    var stock_min = 0;
326
327    $products.find('.woosb-product').each(function () {
328        var $this = jQuery(this);
329        var id = parseInt($this.attr('data-id'));
330        var qty = parseFloat($this.attr('data-qty'));
331        var stock = parseFloat($this.attr('data-stock'));
332
333        if (id > 0 && qty > 0 && (stock >= 0)) {
334            stock_arr.push(Math.floor(stock / qty));
335        }
336    });
337
338    stock_min = Math.min.apply(null, stock_arr);
339    stock_min = isNaN(stock_min) ? 0 : stock_min;
340
341    $qty.attr('max', stock_min);
342
343    if ($qty.val() > stock_min) {
344        $qty.val(stock_min).trigger('change');
345    }
346
347    jQuery(document).trigger('woosb_check_stock', [$wrap, context]);
348}
349
350function woosb_save_ids($wrap, context = null) {
351    var ids = Array();
352    var wid = $wrap.attr('data-id');
353    var $ids = jQuery('.woosb-ids-' + wid);
354    var $products = $wrap.find('.woosb-products');
355
356    $products.find('.woosb-product').each(function () {
357        var $this = jQuery(this);
358        var id = parseInt($this.attr('data-id'));
359        var key = $this.attr('data-key');
360        var qty = parseFloat($this.attr('data-qty'));
361        var attrs = $this.attr('data-attrs');
362
363        if (id > 0 && qty > 0) {
364            if (attrs !== undefined) {
365                attrs = encodeURIComponent(attrs);
366            } else {
367                attrs = '';
368            }
369
370            ids.push(id + '/' + key + '/' + qty + '/' + attrs);
371        }
372    });
373
374    $ids.val(ids.join(','));
375
376    jQuery(document).trigger('woosb_save_ids', [ids, $wrap]);
377}
378
379function woosb_check_qty($qty) {
380    var $wrap = $qty.closest('.woosb-wrap');
381    var qty = parseFloat($qty.val());
382    var min = parseFloat($qty.attr('min'));
383    var max = parseFloat($qty.attr('max'));
384
385    if (qty === '' || isNaN(qty)) {
386        qty = 0;
387    }
388
389    if (!isNaN(min) && qty < min) {
390        qty = min;
391    }
392
393    if (!isNaN(max) && qty > max) {
394        qty = max;
395    }
396
397    $qty.val(qty);
398    $qty.closest('.woosb-product').attr('data-qty', qty);
399
400    // change subtotal
401    if (woosb_vars.bundled_price === 'subtotal' || woosb_vars.bundled_price === 'subtotal_under_name') {
402        var $products = $wrap.find('.woosb-products');
403        var $product = $qty.closest('.woosb-product');
404        var price_suffix = $product.attr('data-price-suffix');
405        var ori_price = parseFloat($product.attr('data-price'));
406        var qty = parseFloat($product.attr('data-qty'));
407        var discount = parseFloat($products.attr('data-discount'));
408
409        $product.find('.woosb-price-ori').hide();
410
411        if (discount > 0 && $products.attr('data-fixed-price') === 'no') {
412            var new_price = woosb_round(ori_price * (100 - discount) / 100);
413
414            $product.find('.woosb-price-new').html(woosb_price_html(ori_price * qty, new_price * qty) + price_suffix).show();
415        } else {
416            $product.find('.woosb-price-new').html(woosb_price_html(ori_price * qty) + price_suffix).show();
417        }
418    }
419
420    jQuery(document).trigger('woosb_check_qty', [qty, $qty]);
421
422    woosb_init($wrap, 'woosb_check_qty');
423}
424
425function woosb_change_price($product, price, regular_price, price_html) {
426    var $products = $product.closest('.woosb-products');
427    var price_suffix = $product.attr('data-price-suffix');
428    var qty = parseFloat($product.attr('data-qty'));
429    var discount = parseFloat($products.attr('data-discount'));
430    var new_price_html = '';
431
432    // hide ori price
433    $product.find('.woosb-price-ori').hide();
434
435    // calculate new price
436    if (woosb_vars.bundled_price === 'subtotal' || woosb_vars.bundled_price === 'subtotal_under_name') {
437        var ori_price = parseFloat(price);
438
439        if (woosb_vars.bundled_price_from === 'regular_price' && regular_price !== undefined) {
440            ori_price = parseFloat(regular_price);
441        }
442
443        var new_price = ori_price;
444
445        if (discount > 0) {
446            new_price = woosb_round(ori_price * (100 - discount) / 100);
447        }
448
449        new_price_html = woosb_price_html(ori_price * qty, new_price * qty) + price_suffix;
450    } else {
451        if (discount > 0) {
452            var ori_price = parseFloat(price);
453
454            if (woosb_vars.bundled_price_from === 'regular_price' && regular_price !== undefined) {
455                ori_price = parseFloat(regular_price);
456            }
457
458            var new_price = woosb_round(ori_price * (100 - discount) / 100);
459
460            new_price_html = woosb_price_html(ori_price, new_price) + price_suffix;
461        } else {
462            if (woosb_vars.bundled_price_from === 'regular_price' && regular_price !== undefined) {
463                new_price_html = woosb_price_html(regular_price) + price_suffix;
464            } else if (price_html !== '') {
465                new_price_html = price_html;
466            }
467        }
468    }
469
470    $product.find('.woosb-price-new').html(new_price_html).show();
471    jQuery(document).trigger('woosb_change_price', [$product, new_price_html]);
472}
473
474function woosb_round(value, decimals = -1) {
475    if (decimals < 0) {
476        decimals = woosb_vars.price_decimals;
477    }
478
479    return Number(Math.round(value + 'e' + decimals) + 'e-' + decimals);
480}
481
482function woosb_format_money(number, places, symbol, thousand, decimal) {
483    number = number || 0;
484    places = !isNaN(places = Math.abs(places)) ? places : 2;
485    symbol = symbol !== undefined ? symbol : '$';
486    thousand = thousand !== undefined ? thousand : ',';
487    decimal = decimal !== undefined ? decimal : '.';
488
489    var negative = number < 0 ? '-' : '', i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '', j = 0;
490
491    if (i.length > 3) {
492        j = i.length % 3;
493    }
494
495    if (woosb_vars.trim_zeros === '1') {
496        return symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places && (parseFloat(number) > parseFloat(i)) ? decimal + Math.abs(number - i).toFixed(places).slice(2).replace(/(\d*?[1-9])0+$/g, '$1') : '');
497    } else {
498        return symbol + negative + (j ? i.substr(0, j) + thousand : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) + (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : '');
499    }
500}
501
502function woosb_format_price(price) {
503    var price_html = '<span class="woocommerce-Price-amount amount">';
504    var price_formatted = woosb_format_money(price, woosb_vars.wc_price_decimals, '', woosb_vars.wc_price_thousand_separator, woosb_vars.wc_price_decimal_separator);
505
506    switch (woosb_vars.wc_price_format) {
507        case '%1$s%2$s':
508            //left
509            price_html += '<span class="woocommerce-Price-currencySymbol">' + woosb_vars.wc_currency_symbol + '</span>' + price_formatted;
510            break;
511        case '%1$s %2$s':
512            //left with space
513            price_html += '<span class="woocommerce-Price-currencySymbol">' + woosb_vars.wc_currency_symbol + '</span> ' + price_formatted;
514            break;
515        case '%2$s%1$s':
516            //right
517            price_html += price_formatted + '<span class="woocommerce-Price-currencySymbol">' + woosb_vars.wc_currency_symbol + '</span>';
518            break;
519        case '%2$s %1$s':
520            //right with space
521            price_html += price_formatted + ' <span class="woocommerce-Price-currencySymbol">' + woosb_vars.wc_currency_symbol + '</span>';
522            break;
523        default:
524            //default
525            price_html += '<span class="woocommerce-Price-currencySymbol">' + woosb_vars.wc_currency_symbol + '</span> ' + price_formatted;
526    }
527
528    price_html += '</span>';
529
530    return price_html;
531}
532
533function woosb_price_html(regular_price, sale_price) {
534    var price_html = '';
535
536    if (woosb_round(sale_price) < woosb_round(regular_price)) {
537        price_html = '<del>' + woosb_format_price(regular_price) + '</del> <ins>' + woosb_format_price(sale_price) + '</ins>';
538    } else {
539        price_html = woosb_format_price(regular_price);
540    }
541
542    return price_html;
543}
544
545function woosb_decimal_places(num) {
546    var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
547
548    if (!match) {
549        return 0;
550    }
551
552    return Math.max(0, // Number of digits right of decimal point.
553        (match[1] ? match[1].length : 0) - // Adjust for scientific notation.
554        (match[2] ? +match[2] : 0));
555}
556
557function woosb_encode_entities(str) {
558    return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
559}
560
561function woosb_decode_entities(str) {
562    var textArea = document.createElement('textarea');
563    textArea.innerHTML = str;
564    return textArea.value;
565}

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.