1/*ÐоиÑк*/ 2jQuery(document).ready(function($) { 3 function initializeSearch(formSelector, inputSelector, resultsSelector) { 4 var searchForm = $(formSelector); 5 var searchInput = searchForm.find(inputSelector); 6 var searchResults = searchForm.find(resultsSelector); 7 8 searchInput.on('input', function() { 9 var query = $(this).val(); 10 if (query.length > 2) { 11 $.ajax({ 12 url: search_params.ajax_url, 13 type: 'POST', 14 data: { 15 action: 'ajax_product_search', 16 query: query 17 }, 18 success: function(response) { 19 var resultsHTML = ''; 20 21 // ÐÑобÑажение каÑегоÑий 22 if (response.categories && response.categories.length > 0) { 23 response.categories.forEach(function(category) { 24 resultsHTML += '<a href="' + category.link + '" class="search-category">' + 25 '<img class="search-icons" src="' + category.icon + '">' + 26 '<div class="search-product__info-name">' + category.name + '</div>' + 27 '<img class="search-arrow" src="' + category.arrov + '">' + 28 '</a>'; 29 }); 30 } 31 32 // ÐÑобÑажение ÑоваÑов 33 if (response.products && response.products.length > 0) { 34 response.products.forEach(function(product) { 35 var price = $('<div>').html(product.price).find('ins .woocommerce-Price-amount').text() || 36 $('<div>').html(product.price).find('.woocommerce-Price-amount').text(); 37 resultsHTML += '<a href="' + product.link + '" class="search-product">' + 38 '<img class="search-thumb" src="' + product.image + '">' + 39 '<div class="search-product__info">' + 40 '<div class="search-product__info-name">' + product.name + '</div>' + 41 '<span class="product-price' + (product.is_on_sale ? ' sale-price' : '') + '">' + product.price + '</span>' + 42 '</div>' + 43 '<img class="search-arrow" src="' + product.arrov + '">' + 44 '</a>'; 45 }); 46 } 47 48 // ÐÑли Ð½ÐµÑ ÑезÑлÑÑаÑов 49 if (!response.products || response.products.length === 0) { 50 resultsHTML += '<div class="search-no-results">ÐиÑего не наÑли</div>'; 51 } 52 53 // СÑÑлка на вÑе ÑезÑлÑÑаÑÑ 54 if (response.total_results > 0) { 55 resultsHTML += '<div class="search-all-results">' + 56 '<a href="/?s=' + query + '&post_type=product">ÐÑе ÑезÑлÑÑаÑÑ Ð¿Ð¾Ð¸Ñка (' + response.total_results + ')</a>' + 57 '</div>'; 58 } 59 60 searchResults.html(resultsHTML).css('display', 'flex').show(); 61 } 62 }); 63 } else { 64 searchResults.html('').hide(); 65 } 66 }); 67 68 // СкÑÑваем ÑезÑлÑÑаÑÑ Ð¿Ð¾Ð¸Ñка пÑи клике вне ÑоÑÐ¼Ñ 69 $(document).on('click', function(e) { 70 if (!$(e.target).closest(searchForm).length) { 71 searchResults.hide(); 72 } 73 }); 74 } 75 76 // ÐниÑиализаÑÐ¸Ñ Ð´Ð»Ñ Ð¾Ð±ÐµÐ¸Ñ ÑоÑм 77 initializeSearch('#searchform-pc', '#s-pc', '.search-results-box'); 78 initializeSearch('#searchform-mobile', '#s-mobile', '.search-results-box'); 79 80}); 81 82
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.