PageSourceSearch

https://www.maxxis.com/int/wp-content/themes/maxxis/assets/js/tire_finder.js?ver=7.1.1

js maxxis.com collected 2026-10-02 07:43:45 UTC 8,765 bytes, 256 lines download raw bytes

1(function($) {
2
3    var $tfinder_parent_categories = $('.tfinder-parent-categories');
4    var $tfinder_children_categories = $('.tfinder-children-categories');
5    var $tfinder_sizes = $('.tfinder-sizes');
6    var $tfinder_findbtn = $('.tfinder-findbtn');
7    var $tfinder_sizes_props = $('.tfinder-sizes-props');
8
9    var $tfinder_form = $('.tfinder-form-fields');
10    var tfinder_select = '.tfinder-select';
11    var tfinder_form_url = $('.tfinder-form').attr('data-url');
12    var tfinder_form_results_url = $('.tfinder-form').attr('data-results-url');
13
14    var dynamic_values = false;
15    var has_vehicles = false;
16    var vehicles_filter_active = false;
17    var field_name_response = null;
18
19    $(document).ready(function(){
20        $tfinder_findbtn.hide();
21		//get_fields({});
22    })
23
24    function get_fields({field_name = null, action, selected = null, form_data = null}){
25        let request_data = {
26            action: action,
27            selected: selected,
28            field_name: field_name,
29            form_data: form_data
30        }
31
32        request({
33            url: tfinder_form_url,
34            data: request_data,
35            done_cb: function(data){
36                if(data.dynamic_values){
37                    dynamic_values = true;
38                };
39
40                if(data.has_vehicles){
41                    has_vehicles = true;
42                };
43
44                if(data.vehicles_filter_active){
45                    vehicles_filter_active = true;
46                };
47
48                if(data.field_name){
49                    field_name_response = data.field_name;
50                };
51
52                if(field_name_response && field_name_response === 'automotive_search_type'){
53                    $('.tfinder-select[field_name="automotive_search_type"]').nextAll().remove();
54                }
55
56
57                if(data.action === 'remove_all_bellow'){
58                    $(tfinder_select).each(function(k, v){
59                        if(!data.action_fields.includes($(v).attr('field_name'))){
60                            $(v).remove();
61                        }
62                    })
63                }
64
65                if(data && data.hasOwnProperty('fields') && data.fields.length > 0){
66                    data.fields.map(function(field){
67                        let field_html = get_select(
68                            field.field_name,
69                            field.options,
70                            field.placeholder,
71                            field.on_change,
72                            field.width,
73                            field.is_subcategory
74                        );
75
76                        let $existing_field =  $('.tfinder-select[field_name="' + field.field_name + '"]');
77
78                        if(vehicles_filter_active){
79                        	$($tfinder_form).append(field_html);
80                        } else {
81                            if(!dynamic_values){
82                                $($tfinder_form).append(field_html);
83                            } else {
84                                if($existing_field.length){
85                                    $existing_field.replaceWith(field_html);
86                                } else {
87                                    $($tfinder_form).append(field_html);
88                                }
89                            }
90                        }
91                    })
92                }
93
94                $(tfinder_select).attr('disabled', false);
95                $tfinder_findbtn.show();
96                $tfinder_findbtn.attr('disabled', false);
97            }
98        });
99    }
100
101    function get_select(field_name, options, placeholder, on_change, width, is_subcategory){
102        var html = '<select is_subcategory="'+is_subcategory+'" style="width: '+width+'" field_name="'+field_name+'" on_change="'+on_change+'" class="tfinder-select ' + field_name + '">';
103
104        if(placeholder){
105            html += '<option value="">' + placeholder + '</option>';
106        }
107
108        if(options){
109            options.map(function(option){
110                html += '<option ' + (option.selected ? "selected": '') + ' value="' + option.value + '">' + option.label + '</option>';
111            })
112        }
113
114        html += '<select>'
115
116        return html;
117    }
118
119    $(document).on('change', tfinder_select, function(){
120        let selected = $(this).find('option:selected').attr('value');
121        let on_change = $(this).attr('on_change');
122        let field_name = $(this).attr('field_name');
123        let is_subcategory = $(this).attr('is_subcategory') ? $(this).attr('is_subcategory') : false;
124        let is_category = $(this).attr('is_category') ? $(this).attr('is_category') : false;
125
126        if(on_change && on_change != 'undefined'){
127            if(is_category){
128                $(this).nextAll(tfinder_select).remove();
129            }
130
131            if(is_subcategory){
132                $(this).nextAll(tfinder_select).remove();
133            }
134
135            if(vehicles_filter_active){
136                $(this).nextAll(tfinder_select).remove();
137                //$('[is_subcategory="true"').nextAll(tfinder_select).remove();
138
139            } else {
140                if(!dynamic_values){
141                    $(this).nextAll(tfinder_select).remove();
142                }
143            }
144
145            $(tfinder_select).attr('disabled', 'disabled');
146            $tfinder_findbtn.attr('disabled', 'disabled');
147
148            let form_data = {};
149            $(tfinder_select).each(function(k ,v){
150                let field_value = $(v).find('option:selected').attr('value');
151
152                let field_key = $(v).attr('field_key');
153               
154                let field_name = $(v).attr('field_name');
155
156                if(field_value){
157                    form_data[field_name] =  field_value;
158                } else {
159                    //$(v).remove();
160                }
161            })
162
163            if(form_data.hasOwnProperty(field_name)){
164                form_data[field_name] = selected;
165            }
166
167            if(selected){
168                $(tfinder_select + '[field_name="' + field_name + '"] option').each(function(k,v){
169                    if($(v).is(':selected')){
170                        if($(v).attr('value') !== selected){
171                            $(v).removeAttr('selected');
172                        }
173                    }
174                })
175            }
176
177            if(dynamic_values && has_vehicles){
178                $('[is_subcategory="true"]').nextAll().remove();
179            }
180
181            if(!dynamic_values && !is_category && is_subcategory === 'undefined' && selected === ''){
182                $(this).remove();
183            }
184
185            get_fields({
186                field_name: field_name,
187                action: on_change,
188                selected: selected,
189                form_data: form_data
190            });
191        }
192    })
193
194    $tfinder_findbtn.on('click', function(e){
195       e.preventDefault();
196
197
198        let form_data = {};
199        $(tfinder_select).each(function(k ,v){
200            let field_value = $(v).find('option:selected').attr('value');
201
202            let field_name = $(v).attr('field_name');
203
204            if(field_value){
205                form_data[field_name] =  field_value;
206            }
207        })
208
209        var data = btoa(JSON.stringify(form_data));
210
211        let url = tfinder_form_results_url + '?filters=' + data;
212
213        window.location.href = url;
214    })
215
216
217    function request({
218        url = '/wp-json/tire-finder/get',
219        method = 'POST',
220        data = null,
221        done_cb = null,
222        done_cb_error = null,
223        fail_cb = null,
224        always_cb = null
225    }){
226        if(!data){
227            return null;
228        }
229
230        jQuery.ajax({
231            url: url,
232            method: method,
233            data: data
234        }).done(function (res) {
235            if(res.error){
236                console.error(res.data)
237                if(done_cb_error && typeof done_cb_error === 'function'){
238                    return done_cb(res.error)
239                }
240            } else {
241                if(done_cb && typeof done_cb === 'function'){
242                    return done_cb(res.data)
243                }
244            }
245        }).fail(function() {
246            if(fail_cb && typeof fail_cb === 'function'){
247                return fail_cb()
248            }
249            
250        }).always(function() {
251            if(always_cb && typeof always_cb === 'function'){
252                return always_cb()
253            }
254        });
255    }
256})( jQuery );

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.