PageSourceSearch

https://363gardens.com/wp-content/plugins/pix-settings/js/pix-script.js

js 363gardens.com collected 2026-10-07 17:44:27 UTC 7,673 bytes, 194 lines download raw bytes

1jQuery(document).ready(function($) {
2
3    // init vanillaSelectBox
4    function pixVanillaSelectBox() {
5        var pixMultiSelectBox = $('select.pix-multi-select'),
6            pixMultiSelect = [];
7
8        pixMultiSelectBox.each(function () {
9            var id = $(this).attr('id'),
10                placeholder = $(this).data('placeholder');
11
12            pixMultiSelect[id] = new vanillaSelectBox('#' + id, {
13                placeHolder: placeholder,
14                search: false
15            });
16        });
17    }
18    pixVanillaSelectBox();
19
20    function getSelectValues(id) {
21        var result = [],
22            collection = document.querySelectorAll("#" + id + " option");
23        
24        collection.forEach(function (x) {
25            if (x.selected) {
26                result.push(x.value);
27            }
28        });
29        return result;
30    }
31
32    function getSelectTotal(id) {
33        var total = 0,
34            select = document.getElementById(id),
35            collection = document.querySelectorAll("#" + id + " option");
36        
37        collection.forEach(function (x) {
38            if (x.selected) {
39                if(total === 0){
40                    total = parseFloat(x.dataset.price);
41                } else {
42                    total = select.dataset.operation === 'multi' ? total * parseFloat(x.dataset.price) : total + parseFloat(x.dataset.price);
43                }
44            }
45        });
46        return total;
47    }
48    
49    $('.pix-calculator [data-dependency]').each(function () {
50        var $dependency = $(this).attr('data-dependency'),
51            el = $(this),
52            hide = false;
53        
54        if(typeof $dependency !== 'undefined'){
55            $.each( JSON.parse($dependency), function() {
56                $.each( this, function( name, val ) {
57                    if (name !== '' && $('[name="' + name + '"]').val() !== val && !$('[name="' + name + '"]').hasClass('hide')) {
58                        hide = true;
59                    }
60                });
61            });
62        }
63        
64        if (hide === true) {
65            el.addClass('hide');
66            el.closest('.pix-calculator-field').addClass('hide');
67        }
68    });
69    
70    function set_dependency_fields(el) {
71        // $('[data-dependency='+el.attr('name')+']').each(function () {
72        //     if ( $(this).attr('data-dependency-val') !== el.find(':selected').attr('value')  ) {
73        //         $(this).addClass('hide');
74        //         $(this).closest('.pix-calculator-field').addClass('hide');
75        //     } else {
76        //         $(this).removeClass('hide');
77        //         $(this).closest('.pix-calculator-field').removeClass('hide');
78        //     }
79        // });
80        
81        el.closest('.pix-calculator').find('[data-dependency').each(function () {
82            var $dependency = $(this).attr('data-dependency'),
83                dep_el = $(this),
84                hide = false;
85            
86            if(typeof $dependency !== 'undefined'){
87                $.each( JSON.parse($dependency), function() {
88                    $.each( this, function( name, val ) {
89                        if (name !== '' && $('[name="' + name + '"]').val() !== val && !$('[name="' + name + '"]').hasClass('hide')) {
90                            hide = true;
91                        }
92                        
93                    });
94                });
95            }
96            
97            if (hide === true) {
98                dep_el.addClass('hide');
99                dep_el.closest('.pix-calculator-field').addClass('hide');
100            } else {
101                dep_el.removeClass('hide');
102                dep_el.closest('.pix-calculator-field').removeClass('hide');
103            }
104        });
105    }
106
107    function pix_calc_get_total($parent){
108        var $total = 0,
109            $out = '',
110            $decimals = $('.pix-calc-total-price', $parent).attr('data-decimals');
111        $('.pix-calc-value:not(.hide)', $parent).each(function() {
112            var operation = $(this).data('operation');
113            if($(this).is('.pix-multi-select')){
114                var str = (getSelectValues($(this).attr('id'))).join(','),
115                    sum = getSelectTotal($(this).attr('id'));
116                if($total === 0){
117                    $total = parseFloat(sum);
118                } else {
119                    $total = operation === 'multi' ? $total * parseFloat(sum) : $total + parseFloat(sum);
120                }
121                $out = $out + $(this).attr('data-title') + ': ' + str + ' - ' + sum + "\n";
122            } else if($(this).is('select') && $(this).find(':selected').attr('value') !== ''){
123                if($total === 0){
124                    $total = parseFloat($(this).find(':selected').attr('data-price'));
125                } else {
126                    $total = operation === 'multi' ? $total * parseFloat($(this).find(':selected').attr('data-price')) : $total + parseFloat($(this).find(':selected').attr('data-price'));
127                }
128                $out = $out + $(this).attr('data-title') + ': ' + $(this).val() + ' - ' + $(this).find(':selected').attr('data-price') + "\n";
129            } else if($(this).is('input[type="number"]') ){
130                var value = $(this).val();
131                if( value !== '' && $(this).attr('data-formula') !== '' ){
132                    var formula = $(this).attr('data-formula');
133                    value = eval(formula.replace('$val', value));
134                } else {
135                    value = 0;
136                }
137                if($total === 0){
138                    $total = parseFloat(value);
139                } else {
140                    $total = operation === 'multi' ? $total * parseFloat(value) : $total + parseFloat(value);
141                }
142                $out = $out + $(this).attr('data-title') + ': ' + $(this).val() + ' - ' + value + "\n";
143            } else {
144                if($(this).prop('checked')){
145                    if($total === 0){
146                        $total = parseFloat($(this).attr('data-price'));
147                    } else {
148                        $total = operation === 'multi' ? $total * parseFloat($(this).attr('data-price')) : $total + parseFloat($(this).attr('data-price'));
149                    }
150                    $out = $out + $(this).attr('data-title') + ': ' + $(this).val() + ' - ' + $(this).attr('data-price') + "\n";
151                }
152            }
153        });
154        
155        if($decimals > 0){
156            $total = $total.toFixed($decimals);
157        }
158        $('.pix-calc-total-price span', $parent).html($total);
159
160        if($('.pix-form-container', $parent).length){
161            $out = $out + $total;
162            $('.pix-form-container .pix-calculator-data', $parent).html($out);
163        }
164    }
165    
166    $(document).on('change', '.pix-calc-value', function() {
167        set_dependency_fields($(this));
168        pix_calc_get_total($(this).closest('.pix-calculator'));
169    });
170
171    $(document).on('click', '.pix-calc-total-btn a', function() {
172        if ( $( '.pix-form-container' ).first().is( ":hidden" ) ) {
173            $( '.pix-form-container' ).slideDown( 700 );
174        } else {
175            $( '.pix-form-container' ).slideUp( 700 );
176        }
177    });
178
179    $('.pix-reset a').on('click', function () {
180        var $parent = $(this).closest('.pix-calculator-fields'),
181            $fields = $(this).closest('.pix-calculator-field');
182
183        $('.pix-calc-value', $fields).each(function() {
184            if($(this).is('select')){
185                $(this).prop('selectedIndex', 0);
186            } else {
187                $(this).prop('checked', false);
188            }
189        });
190
191        pix_calc_get_total($parent);
192    });
193
194});

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.