PageSourceSearch

https://www.holiday.by/bundles/tour/scripts/search.js?v=2.2.35

js holiday.by collected 2026-09-24 18:10:59 UTC 14,395 bytes, 379 lines download raw bytes

1var SearchPromise = null;
2var Search = {
3    config: {
4        search_url: '',
5        ajax_search_url: '',
6        result_container: '',
7        filter_container: '',
8        resort_autocomplete_url: '',
9        routes: {
10            tours: '',
11            tours_country: '',
12            tours_ajax: ''
13        },
14        hot: 0
15    },
16    params: {},
17    landingRedirect: false, // if true - not reload tours
18    init : function( config, params ) {
19        $.extend( this.config, config );
20        this.params = params;
21        this.initHistory();
22        this.initFilterFields();
23        this.initPagination();
24        this.initSorting();
25    },
26    // enable html5 history
27    initHistory : function() {
28        var self = this;
29        History.Adapter.bind(window, "statechange", function () {
30            if (self.landingRedirect == true) {
31                self.landingRedirect = false;
32                return;
33            }
34
35            var state = History.getState();
36            var url = Routing.generate(self.config.routes.tours_ajax, self.params);
37
38            var $listPage = $('.page'),
39                $tourcCalc = $('.tours-list-header__tours-calc'),
40                $percentLoader = $('.list-loading-bar');
41
42            $percentLoader.css('width', '0%');
43            $listPage.addClass('list-loading');
44            $tourcCalc.addClass('in-process');
45
46            $('h1.category-title').text($('h1.category-title').attr('data-multipurpose'));
47            $('.tours-list-col__additional-seo').hide();
48
49            var percents = 0;
50            var intervalID = setInterval(function() {
51                percents += 10;
52                $percentLoader.css('width', percents + '%');
53                if (percents == 90) { clearInterval(intervalID); }
54            }, 50);
55
56            SearchPromise && SearchPromise.abort();
57            SearchPromise = $.ajax({
58                method: 'POST',
59                url: url,
60                success: function(response, textStatus, jqXHR) {
61                    $percentLoader.css('width', '100%');
62
63                    var prevToursCount = $(self.config.result_container).find('.tour-thumbnail').length;
64                    $(self.config.result_container).html(response);
65                    var newToursCount = $(self.config.result_container).find('.tour-thumbnail').length;
66
67                    var resultsCount = jqXHR.getResponseHeader('All-Results-Count');
68                    self.fillAllCountResults(resultsCount);
69
70                    var targetUrl = jqXHR.getResponseHeader('Target-Url');
71                    if (targetUrl) {
72                        self.landingRedirect = true;
73                        History.replaceState({}, $('title').text(), targetUrl);
74                    }
75
76                    if (resultsCount) {
77                        lazyLoadFn();
78
79                        if (self.config.hot) {
80                            carouFredSelInit('.js-shock-card-slider', "variable", true, 4000, '100%', false, 'center', true);
81                        } else {
82                            carouFredSelInit('.js-tour-card-slider', 1, true, '100%', "auto", false, 'center', true);
83                        }
84                    }
85
86                    $listPage.removeClass('list-loading');
87                    $tourcCalc.removeClass('in-process');
88
89                    loadTeasers('.openx-container');
90
91                    if (typeof loadYaBanners == 'function') {
92                        loadYaBanners();
93                    }
94
95                    $('.popupLoader').removeClass('loaded');
96                    $('#expert-pop-up').remove();
97                }
98            });
99        });
100    },
101    // bind fields
102    initFilterFields : function() {
103        var self = this,
104            $filter = $(self.config.filter_container);
105
106        // Country
107        $filter.find('.select-country').change(function() {
108            self.setParam('countrySlug', $(this).val(), true);
109            self.loadResorts();
110        });
111
112        // Earlybooking
113        $filter.find('#earlybooking').change(function() {
114            if ($(this).prop('checked')) {
115                self.setParam('earlybooking', 1, true);
116            } else {
117                self.setParam('earlybooking', '', true);
118            }
119        });
120
121        // bezviz
122        $filter.find('#bezviz').change(function() {
123            if ($(this).prop('checked')) {
124                self.setParam('bezviz', 1, true);
125            } else {
126                self.setParam('bezviz', '', true);
127            }
128        });
129
130        // Type
131        self.toggleFieldDisplay();
132        $filter.find('.select-tour-type').change(function() {
133            var type = $(this).val().split(':');
134            self.setParam('tour-type', '', false);
135            self.setParam('theme', '', false);
136            self.setParam(type[0], type[1], true);
137            self.toggleFieldDisplay();
138        });
139
140        // Date and Month
141        $filter.find('#departure_date_start').change(function() {
142            self.setParam('month', null, false);
143            self.setParam('from', $(this).val(), true);
144        });
145        $filter.find('#departure_date_end').change(function() {
146            self.setParam('month', null, false);
147            self.setParam('to', $(this).val(), true);
148        });
149        $filter.find('#daterange-dates .tours-filter__clear').click(function() {
150            self.setParam('from', null, false);
151            self.setParam('to', null, true);
152        });
153        $filter.find('#departure_month').change(function() {
154            self.setParam('from', null, false);
155            self.setParam('to', null, false);
156            self.setParam('month', $(this).val(), true);
157        });
158        $filter.find('#daterange-toggle-to-month').click(function() {
159            if ($filter.find('#departure_month').val()) {
160                self.setParam('from', null, false);
161                self.setParam('to', null, false);
162                self.setParam('month', $filter.find('#departure_month').val(), true);
163            }
164        });
165        $filter.find('#daterange-toggle-to-dates').click(function() {
166            if ($filter.find('#departure_date_start').val() || $filter.find('#departure_date_end').val()) {
167                self.setParam('month', null, false);
168                self.setParam('from', $filter.find('#departure_date_start').val(), false);
169                self.setParam('to',  $filter.find('#departure_date_end').val(), true);
170            }
171        });
172
173        $filter.find('#amount_of_nights_from').change(function() {
174            self.setParam('nights-from', $(this).val(), true);
175        });
176        $filter.find('#amount_of_nights_to').change(function() {
177            self.setParam('nights-to', $(this).val(), true);
178        });
179
180        // Price
181        $filter.find('.select-price input').focusout(function() {
182            self.setParam('price', null, false);
183            self.setParam('price-from', $('#tour-price-start').val().replace(/[^\/\d]/g,''), false);
184            self.setParam('price-to', $('#tour-price-end').val().replace(/[^\/\d]/g,''), true);
185        });
186        $filter.find('.select-price').closest('.tours-filter').find('.tours-filter__clear').click(function() {
187            self.setParam('price', null, false);
188            self.setParam('price-from', null, false);
189            self.setParam('price-to', null, true);
190        });
191
192        // Departure
193        $filter.find('.select-departure').change(function() {
194            self.setParam('departure', $(this).val(), true);
195        });
196
197        // Resort
198        $filter.find('.select-resort').change(function() {
199            var resort = $(this).val().split(':');
200            self.setParam('resort', '', false);
201            self.setParam('city', '', false);
202            self.setParam('cityby', '', false);
203            self.setParam(resort[0], resort[1], true);
204        });
205
206        // Stars
207        $filter.find('input.select-stars').change(function() {
208            // collect
209            var stars = [];
210            $filter.find('input.select-stars:checked').each(function() {
211                stars.push($(this).attr('data-value'));
212            });
213            // set
214            stars = stars.length ? stars.sort().join('-') : null;
215            self.setParam('hotel-class', stars, true);
216        });
217
218        // Board
219        $filter.find('.select-board').change(function() {
220            self.setParam('board', $(this).val(), true);
221        });
222
223        // Beach line
224        var $beachLineContainer = $filter.find('.select-beach-line');
225        $beachLineContainer.find('input').change(function () {
226            // collect
227            var beachLine = [];
228            $beachLineContainer.find('input:checked').each(function() {
229                beachLine.push($(this).attr('data-value'));
230            });
231            // set
232            beachLine = beachLine.length ? beachLine.join('-') : null;
233            self.setParam('beach-line', beachLine, true);
234        });
235        $beachLineContainer.closest('.tours-filter').find('.tours-filter__clear').click(function() {
236            self.setParam('beach-line', null, true);
237        });
238
239        // Transport
240        var $transportContainer = $filter.find('.select-transport');
241        $transportContainer.find('input.transport-type-input').change(function () {
242            // collect
243            var transport = [];
244            $transportContainer.find('input.transport-type-input:checked').each(function() {
245                transport.push($(this).attr('data-value'));
246            });
247            // set
248            transport = transport.length ? transport.join('-') : null;
249            self.setParam('transport', transport, true);
250        });
251        $transportContainer.closest('.tours-filter').find('.tours-filter__clear').click(function() {
252            self.setParam('transport-included', null, false);
253            self.setParam('no-night-moving', null, false);
254            self.setParam('transport', null, true);
255        });
256        $('#transport-included').change(function () {
257            if ($(this).prop('checked')) {
258                self.setParam('transport-included', 1, true);
259            } else {
260                self.setParam('transport-included', null, true);
261            }
262        });
263        $('#no-night-moving').change(function () {
264            if ($(this).prop('checked')) {
265                self.setParam('no-night-moving', 1, true);
266            } else {
267                self.setParam('no-night-moving', null, true);
268            }
269        });
270
271        // Agency
272        $filter.find('.select-agency').change(function() {
273            self.setParam('agency', $(this).val(), true);
274        });
275
276        // Installments
277        $filter.find('#installments').change(function() {
278            if ($(this).prop('checked')) {
279                self.setParam('installments', 1, true);
280            } else {
281                self.setParam('installments', '', true);
282            }
283        });
284
285        // Exact price
286        $filter.find('#exact_price').change(function() {
287            if ($(this).prop('checked')) {
288                self.setParam('exact_price', 1, true);
289            } else {
290                self.setParam('exact_price', '', true);
291            }
292        });
293
294    },
295    initPagination : function() {
296        // var self = this;
297        // $(document).on('click', '#show-more-tours a', function(e) {
298        //     self.setParam('p', $(this).attr('data-page'), true);
299        //     e.preventDefault();
300        // });
301    },
302    initSorting : function() {
303        var self = this;
304        $('.tours-sorting .sort-button').click(function () {
305            var order = $(this).attr('data-field');
306            var dir   = $(this).hasClass('up') ? 'desc' : 'asc';
307            $('.tours-sorting .sort-button').removeClass('active');
308            $(this).toggleClass('up').toggleClass('down').addClass('active');
309            self.setParam('order', order, false);
310            self.setParam('dir', dir, true);
311        });
312    },
313    // apply filter
314    startFilter : function() {
315        var route = this.config.routes.tours;
316        if (typeof this.params.countrySlug !== 'undefined' && this.params.countrySlug) {
317            route = this.config.routes.tours_country;
318        }
319        var url = Routing.generate(route, this.params);
320        History.pushState({}, $('title').text(), url);
321    },
322    // set filter param value
323    setParam : function (key, value, filter) {
324        this.deleteParam(key);
325        if (value) {
326            this.params[key] = value;
327        }
328        if (filter) {
329            if (key != 'p') {
330                this.deleteParam('p');
331            }
332            this.startFilter();
333        }
334    },
335    // delete filter param value
336    deleteParam : function (key) {
337        if (typeof this.params[key] !== 'undefined') {
338            delete this.params[key];
339        }
340    },
341    fillAllCountResults : function (count) {
342        $('.js-filter-results-count').text( declOfNum(count, ['Подобран', 'Подобрано', 'Подобрано']) + ' ' + count + ' ' + declOfNum(count, ['тур', 'тура', 'туров']));
343    },
344    loadResorts : function (needClear) {
345        var container = $(this.config.filter_container),
346            url = this.config.resort_autocomplete_url;
347
348        var selectizeResort = container.find('.select-resort').data().selectize;
349
350        selectizeResort.settings = $.extend(selectizeResort.settings, {
351            preload: true
352        });
353        selectizeResort.clear();
354        selectizeResort.clearOptions();
355        selectizeResort.load(function (callback) {
356            this.settings.load = null;
357            var $country = container.find('.select-country');
358            $.ajax({
359                url: url,
360                type: 'GET',
361                data: { term: '', countrySlug: $country.val() },
362                error: function (e) {
363                    console.error(e.responseText);
364                    callback();
365                },
366                success: function (data) {
367                    callback(data);
368                }
369            });
370        });
371    },
372    toggleFieldDisplay : function() {
373        if ((typeof this.params['tour-type'] === 'undefined' &&  typeof this.params['theme'] === 'undefined') || this.params['tour-type'] == 1) {
374            $('.only-for-packet').show();
375        } else {
376            $('.only-for-packet').hide();
377        }
378    }
379};

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.