PageSourceSearch

https://ballvin.hu/wp-content/plugins/wpc-composite-products/assets/js/frontend.js?ver=7.6.1

js ballvin.hu collected 2026-10-08 20:33:11 UTC 34,631 bytes, 933 lines download raw bytes

1'use strict';
2
3(function ($) {
4    var $gallery = null;
5    var gallery_loading = false;
6
7    $(function () {
8        if ($('.wooco-wrap').length) {
9            wooco_init_selector();
10
11            $('.wooco-wrap').each(function () {
12                wooco_init($(this), 'loaded');
13            });
14        }
15    });
16
17    $(document).on('woosq_loaded', function () {
18        // composite products in quick view popup
19        if ($('#woosq-popup .wooco-wrap').length) {
20            wooco_init_selector();
21            wooco_init($('#woosq-popup .wooco-wrap'), 'woosq_loaded');
22        }
23    });
24
25    $(document).on('wooco_save_ids', function (e, ids, $wrap, context, $selected) {
26        const block_ui_params = {
27            message: null, overlayCSS: {
28                background: '#fff', opacity: 0.6,
29            },
30        };
31
32        if ((wooco_vars.change_image === 'yes') &&
33            (context === 'loaded' || context === 'on_select' || context ===
34                'on_click')) {
35            var product_id = $wrap.data('id');
36            var $all_gallery = $(wooco_vars.gallery_selector);
37            var $main_gallery = $(wooco_vars.main_gallery_selector);
38
39            if ($all_gallery.length && $main_gallery.length) {
40                if (!ids.length) {
41                    $(document).find('.woocommerce-product-gallery--wooco').unblock().hide();
42                    $main_gallery.unblock().show();
43                } else {
44                    var key = btoa(ids.toString()).replace(/[^a-zA-Z0-9]/g, '');
45                    var $key_gallery = $('.woocommerce-product-gallery--wooco-' + key);
46
47                    if ($key_gallery.length) {
48                        $all_gallery.unblock().hide();
49                        $key_gallery.unblock().show();
50                    } else {
51                        $all_gallery.block(block_ui_params);
52
53                        if (gallery_loading && ($gallery != null)) {
54                            $gallery.abort();
55                        }
56
57                        var data = {
58                            action: 'wooco_load_gallery',
59                            nonce: wooco_vars.nonce,
60                            product_id: product_id,
61                            key: key,
62                            ids: ids,
63                        };
64
65                        gallery_loading = true;
66
67                        $gallery = $.post(wooco_vars.wc_ajax_url.toString().replace('%%endpoint%%', 'wooco_load_gallery'), data,
68                            function (response) {
69                                if (response.gallery) {
70                                    var $wooco_gallery = $(response.gallery);
71
72                                    $all_gallery.unblock().hide();
73                                    $wooco_gallery.insertAfter($main_gallery);
74                                    $(document).trigger('wooco_gallery_loaded', product_id, key, ids);
75
76                                    $wooco_gallery.imagesLoaded(function () {
77                                        $wooco_gallery.wc_product_gallery();
78
79                                        // scroll to selected image
80                                        if ($selected) {
81                                            var selected_image = $selected.data('image_gallery');
82                                            var $gallery_nav = $wooco_gallery.find(
83                                                '.flex-control-nav');
84
85                                            if ($gallery_nav.length &&
86                                                (selected_image !== undefined) &&
87                                                (selected_image !== '')) {
88                                                var $scroll_image = $gallery_nav.find(
89                                                    'li img[src="' + selected_image + '"]');
90
91                                                if ($scroll_image.length) {
92                                                    window.setTimeout(function () {
93                                                        $scroll_image.trigger('click');
94                                                        $(window).trigger('resize');
95                                                    }, 100);
96                                                }
97                                            }
98                                        }
99
100                                        $(document).trigger('wooco_gallery_images_loaded', product_id,
101                                            key, ids);
102                                    });
103                                } else {
104                                    $all_gallery.unblock();
105                                }
106
107                                gallery_loading = false;
108                            });
109                    }
110                }
111            }
112        }
113    });
114
115    $(document).on('click touch', '.single_add_to_cart_button', function (e) {
116        if ($(this).hasClass('wooco-disabled')) {
117            if (wooco_vars.show_alert === 'change') {
118                wooco_show_alert($(this).closest('.wooco-wrap'));
119            }
120
121            e.preventDefault();
122        }
123    });
124
125    $(document).on('click touch', '.wooco-plus, .wooco-minus', function () {
126        // get values
127        var $qty = $(this).closest('.wooco-qty-wrap').find('.wooco_qty').length ? $(
128                this).closest('.wooco-qty-wrap').find('.wooco_qty') : $(this).closest('.wooco-qty-wrap').find('.qty'),
129            val = parseFloat($qty.val()),
130            max = parseFloat($qty.attr('max')), min = parseFloat($qty.attr('min')),
131            step = $qty.attr('step');
132
133        // format values
134        if (!val || val === '' || val === 'NaN') {
135            val = 0;
136        }
137
138        if (max === '' || max === 'NaN') {
139            max = '';
140        }
141
142        if (min === '' || min === 'NaN') {
143            min = 0;
144        }
145
146        if (step === 'any' || step === '' || step === undefined ||
147            parseFloat(step) === 'NaN') {
148            step = 1;
149        } else {
150            step = parseFloat(step);
151        }
152
153        // change the value
154        if ($(this).is('.wooco-plus')) {
155            if (max && (val >= max)) {
156                $qty.val(max);
157            } else {
158                $qty.val((val + step).toFixed(wooco_decimal_places(step)));
159            }
160        } else {
161            if (min && (val <= min)) {
162                $qty.val(min);
163            } else if (val > 0) {
164                $qty.val((val - step).toFixed(wooco_decimal_places(step)));
165            }
166        }
167
168        // trigger change event
169        $qty.trigger('change');
170    });
171
172    $(document).on('keyup change', '.wooco_qty', function () {
173        var $this = $(this);
174        var $wrap = $this.closest('.wooco-wrap');
175        var val = parseFloat($this.val());
176        var min = parseFloat($this.attr('min'));
177        var max = parseFloat($this.attr('max'));
178
179        if ((val < min) || isNaN(val)) {
180            val = min;
181            $this.val(val);
182        }
183
184        if (val > max) {
185            val = max;
186            $this.val(val);
187        }
188
189        $this.closest('.wooco_component_product_selection_item').attr('data-qty', val);
190        $this.closest('.wooco_component_product').attr('data-qty', val);
191
192        wooco_init($wrap, 'update_qty');
193    });
194
195    $(document).on('change', '.wooco-checkbox', function () {
196        var $wrap = $(this).closest('.wooco-wrap');
197
198        wooco_init($wrap, 'checked');
199    });
200})(jQuery);
201
202function wooco_init($wrap, context = null, $selected = null) {
203    if (context === 'loaded' || context === 'woosq_loaded') {
204        // update qty
205        if ($wrap.find('.wooco_qty').length) {
206            $wrap.find('.wooco_qty').trigger('change');
207        } else {
208            $wrap.find('.qty').trigger('change');
209        }
210    }
211
212    wooco_check_ready($wrap, context, $selected);
213    wooco_save_ids($wrap, context, $selected);
214
215    if (context === null || context === 'on_select' || context ===
216        wooco_vars.show_alert) {
217        wooco_show_alert($wrap, context, $selected);
218    }
219
220    jQuery(document).trigger('wooco_init', [$wrap, context, $selected]);
221}
222
223function wooco_check_ready($wrap, context = null, $selected = null) {
224    var wid = $wrap.attr('data-id');
225    var $components = $wrap.find('.wooco-components');
226    var $ids = jQuery('.wooco-ids-' + wid);
227    var $btn = $ids.closest('form.cart').find('.single_add_to_cart_button');
228    var $alert = $wrap.find('.wooco-alert');
229    var is_selection = false;
230    var c_name = '';
231    var is_min = false;
232    var is_max = false;
233    var is_m_min = false;
234    var is_m_max = false;
235    var is_same = false;
236    var is_total_min = false;
237    var is_total_max = false;
238    var is_count = false;
239    var selected_products = [];
240    var allow_same = $components.attr('data-same');
241    var qty = 0;
242    var m_min = 0;
243    var m_max = 10000;
244    var qty_min = parseFloat($components.attr('data-min'));
245    var qty_max = parseFloat($components.attr('data-max'));
246    var total_min = parseFloat($components.attr('data-total-min'));
247    var total_max = parseFloat($components.attr('data-total-max'));
248    var $total = $wrap.find('.wooco-total');
249    var $count = $wrap.find('.wooco-count');
250    var $price = jQuery('.wooco-price-' + wid);
251    var $woobt = jQuery('.woobt-wrap-' + wid);
252    var pricing = $components.attr('data-pricing');
253    var price = wooco_format_number($components.attr('data-price'));
254    var regular_price = wooco_format_number(
255        $components.attr('data-regular-price'));
256    var percent = wooco_format_number($components.attr('data-percent'));
257    var total = 0;
258    var total_regular = 0;
259
260    if (!$components.length ||
261        !$components.find('.wooco_component_product').length) {
262        return;
263    }
264
265    // calculate price
266
267    if (pricing === 'only') {
268        total = price;
269        total_regular = regular_price;
270    } else {
271        // calc price
272        $components.find('.wooco_component_product').each(function () {
273            var $this = jQuery(this);
274            var $checkbox = $this.find('.wooco-checkbox');
275            var _price = wooco_format_number($this.attr('data-price'));
276            var _regular_price = wooco_format_number(
277                $this.attr('data-regular-price'));
278            var _qty = wooco_format_number($this.attr('data-qty'));
279            var _multiple = $this.attr('data-multiple');
280
281            if ($checkbox.length && !$checkbox.prop('checked')) {
282                return;
283            }
284
285            if (_multiple === 'yes') {
286                // multiple selection
287
288                $this.find('.wooco_item_selected').each(function () {
289                    var $_this = jQuery(this);
290                    var __price = wooco_format_number($_this.attr('data-price'));
291                    var __regular_price = wooco_format_number(
292                        $_this.attr('data-regular-price'));
293                    var __qty = wooco_format_number($_this.attr('data-qty'));
294
295                    if ((__price > 0) && (__qty > 0)) {
296                        total += __price * __qty;
297                    }
298
299                    if ((__regular_price > 0) && (__qty > 0)) {
300                        total_regular += __regular_price * __qty;
301                    }
302                });
303            } else {
304                // single selection
305
306                if ((_price > 0) && (_qty > 0)) {
307                    total += _price * _qty;
308                }
309
310                if ((_regular_price > 0) && (_qty > 0)) {
311                    total_regular += _regular_price * _qty;
312                }
313            }
314        });
315
316        // discount
317        if ((percent > 0) && (percent < 100)) {
318            total = total * (100 - percent) / 100;
319        }
320
321        if (pricing === 'include') {
322            total += price;
323            total_regular += regular_price;
324        }
325    }
326
327    var total_html = wooco_price_html(total_regular, total);
328
329    if ((pricing !== 'only') && (percent > 0) && (percent < 100)) {
330        total_html += ' <small class="woocommerce-price-suffix">' +
331            wooco_vars.saved_text.replace('[d]', percent + '%') + '</small>';
332    }
333
334    $total.html(wooco_vars.total_text + ' ' + total_html).slideDown();
335
336    if ((wooco_vars.change_price !== 'no') && (pricing !== 'only')) {
337        if ((wooco_vars.change_price === 'yes_custom') &&
338            (wooco_vars.price_selector !== null) &&
339            (wooco_vars.price_selector !== '')) {
340            $price = jQuery(wooco_vars.price_selector);
341        }
342
343        $price.html(total_html);
344    }
345
346    if ($woobt.length) {
347        $woobt.find('.woobt-products').attr('data-product-price-html', total_html);
348        $woobt.find('.woobt-product-this').attr('data-price', total).attr('data-regular-price', total_regular);
349
350        woobt_init($woobt);
351    }
352
353    jQuery(document).trigger('wooco_calc_price',
354        [total, total_regular, total_html, $wrap, context, $selected]);
355
356    // check ready
357
358    $components.find('.wooco_component_product').each(function () {
359        var $this = jQuery(this);
360        var $checkbox = $this.find('.wooco-checkbox');
361        var _selected = false;
362        var _name = $this.attr('data-name');
363        var _id = parseInt($this.attr('data-id'));
364        var _qty = parseFloat($this.attr('data-qty'));
365        var _required = $this.attr('data-required');
366        var _multiple = $this.attr('data-multiple');
367        var _custom_qty = $this.attr('data-custom-qty');
368
369        if ($checkbox.length && !$checkbox.prop('checked')) {
370            return;
371        }
372
373        if (_custom_qty === 'yes' || _multiple === 'yes') {
374            is_count = true;
375        }
376
377        if (_multiple === 'yes') {
378            // multiple selection
379            var _m_qty = 0;
380            var _m_min = parseFloat($this.attr('data-m-min'));
381            var _m_max = parseFloat($this.attr('data-m-max'));
382
383            $this.find('.wooco_item_selected').each(function () {
384                var $_this = jQuery(this);
385                var __id = parseInt($_this.attr('data-id'));
386                var __qty = parseFloat($_this.attr('data-qty'));
387
388                if (__id > 0) {
389                    qty += __qty;
390                    _m_qty += __qty;
391                    _selected = true;
392                }
393
394                if (allow_same === 'no') {
395                    if (selected_products.includes(__id)) {
396                        is_same = true;
397                    } else {
398                        if (__id > 0) {
399                            selected_products.push(__id);
400                        }
401                    }
402                }
403            });
404
405            if (_m_qty < _m_min) {
406                is_m_min = true;
407                m_min = _m_min;
408
409                if (c_name === '') {
410                    c_name = _name;
411                }
412            }
413
414            if (_m_qty > _m_max) {
415                is_m_max = true;
416                m_max = _m_max;
417
418                if (c_name === '') {
419                    c_name = _name;
420                }
421            }
422        } else {
423            // single selection
424
425            if (_id > 0) {
426                qty += _qty;
427                _selected = true;
428            }
429
430            if (allow_same === 'no') {
431                if (selected_products.includes(_id)) {
432                    is_same = true;
433                } else {
434                    if (_id > 0) {
435                        selected_products.push(_id);
436                    }
437                }
438            }
439        }
440
441        if (!_selected && (_required === 'yes')) {
442            is_selection = true;
443
444            if (c_name === '') {
445                c_name = _name;
446            }
447        }
448    });
449
450    if (is_count) {
451        $count.html('<span class="wooco-count-label">' + wooco_vars.selected_text +
452            '</span> <span class="wooco-count-value">' + qty + '</span>').slideDown();
453        jQuery(document).trigger('wooco_change_count', [$count, qty, qty_min, qty_max]);
454    }
455
456    if (qty < qty_min) {
457        is_min = true;
458    }
459
460    if (qty > qty_max) {
461        is_max = true;
462    }
463
464    if ((pricing !== 'only')) {
465        // check total min
466        if (total_min > 0 && total < total_min) {
467            is_total_min = true;
468        }
469
470        // check total max
471        if (total_max > 0 && total > total_max) {
472            is_total_max = true;
473        }
474    }
475
476    if (is_selection || is_min || is_max || is_m_min || is_m_max || is_same ||
477        is_total_min || is_total_max) {
478        $btn.addClass('wooco-disabled');
479        $alert.addClass('alert-active');
480
481        if (is_selection) {
482            $alert.addClass('alert-selection').html(wooco_vars.alert_selection.replace('[name]',
483                '<strong>' + c_name + '</strong>'));
484        } else if (is_m_min) {
485            $alert.addClass('alert-min').html(wooco_vars.alert_m_min.replace('[min]', m_min).replace('[name]', '<strong>' + c_name + '</strong>'));
486        } else if (is_m_max) {
487            $alert.addClass('alert-max').html(wooco_vars.alert_m_max.replace('[max]', m_max).replace('[name]', '<strong>' + c_name + '</strong>'));
488        } else if (is_min) {
489            $alert.addClass('alert-min').html(wooco_vars.alert_min.replace('[min]', qty_min));
490        } else if (is_max) {
491            $alert.addClass('alert-max').html(wooco_vars.alert_max.replace('[max]', qty_max));
492        } else if (is_same) {
493            $alert.addClass('alert-same').html(wooco_vars.alert_same);
494        } else if (is_total_min) {
495            $alert.addClass('alert-total-min').html(wooco_vars.alert_total_min.replace('[min]',
496                wooco_format_price(total_min)).replace('[total]', wo
496oco_format_price(total)));
497        } else if (is_total_max) {
498            $alert.addClass('alert-total-max').html(wooco_vars.alert_total_max.replace('[max]',
499                wooco_format_price(total_max)).replace('[total]', wooco_format_price(total)));
500        }
501
502        $alert.slideDown();
503
504        jQuery(document).trigger('wooco_check_ready', [
505            false,
506            is_selection,
507            is_same,
508            is_min,
509            is_max,
510            $wrap,
511            context,
512            $selected]);
513    } else {
514        $alert.removeClass(
515            'alert-active alert-selection alert-min alert-max alert-total-min alert-total-max').slideUp(300, function () {
516            $alert.html('');
517        });
518        $btn.removeClass('wooco-disabled');
519
520        // ready
521        jQuery(document).trigger('wooco_check_ready', [
522            true,
523            is_selection,
524            is_same,
525            is_min,
526            is_max,
527            $wrap,
528            context,
529            $selected]);
530    }
531}
532
533function wooco_save_ids($wrap, context = null, $selected = null) {
534    var wid = $wrap.attr('data-id');
535    var $components = $wrap.find('.wooco-components');
536    var $ids = jQuery('.wooco-ids-' + wid);
537    var ids = Array();
538
539    $components.find('.wooco_component_product').each(function () {
540        var $this = jQuery(this);
541        var $checkbox = $this.find('.wooco-checkbox');
542        var key = $this.data('key');
543
544        if ($checkbox.length && !$checkbox.prop('checked')) {
545            return;
546        }
547
548        if ($this.attr('data-multiple') === 'yes') {
549            // multiple selection
550            $this.find('.wooco_item_selected').each(function () {
551                var $_this = jQuery(this);
552
553                if (($_this.attr('data-id') > 0) && ($_this.attr('data-qty') > 0)) {
554                    ids.push(
555                        $_this.attr('data-id') + '/' + $_this.attr('data-qty') + '/' +
556                        key);
557                }
558            });
559        } else {
560            // single selection
561
562            if (($this.attr('data-id') > 0) && ($this.attr('data-qty') > 0)) {
563                ids.push(
564                    $this.attr('data-id') + '/' + $this.attr('data-qty') + '/' + key);
565            }
566        }
567    });
568
569    $ids.val(ids.join(','));
570    jQuery(document).trigger('wooco_save_ids', [ids, $wrap, context, $selected]);
571}
572
573function wooco_show_alert($wrap, context = null, $selected = null) {
574    var $alert = $wrap.find('.wooco-alert');
575
576    if ($alert.hasClass('alert-active')) {
577        $alert.slideDown();
578    } else {
579        $alert.slideUp();
580    }
581
582    jQuery(document).trigger('wooco_show_alert', [$wrap, context, $selected]);
583}
584
585function wooco_init_selector() {
586    if (wooco_vars.selector === 'ddslick') {
587        jQuery('.wooco_component_product_select').each(function () {
588            var $this = jQuery(this);
589            var $selection = $this.closest('.wooco_component_product_selection');
590            var $component = $this.closest('.wooco_component_product');
591            var $wrap = $this.closest('.wooco-wrap');
592
593            $selection.data('select', 0);
594
595            $this.ddslick({
596                width: '100%', onSelected: function (data) {
597                    var _select = $selection.data('select');
598                    var $selected = jQuery(data.original[0].children[data.selectedIndex]);
599
600                    if (data.selectedData.value == '-1') {
601                        if (!$selection.find('.dd-selected .dd-desc').length) {
602                            $selection.find('.dd-selected').addClass('dd-option-without-desc');
603                            $selection.find('.dd-option-selected').addClass('dd-option-without-desc');
604                        } else {
605                            $selection.find('.dd-selected').removeClass('dd-option-without-desc');
606                            $selection.find('.dd-option-selected').removeClass('dd-option-without-desc');
607                        }
608                    }
609
610                    // check empty desc
611                    if (!$selection.hasClass('wooco-ddslick-checked-desc')) {
612                        $selection.find('.dd-selected, .dd-option').each(function () {
613                            if (!jQuery(this).find('.dd-desc').length) {
614                                jQuery(this).addClass('dd-option-without-desc');
615                            } else {
616                                jQuery(this).removeClass('dd-option-without-desc');
617                            }
618                        });
619
620                        $selection.addClass('wooco-ddslick-checked-desc');
621                    }
622
623                    // check disabled
624                    if (!$selection.hasClass('wooco-ddslick-checked-disabled')) {
625                        $selection.find('.dd-selected, .dd-option').each(function () {
626                            if (parseInt(jQuery(this).find('.dd-option-value').val()) === 0) {
627                                jQuery(this).addClass('dd-option-disabled');
628                            } else {
629                                jQuery(this).removeClass('dd-option-disabled');
630                            }
631                        });
632
633                        $selection.addClass('wooco-ddslick-checked-disabled');
634                    }
635
636                    wooco_selected($selected, $selection, $component);
637
638                    if (_select > 0) {
639                        wooco_init($wrap, 'on_select', $selected);
640                    } else {
641                        // selected on init_selector
642                        wooco_init($wrap, 'selected', $selected);
643                    }
644
645                    $selection.data('select', _select + 1);
646                },
647            });
648        });
649    } else if (wooco_vars.selector === 'select2') {
650        jQuery('.wooco_component_product_select').each(function () {
651            var $this = jQuery(this);
652            var $selection = $this.closest('.wooco_component_product_selection');
653            var $component = $this.closest('.wooco_component_product');
654            var $wrap = $this.closest('.wooco-wrap');
655
656            if ($this.val() !== '') {
657                var $default = jQuery('option:selected', this);
658
659                wooco_selected($default, $selection, $component);
660                wooco_init($wrap, 'selected', $default);
661            }
662
663            $this.select2({
664                templateResult: wooco_select2_state,
665                width: '100%',
666                containerCssClass: 'wpc-select2-container',
667                dropdownCssClass: 'wpc-select2-dropdown',
668            });
669        });
670
671        jQuery('.wooco_component_product_select').on('select2:select', function (e) {
672            var $this = jQuery(this);
673            var $selection = $this.closest('.wooco_component_product_selection');
674            var $component = $this.closest('.wooco_component_product');
675            var $wrap = $this.closest('.wooco-wrap');
676            var $selected = jQuery(e.params.data.element);
677
678            wooco_selected($selected, $selection, $component);
679            wooco_init($wrap, 'on_select', $selected);
680        });
681    } else {
682        jQuery('.wooco_component_product_select').each(function () {
683            // check on start
684            var $this = jQuery(this);
685            var $selection = $this.closest('.wooco_component_product_selection');
686            var $component = $this.closest('.wooco_component_product');
687            var $wrap = $this.closest('.wooco-wrap');
688            var $selected = jQuery('option:selected', this);
689
690            wooco_selected($selected, $selection, $component);
691            wooco_init($wrap, 'selected', $selected);
692        });
693
694        jQuery('body').on('change', '.wooco_component_product_select', function () {
695            // check on select
696            var $this = jQuery(this);
697            var $selection = $this.closest('.wooco_component_product_selection');
698            var $component = $this.closest('.wooco_component_product');
699            var $wrap = $this.closest('.wooco-wrap');
700            var $selected = jQuery('option:selected', this);
701
702            wooco_selected($selected, $selection, $component);
703            wooco_init($wrap, 'on_select', $selected);
704        });
705    }
706
707    jQuery('.wooco_component_product_selection_item.wooco_item_selected').each(function () {
708        var $this = jQuery(this);
709        var $selection = $this.closest('.wooco_component_product_selection');
710        var $component = $this.closest('.wooco_component_product');
711        var $wrap = $this.closest('.wooco-wrap');
712
713        wooco_selected($this, $selection, $component);
714        wooco_init($wrap, 'selected', $this);
715    });
716
717    jQuery('body').on('click touch', '.wooco_component_product_selection_item', function (e) {
718        if (jQuery(e.target).closest('.wooco_component_product_selection_item_qty').length ===
719            0 && !jQuery(e.target).is('a, a *')) {
720            // check on select
721            var $this = jQuery(this);
722            var $selection = $this.closest('.wooco_component_product_selection');
723            var $component = $this.closest('.wooco_component_product');
724            var $wrap = $this.closest('.wooco-wrap');
725
726            if ($component.attr('data-multiple') === 'yes') {
727                // multiple selection
728                $this.toggleClass('wooco_item_selected');
729            } else {
730                // single selection
731                if ($this.hasClass('wooco_item_selected')) {
732                    // remove
733                    $component.attr('data-id', '-1');
734                    $component.attr('data-price', '');
735                    $component.attr('data-price-html', '');
736                    $component.attr('data-regular-price', '');
737                    $this.removeClass('wooco_item_selected');
738                } else {
739                    $selection.find('.wooco_component_product_selection_item').removeClass('wooco_item_selected');
740                    $this.addClass('wooco_item_selected');
741                    wooco_selected($this, $selection, $component);
742                }
743            }
744
745            wooco_init($wrap, 'on_click', $this);
746        }
747    });
748}
749
750function wooco_selected($selected, $selection, $component) {
751    var id = $selected.attr('data-id');
752    var pid = $selected.attr('data-pid');
753    var price = $selected.attr('data-price');
754    var purchasable = $selected.attr('data-purchasable');
755    var regular_price = $selected.attr('data-regular-price');
756    var link = $selected.attr('data-link');
757    var image = '<img src="' + $selected.attr('data-imagesrc') + '"/>';
758    var price_html = $selected.attr('data-price-html');
759    var availability = $selected.attr('data-availability');
760    var custom_qty = $component.attr('data-custom-qty');
761    var qid = id; // product ID for quick view
762
763    if (purchasable === 'yes') {
764        $component.attr('data-id', id);
765    } else {
766        $component.attr('data-id', 0);
767    }
768
769    $component.attr('data-price', price);
770    $component.attr('data-price-html', price_html);
771    $component.attr('data-regular-price', regular_price);
772
773    if (custom_qty === 'yes') {
774        if ($selected.find('.wooco_qty').length) {
775            $component.attr('data-qty', $selected.find('.wooco_qty').val());
776        } else if ($selected.find('.qty').length) {
777            $component.attr('data-qty', $selected.find('.qty').val());
778        }
779    }
780
781    if ((wooco_vars.quickview_variation === 'parent') && pid) {
782        qid = pid;
783    }
784
785    if (wooco_vars.product_link !== 'no') {
786        $selection.find('.wooco_component_product_link').remove();
787        if (link !== '') {
788            if (wooco_vars.product_link === 'yes_popup') {
789                $selection.append(
790                    '<a class="wooco_component_product_link woosq-link" data-id="' +
791                    qid + '" data-context="wooco" href="' + link +
792                    '" target="_blank"> &nbsp; </a>');
793            } else {
794                $selection.append(
795                    '<a class="wooco_component_product_link" href="' + link +
796                    '" target="_blank"> &nbsp; </a>');
797            }
798        }
799    }
800
801    $component.find('.wooco_component_product_image').html(image);
802    $component.find('.wooco_component_product_price').html(price_html);
803    $component.find('.wooco_component_product_availability').html(availability);
804
805    jQuery(document).trigger('wooco_selected', [$selected, $selection, $component]);
806}
807
808function wooco_select2_state(state) {
809    if (!state.id) {
810        return state.text;
811    }
812
813    var $state = {};
814
815    if (jQuery(state.element).attr('data-imagesrc') !== '') {
816        $state = jQuery('<span class="image"><img src="' +
817            jQuery(state.element).attr('data-imagesrc') +
818            '"/></span><span class="info"><span class="name">' + state.text +
819            '</span> <span class="desc">' +
820            jQuery(state.element).attr('data-description') + '</span></span>');
821    } else {
822        $state = jQuery('<span class="info"><span class="name">' + state.text +
823            '</span> <span class="desc">' +
824            jQuery(state.element).attr('data-description') + '</span></span>');
825    }
826
827    return $state;
828}
829
830function wooco_round(value) {
831    return Number(Math.round(value + 'e' + wooco_vars.price_decimals) + 'e-' +
832        wooco_vars.price_decimals);
833}
834
835function wooco_decimal_places(num) {
836    var match = ('' + num).match(/(?:\.(\d+))?(?:[eE]([+-]?\d+))?$/);
837
838    if (!match) {
839        return 0;
840    }
841
842    return Math.max(0, // Number of digits right of decimal point.
843        (match[1] ? match[1].length : 0)
844        // Adjust for scientific notation.
845        - (match[2] ? +match[2] : 0));
846}
847
848function wooco_format_money(number, places, symbol, thousand, decimal) {
849    number = number || 0;
850    places = !isNaN(places = Math.abs(places)) ? places : 2;
851    symbol = symbol !== undefined ? symbol : '$';
852    thousand = thousand || '';
853    decimal = decimal || '';
854
855    var negative = number < 0 ? '-' : '',
856        i = parseInt(number = Math.abs(+number || 0).toFixed(places), 10) + '',
857        j = 0;
858
859    if (i.length > 3) {
860        j = i.length % 3;
861    }
862
863    if (wooco_vars.trim_zeros === '1') {
864        return symbol + negative + (j ? i.substr(0, j) + thousand : '') +
865            i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) +
866            (places && (parseFloat(number) > parseFloat(i)) ? decimal +
867                Math.abs(number - i).toFixed(places).slice(2).replace(/(\d*?[1-9])0+$/g, '$1') : '');
868    } else {
869        return symbol + negative + (j ? i.substr(0, j) + thousand : '') +
870            i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand) +
871            (places ? decimal + Math.abs(number - i).toFixed(places).slice(2) : '');
872    }
873}
874
875function wooco_format_number(number) {
876    return parseFloat(number.replace(/[^0-9.,]/g, '').replace(',', '.'));
877}
878
879function wooco_format_price(price) {
880    var price_html = '<span class="woocommerce-Price-amount amount">';
881    var price_formatted = wooco_format_money(price, wooco_vars.price_decimals, '',
882        wooco_vars.price_thousand_separator, wooco_vars.price_decimal_separator);
883
884    switch (wooco_vars.price_format) {
885        case '%1$s%2$s':
886            //left
887            price_html += '<span class="woocommerce-Price-currencySymbol">' +
888                wooco_vars.currency_symbol + '</span>' + price_formatted;
889            break;
890        case '%1$s %2$s':
891            //left with space
892            price_html += '<span class="woocommerce-Price-currencySymbol">' +
893                wooco_vars.currency_symbol + '</span> ' + price_formatted;
894            break;
895        case '%2$s%1$s':
896            //right
897            price_html += price_formatted +
898                '<span class="woocommerce-Price-currencySymbol">' +
899                wooco_vars.currency_symbol + '</span>';
900            break;
901        case '%2$s %1$s':
902            //right with space
903            price_html += price_formatted +
904                ' <span class="woocommerce-Price-currencySymbol">' +
905                wooco_vars.currency_symbol + '</span>';
906            break;
907        default:
908            //default
909            price_html += '<span class="woocommerce-Price-currencySymbol">' +
910                wooco_vars.currency_symbol + '</span> ' + price_formatted;
911    }
912
913    price_html += '</span>';
914
915    return price_html;
916}
917
918function wooco_price_html(regular_price, sale_price) {
919    var price_html = '';
920
921    if (wooco_round(sale_price) !== wooco_round(regular_price)) {
922        if (wooco_round(sale_price) < wooco_round(regular_price)) {
923            price_html = '<del>' + wooco_format_price(regular_price) +
924                '</del> <ins>' + wooco_format_price(sale_price) + '</ins>';
925        } else {
926            price_html = wooco_format_price(sale_price);
927        }
928    } else {
929        price_html = wooco_format_price(regular_price);
930    }
931
932    return price_html;
933}

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.