1jQuery(document).ready(function($) { 2var lastSearchTerm = ''; 3var lastResultsHtml = ''; 4var lastResultsCount = 0; 5 var searchTimeout; 6 var currentCategory = 0; 7 var isMobileActive = false; 8 9 var $searchContainer = $('.floating-side-search'); 10 var $searchInput = $('.floating-side-search-input'); 11 var $searchBtn = $('.floating-side-search-btn'); 12 var $resultsContainer = $('.floating-side-search-results'); 13 var $filterToggle = $('.floating-side-filter-toggle'); 14 var $filterOptions = $('.floating-side-filter-options'); 15 var $overlay = $('.floating-side-overlay'); 16 var $mobileClose = $('.floating-side-mobile-close'); 17 18 // ФилÑÑÑ ÐºÐ°ÑегоÑий 19 $filterToggle.on('click', function(e) { 20 e.stopPropagation(); 21 $filterOptions.toggleClass('active'); 22 }); 23 24 $(document).on('click', function(e) { 25 if (!$(e.target).closest('.floating-side-filter-dropdown').length) { 26 $filterOptions.removeClass('active'); 27 } 28 }); 29 30 $('.floating-side-filter-option').on('click', function() { 31 currentCategory = $(this).data('category-id'); 32 var categoryName = $(this).text(); 33 $('.floating-side-filter-current').text(categoryName); 34 $filterOptions.removeClass('active'); 35 36 if ($searchInput.val().trim().length >= 2) { 37 performSearch(true); 38 } 39 }); 40 41 42// ÐÑинÑдиÑелÑно обновлÑем flex поÑле оÑкÑÑÑÐ¸Ñ Ð¿Ð°Ð½ÐµÐ»Ð¸ 43$('.floating-search-text').on('click', function() { 44 setTimeout(function() { 45 $('.floating-side-search-results').css('height', 'auto'); // на вÑÑкий ÑлÑÑай 46 }, 350); 47}); 48 49 // ÐобилÑнÑй Ñежим 50function activateMobileMode() { 51 if (isMobileActive) return; 52 isMobileActive = true; 53 $searchContainer.addClass('mobile-active'); 54 $searchBtn.hide(); 55$('body').addClass('floating-search-no-scroll'); 56 setTimeout(function() { 57 $searchInput.focus(); 58 }, 100); 59} 60 61function deactivateMobileMode() { 62 if (!isMobileActive) return; 63 isMobileActive = false; 64 $searchContainer.removeClass('mobile-active'); 65 $resultsContainer.hide(); 66$('body').removeClass('floating-search-no-scroll'); 67 $searchInput.blur(); 68 $searchBtn.show(); 69 $('.floating-search-handle').show(); // â ÐÐÐÐÐ ÐЩÐÐРРУЧÐУ (лÑпÑ) 70 // ÐакÑÑваем внеÑнÑÑ Ð¿Ð°Ð½ÐµÐ»Ñ Ð²Ð¸Ð´Ð¶ÐµÑа (еÑли она оÑкÑÑÑа) 71 var $widget = $('.floating-search-widget'); 72 $widget.removeClass('open').addClass('collapsed'); 73} 74 75 if (window.innerWidth <= 768) { 76 $searchInput.on('focus', function(e) { 77 if (!isMobileActive) { 78 e.preventDefault(); 79 activateMobileMode(); 80 } 81 }); 82 83 $mobileClose.on('click', function() { 84 deactivateMobileMode(); 85 }); 86 87 $overlay.on('click', function() { 88 deactivateMobileMode(); 89 }); 90 } 91 92 $(window).on('resize', function() { 93 if (window.innerWidth > 768 && isMobileActive) { 94 deactivateMobileMode(); 95 } 96 }); 97 98 // ÐоиÑк 99function performSearch(force) { 100 var searchTerm = $searchInput.val().trim(); 101 102 if (searchTerm.length < 2) { 103 $resultsContainer.hide().empty(); 104 lastSearchTerm = ''; 105 lastResultsHtml = ''; 106 return; 107 } 108 109 // ÐÑли поиÑковÑй ÑеÑмин не изменилÑÑ Ð¸ force=false â показÑваем ÑÑаÑÑе ÑезÑлÑÑаÑÑ (еÑли они еÑÑÑ) 110 if (!force && searchTerm === lastSearchTerm && lastResultsHtml) { 111 $resultsContainer.html(lastResultsHtml).show(); 112 return; 113 } 114 115 clearTimeout(searchTimeout); 116 $resultsContainer.html('<div class="floating-side-search-loading">ð ÐоиÑк...</div>').show(); 117 118 searchTimeout = setTimeout(function() { 119 $.ajax({
120 url: floating_search.ajax_url, 121 type: 'POST', 122 data: { 123 action: 'floating_ajax_search', 124 search_term: searchTerm, 125 category_id: currentCategory, 126 nonce: floating_search.nonce 127 }, 128 success: function(response) { 129 if (response.success && response.data.length > 0) { 130 var html = '<div class="floating-side-results-count">Ðайдено: ' + response.data.length + '</div>'; 131 $.each(response.data, function(i, product) { 132 var metaHtml = ''; 133 if (product.artikul) metaHtml += '<span class="floating-side-meta-item">ÐÑÑикÑл: ' + product.artikul + '</span>'; 134 if (product.kod) metaHtml += '<span class="floating-side-meta-item">Ðод: ' + product.kod + '</span>'; 135 136 html += ` 137 <div class="floating-side-result-item" data-url="${product.url}"> 138 <div class="floating-side-result-image"> 139 ${product.image ? `<img src="${product.image}" alt="${product.title}">` : '<span>ð¦</span>'} 140 </div> 141 <div class="floating-side-result-content"> 142 <div class="floating-side-result-title">${product.title}</div> 143 ${metaHtml ? `<div class="floating-side-result-meta">${metaHtml}</div>` : ''} 144 <div class="floating-side-result-price">${product.price}</div> 145 </div> 146 <div class="floating-side-result-actions"> 147 ${product.quick_view} 148 </div> 149 </div> 150 `; 151 }); 152 lastSearchTerm = searchTerm; 153 lastResultsHtml = html; 154 $resultsContainer.html(html).show(); 155 } else { 156 $resultsContainer.html('<div class="floating-side-search-no-results">ð ÐиÑего не найдено</div>').show(); 157 } 158 }, 159 error: function() { 160 $resultsContainer.html('<div class="floating-side-search-error">â ï¸ ÐÑибка поиÑка</div>').show(); 161 } 162 }); 163 }, 400); 164} 165 166 $searchInput.on('input', function() { performSearch(false); }); 167 $searchInput.on('keypress', function(e) { if (e.which === 13) { e.preventDefault(); performSearch(true); } }); 168 $searchBtn.on('click', function() { performSearch(true); }); 169 170// СкÑÑваем клавиаÑÑÑÑ Ð¿Ñи ÑкÑолле ÑезÑлÑÑаÑов (мобилÑнÑе) 171$resultsContainer.on('scroll', function() { 172 if (window.innerWidth <= 768) { 173 $searchInput.blur(); 174 } 175}); 176 177// ÐоказÑваем кÑÑиÑованнÑе ÑезÑлÑÑаÑÑ Ð¿Ñи ÑокÑÑе на поле (деÑкÑоп и мобилÑнÑе) 178$searchInput.on('focus', function() { 179 var term = $searchInput.val().trim(); 180 if (term.length >= 2 && lastResultsHtml) { 181 $resultsContainer.html(lastResultsHtml).show(); 182 } 183}); 184 185 $(document).on('click', function(e) { 186 if (!$(e.target).closest('.floating-side-search-wrapper').length && !isMobileActive) { 187 $resultsContainer.hide(); 188 } 189 }); 190 191 // === ÐÐÐ ÐÐÐТЧÐÐÐ ÐÐÐÐÐÐ (ÐСÐÐ ÐÐÐÐÐÐЫÐ) === 192 193 // Ðлик по каÑÑоÑке ÑоваÑа - пеÑÐµÑ Ð¾Ð´ на ÑÑÑаниÑÑ (ÐРеÑли кликнÑли на ÐºÐ½Ð¾Ð¿ÐºÑ Ð±ÑÑÑÑого пÑоÑмоÑÑа) 194 $(document).on('click', '.floating-side-result-item', function(e) { 195 // ÐÑли кликнÑли на ÐºÐ½Ð¾Ð¿ÐºÑ Ð±ÑÑÑÑого пÑоÑмоÑÑа â не пеÑÐµÑ Ð¾Ð´Ð¸Ð¼ 196 if ($(e.target).closest('.woosq-btn').length) { 197 e.preventDefault(); 198 e.stopPropagation(); 199 return; 200 } 201 window.location.href = $(this).data('url'); 202 });
203 204 // Ðнопка бÑÑÑÑого пÑоÑмоÑÑа â ÑолÑко оÑкÑÑÑие попапа, без пеÑÐµÑ Ð¾Ð´Ð° 205 $(document).on('click', '.floating-side-result-actions .woosq-btn', function(e) { 206 e.stopPropagation(); 207 e.preventDefault(); 208 // Ðлагин WPC Smart Quick View Ñам обÑабоÑÐ°ÐµÑ Ð¾ÑкÑÑÑие попапа 209 }); 210 211 // СÑаÑÑй обÑабоÑÑик â оÑклÑÑаем 212 $(document).off('click', '.floating-side-quick-view'); 213 $(document).on('click', '.floating-side-quick-view', function(e) { 214 e.stopPropagation(); 215 e.preventDefault(); 216 }); 217 218 $(document).on('keyup', function(e) { 219 if (e.key === 'Escape') { 220 if (isMobileActive) { 221 deactivateMobileMode(); 222 } 223 $resultsContainer.hide(); 224 } 225 }); 226});
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.