PageSourceSearch

https://coralclub.ru/local/components/cci/menu.top.search/templates/.default/script.js?179146020814770

js coralclub.ru collected 2026-10-09 03:08:06 UTC 14,770 bytes, 375 lines download raw bytes

1$(document).ready(function () {
2    const saveSearched = (val) => {
3        if (window.last_search_products && !window.last_search_products.includes(val)) {
4            window.last_search_products.push(val);
5        }
6    };
7    const ls_interval = setInterval(() => {
8        localStorage.setItem('last_search_products', JSON.stringify(window.last_search_products));
9    }, 1000);
10
11    let firstSearch = false;
12
13    $(".search__nav-btn").on('click', function () {
14        firstSearch = true;
15        $.getJSON('/ajax/quickSearch.php', function(products) {
16            window.fast_search_products = products;
17        });
18    });
19
20    $(document.body).on('click', '.searchResults article', function (event) {
21        var search = $("#searchInput").val();
22        var value = $(this).find(".productBuy").attr("data-offer");
23        console.log(search,value);
24        dataLayer.push({'event': 'UAevent','eventCategory':search,'eventAction':value});
25    })
26    /*if($("html").hasClass("bx-touch")) {
27        $("#searchInput").change(function(){
28
29            if($("#searchInput").val().length > 0)
30                $(".searchBlock").find(".searchClear").show();
31            else {
32                $('.searchLabel').show();
33                $('.searchResults-quantity').hide();
34                $(".searchBlock").find(".searchClear").hide();
35            }
36
37            return true;
38        });
39
40    } else {
41
42    }*/
43    // $("#searchInput").keyup(function(event){
44    function delay(callback, ms) {
45        var timer = 0;
46        return function() {
47            var context = this, args = arguments;
48            clearTimeout(timer);
49            timer = setTimeout(function () {
50                callback.apply(context, args);
51            }, ms || 0);
52        };
53    }
54
55    function is_touch_device_search() {
56
57        var prefixes = ' -webkit- -moz- -o- -ms- '.split(' ');
58
59        var mq = function (query) {
60            return window.matchMedia(query).matches;
61        }
62
63        if (('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
64            return true;
65        }
66
67        var query = ['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join('');
68        return mq(query);
69    }
70
71    function hintEvents(hints, lines) {
72        hints.html(lines.join(''));
73
74        hints.find('.ls-hint').on('click', function() {
75            if (!$(this).hasClass('hint-link')) {
76                var query = $(this).get(0).dataset.query;
77                saveSearched(query);
78                $("#searchInput").val(query);
79                $("#searchResults-hints").html('');
80
81                if ($("#searchInput").val().length > 0){
82                    $(".searchBlock").find(".searchClear").removeClass('none').removeAttr('style');
83                } else {
84                    $('.searchLabel').show();
85                    $('.searchResults-quantity').hide();
86                    $(".searchBlock").find(".searchClear").addClass('none').removeAttr('style');
87                }
88
89                initSearch();
90            } else {
91                $('body').fadeOut();
92            }
93        });
94
95        hints.find('.ls-hint .remove-ls').on('click', function(e) {
96            e.stopPropagation();
97            var query = $(this).get(0).dataset.query;
98            const index = window.last_search_products.indexOf(query);
99            if (index > -1) {
100                window.last_search_products.splice(index, 1);
101                $("#searchInput").trigger('keyup');
102            }
103        });
104    }
105
106    $("#searchInput").on('keyup touchend', function(keyEvent) {
107        const hints = $("#searchResults-hints");
108        const searchValue = $(this).val();
109
110        if (searchValue.length > 0) {
111            const lines = [];
112            var count = 0;
113
114            // last search
115            if (window.last_search_products && window.last_search_products.length > 0) {
116                const lsRows = window.last_search_products.filter(function(element) {
117                    const name = element.toLowerCase();
118                    return name.indexOf(searchValue.toLowerCase()) === 0;
119                });
120
121                for (const item of lsRows ) {
122                    if (count > 4) break;
123                    var str = "<span class='hint ls-hint' data-query='"+item+"'><span class='txt'>" + item.toLowerCase().replace(searchValue.toLowerCase(), '<b>' + searchValue.toLowerCase() + '</b>') + "</span> <i class='icon-ls'></i><i class='remove-ls' data-query='"+item+"'></i></span>";
124                    lines.push(str);
125                    count++;
126                }
127            }
128
129            // fast search
130            const rows = window.fast_search_products.filter(function(element) {
131                const name = element.value.toLowerCase();
132                return name.includes(searchValue.toLowerCase());
133            });
134
135            /*for (const item of rows ) {
136                if (count > 9) break;
137                var str = "<a href='/shop/redirectToProduct.php?OFFER_ID="+item.objectId+"' class='hint ls-hint hint-link' data-query='"+item.value+"'><span class='txt'>" + item.value.toLowerCase().replace(searchValue.toLowerCase(), '<b>' + searchValue.toLowerCase() + '</b>') + "</span></a>";
138                lines.push(str);
139                count++;
140            }*/
141
142            hintEvents(hints, lines);
143            if (keyEvent.keyCode === 13) {
144                saveSearched(searchValue);
145                hints.html('');
146            }
147        } else {
148            if (window.last_search_products && window.last_search_products.length > 0) {
149                const lines = [];
150                var count = 0;
151                const reversed = JSON.parse(JSON.stringify(window.last_search_products)).reverse();
152                for (const item of reversed ) {
153                    if (count > 4) break;
154                    var str = "<span class='hint ls-hint' data-query='"+item+"'><span class='txt'>" + item + "</span> <i class='icon-ls'></i><i class='remove-ls' data-query='"+item+"'></i></span>";
155                    lines.push(str);
156                    count++;
157                }
158                hintEvents(hints, lines);
159            }
160        }
161    });
162
163    $("#searchInput").on('blur', function(e) {
164        setTimeout(function() {
165            $("#searchResults-hints").html('');
166        }, 400);
167    });
168    $("#searchInput").on('focus click', function() {
169        if (!firstSearch) {
170            $('#searchInput').trigger('keyup');
171        } else {
172            firstSearch = false;
173        }
174    });
175
176
177    $("#searchInput").on('keyup touchend', delay(function(event) {
178        if ($("html").hasClass("bx-touch")) {
179            // if(event.keyCode != 13){
180            //     return false;
181            // }
182            // $("#searchInput").blur();
183        }
184
185        if ($("#searchInput").val().length > 0){
186            $(".searchBlock").find(".searchClear").removeClass('none').removeAttr('style');
187        }else {
188            $('.searchLabel').show();
189            $('.searchResults-quantity').hide();
190            $(".searchBlock").find(".searchClear").addClass('none').removeAttr('style');
191        }
192
193        initSearch();
194        return true;
195    },is_touch_device_search()?2000:1100));
196
197    $(".searchClear").click(function () {
198        $("#searchInput").val("").focus();
199        $('.searchResults').html("");
200        $(".searchBlock").find(".searchClear").addClass('none').removeAttr('style');
201        $('.searchLabel').show();
202        $('.searchResults-quantity').hide();
203        $("#searchResults-hints").html('');
204    });
205
206    $('.searchLabel a').click(function () {
207        $("#searchInput").val($(this).text()).trigger('keyup');
208        $(".searchBlock").find(".searchClear").removeClass('none').removeAttr('style');
209    });
210    var productCodes = [];
211    var addSearchProductsToAnalytics = function () {
212        var catalogList = document.querySelectorAll('.searchBlock .catalog-items');
213        catalogList.forEach(function( list ){
214            var elements = list.querySelectorAll('.prod_card');
215            var analyticsData = [];
216            elements.forEach(function( target, index ){
217
218                //  позиция элемента
219                var targetPosition = {
220                        top: window.pageYOffset + target.getBoundingClientRect().top,
221                        left: window.pageXOffset + target.getBoundingClientRect().left,
222                        right: window.pageXOffset + target.getBoundingClientRect().right,
223                        bottom: window.pageYOffset + target.getBoundingClientRect().bottom
224                    },
225                    // позиции окна
226                    windowPosition = {
227                        top: window.pageYOffset,
228                        left: window.pageXOffset + target.closest('.catalog-items').getBoundingClientRect().left,
229                        right: window.pageXOffset + target.closest('.catalog-items').getBoundingClientRect().right,
230                        bottom: window.pageYOffset + document.documentElement.clientHeight
231                    };
232
233                if (targetPosition.bottom > windowPosition.top &&
234                    targetPosition.top < windowPosition.bottom &&
235                    targetPosition.right > windowPosition.left &&
236                    targetPosition.left < windowPosition.right) {
237                    if (!productCodes.includes(target.dataset.code)){
238                        productCodes.push(target.dataset.code);
239                        if(target.dataset.offer_data != undefined) {
240                            var dataPrepared = JSON.parse(target.dataset.offer_data);
241                            dataPrepared.index = ++index;
242                            analyticsData.push(dataPrepared);
243                        }
244                    }
245                }
246            });
247            if(analyticsData.length>0){
248                window.dataLayer = window.dataLayer || [];
249                window.dataLayer.push({ ecommerce: null });
250                window.dataLayer.push({
251                    'event': 'view_item_list',
252                    'ecommerce': {
253                        'item_list_id': list.dataset.list_id || "",
254                        'item_list_name': list.dataset.list_name || "",
255                        'currency': window.currency_name, //Валюта RUB, EUR, USD
256                        'items': analyticsData
257                    }
258                });
259
260                console.log('view_item_list search');
261                console.log(analyticsData);
262            }
263
264        });
265    };
266    var timeoutObject = new Object();
267
268    var search_answer = 1;
269    var search_word_temp = "";
270    var search_cache = {};
271
272    function initSearchFlashTimers($container) {
273        if (typeof initializeClock !== "function") {
274            return;
275        }
276
277        var createFlashTime = function (flashDate) {
278            var parts = flashDate.split("/");
279            var date = parts[0].split(".");
280            var time = parts[1].split(":");
281            return new Date(date[2], parseInt(date[1], 10) - 1, date[0], time[0], time[1], time[2]);
282        };
283
284        $container.find(".catalog_flash_time").each(function () {
285            var $timer = $(this);
286            var flashEnd = $timer.data("flash_date");
287            var flashStart = $timer.data("flash_date_start");
288
289            if (!flashEnd || !flashStart) {
290                return;
291            }
292
293            initializeClock($timer, createFlashTime(flashEnd), createFlashTime(flashStart));
294        });
295    }
296
297    function initSearch(){
298        var search_word = "";
299        search_word = $("#searchInput").val()?.trim().replace(/\s+/g, ' ');
300        // Ищем попавшие в видимую область экрана продукты
301
302        if (typeof search_cache[search_word] !== "undefined") {
303            var data = search_cache[search_word];
304            $('.searchResults').html(data.HTML);
305            $('.searchLabel').hide();
306            $('.searchResults-quantity').html(data.MESSAGE);
307            $('.searchResults-quantity').show();
308
309            if (typeof initItemsHeight === "function") {
310                initItemsHeight();
311            }
312
313            $('.lazy').Lazy({
314                effect: 'fadeIn',
315                visibleOnly: true,
316            });
317            initSearchFlashTimers($('.searchResults'));
318            addSearchProductsToAnalytics();
319
320        } else if((search_word.length > 2 || search_word == "D3" || search_word == "Д3" || search_word == "д3" || search_word == "d3") && search_word_temp != search_word){
321            search_word_temp = search_word;
322            var $searchLoader = $('.searchLoader');
323
324            if (typeof timeoutObject["search"] !== "undefined") {
325                clearTimeout(timeoutObject["search"]);
326            }
327
328            $('.searchResults').html("");
329            $searchLoader.show();
330
331            timeoutObject["search"] = setTimeout(function() {
332                if (search_answer == 1) {
333                    search_answer = 0;
334                    $.ajax({
335                        type: "POST",
336                        url: '/ajax/search.php',
337                        data: {
338                            sessid: BX.bitrix_sessid(),
339                            text: search_word
340                        },
341                        dataType: "json",
342                        timeout: 1000*60,
343                        async: true,
344                        error: function (request, error) {
345                            console.log(error);
346                        },
347                        success: function (data) {
348                            search_answer = 1;
349                            $('.searchResults').html(data.HTML);
350                            $('.searchLabel').hide();
351                            $('.searchResults-quantity').html(data.MESSAGE);
352                            $('.searchResults-quantity').show();
353                            $searchLoader.hide();
354                            if (typeof initItemsHeight === "function") {
355                                initItemsHeight();
356                            }
357
358                            $('.lazy').Lazy({
359                                effect: 'fadeIn',
360                                visibleOnly: true,
361                            });
362                            initSearchFlashTimers($('.searchResults'));
363                            addSearchProductsToAnalytics();
364                            search_cache[search_word] = data;
365                        }
366                    })
367                };
368            }, 500);
369        }
370
371        document.querySelector('.popup-search-menu-slide').addEventListener('scroll', function() {
372            addSearchProductsToAnalytics();
373        });
374    };
375});

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.