PageSourceSearch

https://www.turpravda.com/static/js/index_suggest.js

js turpravda.com collected 2026-10-02 11:17:03 UTC 5,193 bytes, 115 lines download raw bytes

1(function(obj, $){
2
3    $(function(){
4
5        var $input = $('#indexSearch');
6        var cacheLimit = 15;
7        var suggestCache = {};
8
9        $input.tpautocomplete({
10            appendTo:'#cntListLocal',
11            source: function(request, response) {
12                if(suggestCache[request.term] !== undefined){
13                    response(suggestCache[request.term]);
14                    return;
15                }
16
17                $.ajax({
18                    url: obj.baseUrl +"/reviews/fullsearch/",
19                    //url: "/tmp.php",
20                    type: 'POST',
21                    dataType: 'json',
22                    data:  {search:$.toJSON({text:request.term})},
23                    success: function(d) {
24                        if(d && d.data && d.data.length != 0){
25                            suggestCache[request.term] = d.data;
26                            var n = 0;
27                            var m = [];
28                            for(var i in suggestCache){
29                                n++;
30                                m.push(i);
31                            }
32                            for(var k = 0; k<n-cacheLimit; k++){
33                                delete suggestCache[m[k]];
34                            }
35
36                            if ( jQuery('body').hasClass('Index-index') ) {
37                                dataLayer.push({'event':'GAevent', 'eCategory':'Search', 'eAction':'Home', 'eLabel':'GotResults', 'eValue':d.data.length});
38                            } else if ( jQuery('body').hasClass('Country-all') ) {
39                                dataLayer.push({'event':'GAevent', 'eCategory':'Search', 'eAction':'Countries', 'eLabel':'GotResults', 'eValue':d.data.length});
40                            } else if ( jQuery('body').hasClass('Sight-index') ) {
41                                dataLayer.push({'event':'GAevent', 'eCategory':'Search', 'eAction':'Places', 'eLabel':'GotResults', 'eValue':d.data.length});
42                            } else if ( jQuery('body').hasClass('Agency-index') ) {
43                                dataLayer.push({'event':'GAevent', 'eCategory':'Search', 'eAction':'Agents', 'eLabel':'GotResults', 'eValue':d.data.length});
44                            }
45                            
46                            response(d.data);
47                        } else {
48                           var $data = [];
49
50                            $data.push({
51                                type: "notfound",
52                                label: jQuery.i18n('search_not_found')+"<div><a href='"+obj.baseUrl+"/countries.html'>"+jQuery.i18n("hotels")+"</a></div>",
53                                value: jQuery('#suggestSearch').val(),
54                                inputValue: jQuery('#indexSearch').val()
55                            });
56
57                            response($data);
58                            //
59                            //var $menu = jQuery(".ui-autocomplete.ui-menu");
60                            //var $li = jQuery('li').html('Отелей не найдено');
61                            //
62                            //$menu.html('');
63                            //
64                            //$menu.append($li).show();
65                            //console.log($menu);
66                        }
67                    }
68                });
69            },
70            select: function(h, v){
71                var item = v.item;
72
73                if(item.type == 'notfound'){
74                    jQuery('#search_form').submit();
75                    return;
76
77                } else if(item.type == 'sight'){
78                    window.location.href = (obj.baseUrl? obj.baseUrl:"") +
79                        '/places/' + item.code + '/' + item.nameTr + '/' + item.translit + '-s' + item.objectId + '/'
80
81                }else if(item.type == 'user'){
82                    window.location.href = obj.baseUrlMy +
83                        '/' + item.value + '/';
84
85                } else if(item.type == 'agency'){
86                    window.location.href = (obj.baseUrl? obj.baseUrl:"") +
87                        '/Турфирмы/' + item.value + '-' + item.agencyId + '/'
88
89                }else if(item.objectId >= 5000) {
90                    window.location.href = (obj.baseUrl? obj.baseUrl:"") +
91                        '/' + item.code + '/' + item.nameTr + '/' + item.link + '-h' + item.objectId + '.html';
92
93                } else if(item.objectId >= 500) {
94                    window.location.href = (obj.baseUrl? obj.baseUrl:"") +
95                        '/' + item.code + '/' + item.nameTr + '/';
96
97                } else {
98                    window.location.href = (obj.baseUrl? obj.baseUrl:"") +
99                        '/' + item.code + '/';
100                }
101                dataLayer.push({
102                    'event': 'GAevent',
103                    'eCategory': 'Main',
104                    'eAction': 'Search_suggest'
105                });
106            },
107            minLength: 3,
108            delay: 500,
109            autoFocus: true
110        })
111        $input.focus(function(){
112           $(this).tpautocomplete('search', $(this).val());
113        });
114    })
115})(obj, 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.