1(function ($, window) { 2 'use strict'; 3 4 if (!$ || !$.fn || !$.fn.autocomplete) return; 5 if (window.aiSearchSuggestionsInitialized) return; 6 window.aiSearchSuggestionsInitialized = true; 7 8 var storageKey = 'aiSearchSuggestionsV16'; 9 var recentSearchCookie = 'recentsearch'; 10 var recentSearchCookieLifetime = 60 * 60 * 24 * 90; 11 var memoryCache = readCache(); 12 var activeRequest = null; 13 var discoveryRequest = null; 14 var popularSuggestions = null; 15 var popularProductSuggestions = null; 16 var loadingStylesMounted = false; 17 18 initializeSuggestions(); 19 20 function initializeSuggestions() { 21 mountLoadingStyles(); 22 window.setTimeout(mount2xuSearchCatalogLinks, 500); 23 patchSmartSearchListing(); 24 window.setTimeout(patchSmartSearchListing, 500); 25 $('#smart-search-query[name="keywords"], .smart-search-form input[name="keywords"], form.quick_find input[name="keywords"], form.home-smart-search input[name="keywords"]').each(function () { 26 var input = this; 27 var form = $(input).closest('form')[0]; 28 if (!form || $(input).data('ai-search-suggestions')) return; 29 if ($(form).hasClass('two-xu-smart-search') && window.innerWidth > 1023) { 30 $(form).addClass('anta-search-discovery'); 31 } 32 if ($(form).hasClass('js-navbar-form') 33 && /\/search_ai\.php(?:$|\?)/.test($(form).attr('action') || '')) { 34 $(form).addClass('anta-search-discovery'); 35 } 36 if ($(form).hasClass('quick_find')) { 37 try { 38 if ($(input).data('ui-autocomplete')) $(input).autocomplete('destroy'); 39 } catch (error) { 40 // The legacy header search may have a partially initialized widget. 41 } 42 removeLegacyHeaderHandler(input, 'focus', 'youAlreadySearched'); 43 removeLegacyHeaderHandler(form, 'submit', 'search'); 44 } 45 46 $(input).data('ai-search-suggestions', true); 47 $(form).off('submit.aiSearchLoading').on('submit.aiSearchLoading', function () { 48 if ($.trim(input.value || '') !== '') { 49 addRecentSearch(input.value); 50 showSearchLoading(form); 51 } 52 }); 53 54 $(input).autocomplete({ 55 appendTo: $(form), 56 minLength: 2, 57 delay: 120, 58 open: function () { 59 updateSearchSuggestionsPosition(input, form); 60 setSearchSuggestionsOpen(input, true); 61 }, 62 close: function () { 63 setSearchSuggestionsOpen(input, false); 64 }, 65 source: function (request, response) { 66 var term = normalize(request.term); 67 hideSearchDiscovery(input); 68 if (term.length < 2) { 69 response([]); 70 return; 71 } 72 if (memoryCache[term]) { 73 response(memoryCache[term].slice(0)); 74 return; 75 } 76 if (activeRequest && activeRequest.readyState !== 4) activeRequest.abort(); 77 activeRequest = $.getJSON('/search_ai.php', { 78 smart_suggestions: 1, 79 suggestion_mode: 'term', 80 suggestion_term: term, 81 suggestion_lookup: lookupTerm(term) 82 }) 83 .done(function (items) { 84 items = $.isArray(items) ? normalizeAntaSuggestions(items) : []; 85 items = filterItems(items, term); 86 if (!$.grep(items, function (item) { return item.type === 'model_group'; }).length) { 87 items = items.slice(0, 15); 88 } 89 memoryCache[term] = items; 90 writeCache(memoryCache); 91 response(items); 92 }) 93 .fail(function (xhr, status) { 94 if (status !== 'abort') response([]); 95 }); 96 }, 97 select: function (event, ui) { 98 if (ui.item && ui.item.type === 'model_group') return false; 99 if (ui.item && ui.item.type === 'model_more' && ui.item.url) { 100 window.location.href = ui.item.url; 101 return false; 102 } 103 if (ui.item && ui.item.type === 'product' && ui.item.url) { 104 addRecentSearch(input.value || ui.item.value); 105 showSearchLoading(form); 106 openArticleSuggestion(ui.item, input.value || ui.item.value); 107 return false; 108 } 109 if (ui.item && ui.item.value) input.value = ui.item.value; 110 addRecentSearch(input.value); 111 showSearchLoading(form); 112 form.submit(); 113 return false; 114 } 115 }); 116 117 var autocomplete = $(input).data('ui-autocomplete'); 118 if (autocomplete) { 119 $(input).autocomplete('widget').addClass('smart-search-suggestions'); 120 autocomplete._renderItem = function (list, item) { 121 if (item.type === 'model_group') { 122 return $('<li>').addClass('ui-menu-item ui-state-disabled smart-search-model-group') 123 .append($('<div>').addClass('smart-search-model-group-title').text(item.value))
124 .appendTo(list); 125 } 126 if (item.type === 'model_more') { 127 return $('<li>').addClass('ui-menu-item smart-search-model-more') 128 .append($('<a>').addClass('suggestion ui-corner-all') 129 .attr('href', item.url).text(item.value)) 130 .appendTo(list); 131 } 132 if (item.type === 'product') return renderProductSuggestion(list, item, input.value); 133 var link = $('<a>').addClass('suggestion ui-corner-all'); 134 appendHighlightedText( 135 $('<span>').addClass('result').appendTo(link), 136 item.value || '', 137 input.value 138 ); 139 if (item.count !== undefined && item.count !== null && item.count !== '') { 140 $('<span>').addClass('result-count').text(item.count).appendTo(link); 141 } 142 return $('<li>').addClass('ui-menu-item').append(link).appendTo(list); 143 }; 144 } 145 bindSearchHistory(input, form); 146 }); 147 $(window).off('pageshow.aiSearchLoading').on('pageshow.aiSearchLoading', clearSearchLoading); 148 } 149 150 function mount2xuSearchCatalogLinks() { 151 if (!/\/search_ai\.php$/i.test(window.location.pathname || '')) return; 152 if (!document.querySelector('form.quick_find.two-xu-smart-search')) return; 153 var host = document.querySelector('.advanced_search_result .banner'); 154 if (!host || document.getElementById('smart-search-catalog-links') 155 || document.getElementById('two-xu-search-catalog-links')) return; 156 157 var productIds = []; 158 var seenProductIds = {}; 159 $('.product_small [data-products_id], .product_small [data-product-id]').each(function () { 160 var productId = parseInt(this.getAttribute('data-products_id') || this.getAttribute('data-product-id'), 10); 161 if (!productId || seenProductIds[productId]) return; 162 seenProductIds[productId] = true; 163 productIds.push(productId); 164 if (productIds.length >= 24) return false; 165 }); 166 if (!productIds.length) return; 167 168 var block = $('<div>') 169 .attr('id', 'two-xu-search-catalog-links') 170 .addClass('smart-search-catalog-links two-xu-search-catalog-links') 171 .attr('aria-live', 'polite') 172 .append($('<div>').addClass('smart-search-catalog-links-label').text('\u0412 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435:')); 173 var list = $('<div>').addClass('smart-search-catalog-links-list').appendTo(block); 174 for (var skeletonIndex = 0; skeletonIndex < 3; skeletonIndex++) { 175 $('<span>').addClass('smart-search-catalog-link-skeleton').appendTo(list); 176 } 177 block.appendTo(host); 178 179 var keywordMatch = (window.location.search || '').match(/(?:^|[?&])keywords=([^&]*)/i); 180 var searchQuery = ''; 181 if (keywordMatch && keywordMatch[1]) { 182 try { searchQuery = decodeURIComponent(keywordMatch[1].replace(/\+/g, ' ')); } 183 catch (error) { searchQuery = keywordMatch[1]; } 184 } 185 $.getJSON('/search_ai.php', { 186 search_catalog_links: 1, 187 catalog_product_ids: productIds.join(','), 188 catalog_query: searchQuery 189 }) 190 .done(function (payload) { 191 var links = payload && payload.ok && $.isArray(payload.links) ? payload.links : []; 192 list.empty(); 193 $.each(links, function (_, link) { 194 if (!link || !link.name || !link.url) return; 195 $('<a>') 196 .addClass('smart-search-catalog-link') 197 .attr('href', link.url) 198 .text(link.name) 199 .appendTo(list); 200 }); 201 if (!list.children().length) block.remove(); 202 }) 203 .fail(function () { block.remove(); }); 204 } 205 206 window.aiSearchShowLoading = showSearchLoading; 207 208 function removeLegacyHeaderHandler(element, eventName, functionName) { 209 if (!element || !$._data) return; 210 var events = $._data(element, 'events') || {}; 211 var handlers = events[eventName] || []; 212 var handlerToRemove = null; 213 214 $.each(handlers, function (_, eventHandler) { 215 var name = eventHandler && eventHandler.handler && eventHandler.handler.name 216 ? eventHandler.handler.name 217 : ''; 218 if (name.indexOf(functionName) !== -1) handlerToRemove = eventHandler.handler; 219 }); 220 if (!handlerToRemove && handlers.length) { 221 handlerToRemove = handlers[handlers.length - 1].handler; 222 } 223 if (handlerToRemove) $(element).off(eventName, handlerToRemove); 224 } 225 226 function patchSmartSearchListing() { 227 if (!window.listing || !window.listing.options || !$.fn.ajaxForm) return; 228 229 var originalResponseHandler = window.listing.options.formShowResponse; 230 if (typeof originalResponseHandler !== 'function' || originalResponseHandler.smartSearchPatched) return; 231 232 var form = $(window.listing.options.form || '#filtr-form'); 233 if (!form.length) return; 234 235 function clearListingLoading() { 236 form.removeClass('loading'); 237 $('.loadmore a').removeClass('loading'); 238 $('.catalog-products-count,.mobile-loading,.js-h1-wrapper,.js-loading-filters').removeClass('loading'); 239 window.listing.loading = false;
240 } 241 242 function responseHandler(responseText, statusText, additParam, jqForm) { 243 var productsList = []; 244 $.each(responseText && responseText.productsList ? responseText.productsList : [], function (_, product) { 245 if (!product) return; 246 if (parseInt(product.products_images_count, 10) > 0 && typeof product.products_bimage !== 'string') { 247 product.products_images_count = 0; 248 } 249 productsList.push(product); 250 }); 251 if (responseText) responseText.productsList = productsList; 252 form.attr('data-smart-search-response-products', productsList.length); 253 form.removeAttr('data-smart-search-listing-error'); 254 255 try { 256 return originalResponseHandler.call(this, responseText, statusText, additParam, jqForm); 257 } catch (error) { 258 form.attr('data-smart-search-listing-error', error && error.message ? error.message : 'render_error'); 259 if (window.console && typeof window.console.error === 'function') { 260 window.console.error('Smart search listing response failed', error); 261 } 262 } finally { 263 clearListingLoading(); 264 } 265 } 266 267 responseHandler.smartSearchPatched = true; 268 window.listing.options.formShowResponse = responseHandler; 269 form.attr('data-smart-search-listing-patched', '1'); 270 form.ajaxFormUnbind().ajaxForm({ 271 dataType: window.listing.options.formDataType, 272 beforeSubmit: window.listing.options.formShowRequest, 273 success: responseHandler, 274 error: function (xhr, statusText, error) { 275 form.attr('data-smart-search-listing-error', statusText || error || 'ajax_error'); 276 clearListingLoading(); 277 }, 278 timeout: Math.max(parseInt(window.listing.options.formTimeout, 10) || 0, 60000), 279 listing: window.listing 280 }); 281 } 282 283 function bindSearchHistory(input, form) { 284 var field = $(input); 285 field.off('.aiSearchHistory') 286 .on('focus.aiSearchHistory', function () { 287 if ($(form).hasClass('anta-search-discovery')) { 288 $('html').addClass('anta-mobile-search-open'); 289 } 290 showSearchDiscovery(input, form); 291 }) 292 .on('input.aiSearchHistory', function () { 293 var value = $.trim(input.value || ''); 294 var previousTimer = $(input).data('ai-search-term-timer'); 295 if (previousTimer) window.clearTimeout(previousTimer); 296 if (value === '') { 297 window.setTimeout(function () { 298 if ($.trim(input.value || '') === '') showSearchDiscovery(input, form); 299 }, 160); 300 } else { 301 hideSearchDiscovery(input); 302 if (discoveryRequest && discoveryRequest.readyState !== 4) { 303 discoveryRequest.abort(); 304 discoveryRequest = null; 305 } 306 if (value.length >= 2) { 307 $(input).data('ai-search-term-timer', window.setTimeout(function () { 308 if ($.trim(input.value || '') === value) { 309 $(input).autocomplete('search', value); 310 } 311 }, 0)); 312 } else { 313 $(input).autocomplete('close'); 314 } 315 } 316 }) 317 .on('keydown.aiSearchHistory', function (event) { 318 if (event.key === 'Escape' || event.keyCode === 27) hideSearchDiscovery(input); 319 }); 320 321 $(document).on('mousedown.aiSearchHistory', function (event) { 322 if (event.target !== input && !$.contains(form, event.target)) { 323 hideSearchDiscovery(input); 324 if ($(form).hasClass('js-navbar-form')) { 325 $(form).removeClass('focused'); 326 $('#filtersBlock').removeClass('low-z-index'); 327 input.blur(); 328 setSearchSuggestionsOpen(input, false); 329 } 330 } 331 }); 332 $(form).off('reset.aiSearchHistory').on('reset.aiSearchHistory', function () { 333 window.setTimeout(function () { 334 $(input).autocomplete('close'); 335 hideSearchDiscovery(input); 336 input.blur(); 337 setSearchSuggestionsOpen(input, false); 338 }, 0); 339 }); 340 } 341 342 function showSearchDiscovery(input, form) { 343 renderSearchDiscovery( 344 input, 345 form, 346 popularSuggestions, 347 popularProductSuggestions, 348 popularSuggestions === null 349 ); 350 if (discoveryRequest && discoveryRequest.readyState !== 4) return; 351 352 discoveryRequest = $.getJSON('/search_ai.php', { 353 smart_suggestions: 1, 354 suggestion_mode: 'discovery' 355 }) 356 .done(function (payload) { 357 popularSuggestions = payload && $.isArray(payload.popular) ? payload.popular : []; 358 popularProductSuggestions = payload && $.isArray(payload.products) ? payload.products : []; 359 if (shouldRefreshSearchDiscovery(input, form)) { 360 renderSearchDiscovery( 361 input, 362 form, 363 popularSuggestions, 364 popularProductSuggestions, 365 false 366 ); 367 } 368 }) 369 .fail(function () { 370 popularSuggestions = []; 371 popularProductSuggestions = []; 372 if (shouldRefreshSearchDiscovery(input, form)) { 373 renderSearchDiscovery(input, form, popularSuggestions, popularProductSuggestions, false); 374 } 375 }) 376 .always(function () { 377 discoveryRequest = null; 378 }); 379 } 380 381 function shouldRefreshSearchDiscovery(input, form) { 382 if ($.trim(input.value || '') !== '') return false;
383 if (document.activeElement === input) return true; 384 if (!$(form).hasClass('two-xu-smart-search')) return false; 385 return $(input).autocomplete('widget').attr('data-smart-search-discovery') === '1'; 386 } 387 388 function renderSearchDiscovery(input, form, popular, products, loading) { 389 var history = readRecentSearches(); 390 var list = $(input).autocomplete('widget'); 391 var splitDiscovery = $(form).hasClass('anta-search-discovery'); 392 var queryList = splitDiscovery 393 ? $('<ul>').addClass('smart-search-discovery-column smart-search-discovery-column--queries') 394 : list; 395 var productList = splitDiscovery 396 ? $('<ul>').addClass('smart-search-discovery-column smart-search-discovery-column--products') 397 : list; 398 var recentKeys = {}; 399 list.empty() 400 .removeAttr('data-smart-search-history') 401 .attr('data-smart-search-discovery', '1'); 402 403 if (history.length > 0) { 404 appendDiscoveryHeader(queryList, '\u0412\u044b \u0438\u0441\u043a\u0430\u043b\u0438', true, function () { 405 clearRecentSearches(); 406 renderSearchDiscovery( 407 input, 408 form, 409 popularSuggestions || [], 410 popularProductSuggestions || [], 411 false 412 ); 413 input.focus(); 414 }); 415 for (var i = history.length - 1; i >= 0; i--) { 416 var recentQuery = history[i]; 417 recentKeys[normalize(recentQuery)] = true; 418 appendDiscoveryItem(queryList, recentQuery, 'history', input, form, function (query) { 419 deleteRecentSearch(query); 420 renderSearchDiscovery( 421 input, 422 form, 423 popularSuggestions || [], 424 popularProductSuggestions || [], 425 false 426 ); 427 input.focus(); 428 }); 429 } 430 } 431 432 var popularItems = []; 433 if (!loading) { 434 $.each($.isArray(popular) ? popular : [], function (_, item) { 435 var query = item && item.value ? $.trim(String(item.value)) : ''; 436 if (!query || recentKeys[normalize(query)]) return; 437 popularItems.push(query); 438 return popularItems.length < 6; 439 }); 440 } 441 442 if (popularItems.length > 0) { 443 appendDiscoveryHeader( 444 queryList, 445 '\u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u044b', 446 false 447 ); 448 $.each(popularItems, function (_, query) { 449 appendDiscoveryItem(queryList, query, 'popular', input, form); 450 }); 451 } 452 453 var productItems = []; 454 if (!loading) { 455 $.each($.isArray(products) ? products : [], function (_, item) { 456 if (!item || item.type !== 'product' || !item.url) return; 457 productItems.push(item); 458 return productItems.length < 6; 459 }); 460 } 461 if (productItems.length > 0) { 462 appendDiscoveryHeader( 463 productList, 464 '\u041f\u043e\u043f\u0443\u043b\u044f\u0440\u043d\u044b\u0435 \u0442\u043e\u0432\u0430\u0440\u044b', 465 false 466 ); 467 $.each(productItems, function (_, item) { 468 appendDiscoveryProduct(productList, item, input, form); 469 }); 470 } 471 472 if (splitDiscovery && (queryList.children().length || productList.children().length)) { 473 var layout = $('<li>') 474 .addClass('smart-search-discovery-layout') 475 .attr('role', 'presentation'); 476 if (queryList.children().length) queryList.appendTo(layout); 477 if (productList.children().length) productList.appendTo(layout); 478 layout.toggleClass( 479 'has-two-columns', 480 queryList.children().length > 0 && productList.children().length > 0 481 ).appendTo(list); 482 } 483 484 if (!list.children().length) { 485 hideSearchDiscovery(input); 486 return; 487 } 488 489 updateSearchSuggestionsPosition(input, form); 490 list.css({ 491 display: 'block', 492 left: '0', 493 width: $(form).innerWidth() + 'px' 494 }); 495 setSearchSuggestionsOpen(input, true); 496 } 497 498 function updateSearchSuggestionsPosition(input, form) { 499 if (!input || !form || !input.getBoundingClientRect || !form.getBoundingClientRect) return; 500 var inputRect = input.getBoundingClientRect(); 501 var formRect = form.getBoundingClientRect(); 502 var relativeTop = Math.round(inputRect.bottom - formRect.top); 503 var relativeLeft = Math.max(0, Math.round(inputRect.left - formRect.left)); 504 if ($(form).hasClass('two-xu-smart-search') && window.innerWidth > 1023) { 505 relativeLeft = Math.max(0, relativeLeft - 10); 506 } 507 var isMobileAnta = $(form).hasClass('anta-search-discovery') && window.innerWidth <= 1023; 508 var top = isMobileAnta ? relativeTop : Math.max(0, relativeTop); 509 form.style.setProperty('--smart-search-suggestions-top', top + 'px'); 510 form.style.setProperty('--smart-search-suggestions-content-left', relativeLeft + 'px'); 511 form.style.setProperty('--smart-search-suggestions-viewport-top', Math.round(inputRect.bottom) + 'px'); 512 } 513 514 function appendDiscoveryHeader(list, title, canClear, clearCallback) { 515 var header = $('<li>').addClass('smart-search-discovery-header'); 516 $('<span>').addClass('smart-search-discovery-title').text(title).appendTo(header); 517 if (canClear) { 518 $('<button type="button">').addClass('smart-search-history-clear') 519 .text('\u041e\u0447\u0438\u0441\u0442\u0438\u0442\u044c') 520 .on('mousedown click', function (event) { 521 event.preventDefault(); 522 event.stopPropagation(); 523 if (event.type === 'click' && clearCallback) clearCallback(); 524 }).appendTo(header); 525 }
526 header.appendTo(list); 527 } 528 529 function appendDiscoveryItem(list, query, type, input, form, deleteCallback) { 530 var item = $('<li>').addClass('smart-search-discovery-item smart-search-discovery-' + type); 531 var button = $('<button type="button">').addClass('smart-search-discovery-query'); 532 button.append(buildDiscoveryIcon(type)); 533 $('<span>').addClass('smart-search-discovery-query-text').text(query).appendTo(button); 534 button.on('mousedown click', function (event) { 535 event.preventDefault(); 536 event.stopPropagation(); 537 if (event.type !== 'click') return; 538 input.value = query; 539 addRecentSearch(query); 540 hideSearchDiscovery(input); 541 showSearchLoading(form); 542 form.submit(); 543 }).appendTo(item); 544 if (type === 'history' && deleteCallback) { 545 $('<button type="button">').addClass('smart-search-history-delete') 546 .attr('aria-label', '\u0423\u0434\u0430\u043b\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441') 547 .attr('title', '\u0423\u0434\u0430\u043b\u0438\u0442\u044c') 548 .html('×') 549 .on('mousedown click', function (event) { 550 event.preventDefault(); 551 event.stopPropagation(); 552 if (event.type === 'click') deleteCallback(query); 553 }).appendTo(item); 554 } 555 item.appendTo(list); 556 } 557 558 function appendDiscoveryProduct(list, item, input, form) { 559 var row = renderProductSuggestion(list, item, ''); 560 row.addClass('smart-search-discovery-product'); 561 row.find('a').on('mousedown click', function (event) { 562 event.preventDefault(); 563 event.stopPropagation(); 564 if (event.type !== 'click') return; 565 addRecentSearch(item.value || item.title || ''); 566 hideSearchDiscovery(input); 567 showSearchLoading(form); 568 openArticleSuggestion(item, item.value || item.title || ''); 569 }); 570 } 571 572 function buildDiscoveryIcon(type) { 573 var icon = $('<span>').addClass('smart-search-discovery-icon').attr('aria-hidden', 'true'); 574 if (type === 'popular') { 575 icon.html('<svg viewBox="0 0 20 20" focusable="false"><path d="M3 14l4-4 3 3 6-7"/><path d="M12 6h4v4"/></svg>'); 576 } else { 577 icon.html('<svg viewBox="0 0 20 20" focusable="false"><circle cx="10" cy="10" r="7"/><path d="M10 6v4l3 2"/></svg>'); 578 } 579 return icon; 580 } 581 582 function hideSearchDiscovery(input) { 583 var list = $(input).autocomplete('widget'); 584 if (list.attr('data-smart-search-discovery') === '1' 585 || list.find('.smart-search-discovery-header,.smart-search-discovery-item,.smart-search-discovery-skeleton,.smart-search-discovery-empty').length) { 586 list.removeAttr('data-smart-search-discovery').empty().hide(); 587 setSearchSuggestionsOpen(input, false); 588 } 589 } 590 591 function setSearchSuggestionsOpen(input, isOpen) { 592 var form = $(input) 593 .attr('aria-expanded', isOpen ? 'true' : 'false') 594 .closest('form'); 595 form.toggleClass('has-smart-search-suggestions', Boolean(isOpen)); 596 form.closest('#header .middle').toggleClass('has-smart-search-layer', Boolean(isOpen)); 597 if (form.hasClass('anta-search-discovery')) { 598 $('html').toggleClass('anta-mobile-search-open', Boolean(isOpen) || form.hasClass('focused')); 599 } 600 } 601 602 function renderProductSuggestion(list, item, term) { 603 var link = $('<a>').addClass('suggestion smart-search-product-suggestion ui-corner-all'); 604 if (item.url) link.attr('href', item.url); 605 var visual = $('<span>').addClass('smart-search-product-suggestion-image'); 606 if (item.image) { 607 $('<img>').attr({ 608 src: item.image, 609 alt: item.title || item.value || '' 610 }).appendTo(visual); 611 } else { 612 visual.addClass('is-empty'); 613 } 614 visual.appendTo(link); 615 var information = $('<span>').addClass('smart-search-product-suggestion-info'); 616 if (item.value) { 617 $('<span>').addClass('smart-search-product-suggestion-article') 618 .text(item.value).appendTo(information); 619 } 620 appendHighlightedText( 621 $('<span>').addClass('smart-search-product-suggestion-title').appendTo(information), 622 item.title || item.value || '', 623 term 624 ); 625 var prices = $('<span>').addClass('smart-search-product-suggestion-prices'); 626 $('<span>').addClass('smart-search-product-suggestion-price') 627 .text(formatSuggestionPrice(item.price)).appendTo(prices); 628 if (parseFloat(item.old_price) > parseFloat(item.price)) { 629 $('<span>').addClass('smart-search-product-suggestion-old-price') 630 .text(formatSuggestionPrice(item.old_price)).appendTo(prices); 631 } 632 prices.appendTo(information);
633 information.appendTo(link); 634 return $('<li>').addClass('ui-menu-item smart-search-product-suggestion-item') 635 .append(link).appendTo(list); 636 } 637 638 function appendHighlightedText(container, text, term) { 639 text = String(text || ''); 640 term = $.trim(String(term || '')); 641 if (!term) { 642 container.text(text); 643 return container; 644 } 645 646 var normalizedText = text.toLocaleLowerCase(); 647 var normalizedTerm = term.toLocaleLowerCase(); 648 var start = normalizedText.indexOf(normalizedTerm); 649 if (start < 0) { 650 container.text(text); 651 return container; 652 } 653 654 if (start > 0) container.append(document.createTextNode(text.substring(0, start))); 655 $('<strong>').text(text.substr(start, term.length)).appendTo(container); 656 if (start + term.length < text.length) { 657 container.append(document.createTextNode(text.substring(start + term.length))); 658 } 659 return container; 660 } 661 662 function openArticleSuggestion(item, query) { 663 var targetUrl = item && item.url ? item.url : ''; 664 var productId = item && item.products_id ? parseInt(item.products_id, 10) : 0; 665 var navigated = false; 666 667 function navigate(searchId) { 668 if (navigated) return; 669 navigated = true; 670 if (searchId) targetUrl = addSearchIdToUrl(targetUrl, searchId); 671 window.location.href = targetUrl; 672 } 673 674 if (!targetUrl || !productId || !$.trim(query || '')) { 675 navigate(0); 676 return; 677 } 678 679 $.ajax({ 680 url: '/search_ai.php', 681 type: 'POST', 682 dataType: 'json', 683 timeout: 5000, 684 data: { 685 article_suggestion_click: 1, 686 query: $.trim(query), 687 products_id: productId 688 } 689 }).done(function (payload) { 690 var searchEvent = payload && payload.success && payload.event ? payload.event : null; 691 if (searchEvent) sendArticleSearchYandexGoals(searchEvent); 692 navigate(searchEvent && searchEvent.search_id ? searchEvent.search_id : 0); 693 }).fail(function () { 694 navigate(0); 695 }); 696 } 697 698 function addSearchIdToUrl(url, searchId) { 699 if (!url || !searchId || /(?:\?|&)sqid=/.test(url)) return url; 700 var hash = ''; 701 var hashPosition = url.indexOf('#'); 702 if (hashPosition >= 0) { 703 hash = url.substring(hashPosition); 704 url = url.substring(0, hashPosition); 705 } 706 return url + (url.indexOf('?') >= 0 ? '&' : '?') 707 + 'sqid=' + encodeURIComponent(searchId) + hash; 708 } 709 710 function sendArticleSearchYandexGoals(searchEvent) { 711 if (typeof window.ym !== 'function' || !window.PROSKTR || !PROSKTR.yaCounterId) return; 712 var payload = $.extend({}, searchEvent, { 713 results_count: 1, 714 position: 1 715 }); 716 window.ym(PROSKTR.yaCounterId, 'reachGoal', 'site_search', {search_funnel: payload}); 717 window.ym(PROSKTR.yaCounterId, 'reachGoal', 'search_product_click', {search_funnel: payload}); 718 } 719 720 function formatSuggestionPrice(value) { 721 var number = Math.round(parseFloat(value) || 0); 722 if (number <= 0) return ''; 723 return String(number).replace(/\B(?=(\d{3})+(?!\d))/g, ' ') + ' \u20bd'; 724 } 725 726 function readRecentSearches() { 727 var value = ''; 728 if (window.cookieObj && typeof window.cookieObj.getCookie === 'function') { 729 value = window.cookieObj.getCookie(recentSearchCookie) || ''; 730 } else { 731 var match = document.cookie.match(new RegExp('(?:^|; )' + recentSearchCookie + '=([^;]*)')); 732 if (match) { 733 try { value = decodeURIComponent(match[1]); } catch (error) { value = match[1]; } 734 } 735 } 736 if (!value || value === 'undefined') return []; 737 return $.grep(value.split(','), function (query) { 738 return $.trim(query || '') !== ''; 739 }); 740 } 741 742 function addRecentSearch(query) { 743 query = normalize(query); 744 if (query.length < 2) return; 745 var history = readRecentSearches(); 746 if ($.inArray(query, history) !== -1) return; 747 history.push(query); 748 writeRecentSearches(history); 749 } 750 751 function deleteRecentSearch(query) { 752 writeRecentSearches($.grep(readRecentSearches(), function (item) { 753 return item !== query; 754 })); 755 } 756 757 function clearRecentSearches() { 758 writeRecentSearches([]); 759 } 760 761 function writeRecentSearches(history) { 762 var value = history.join(','); 763 while (value.length > 200 && history.length) { 764 history.shift(); 765 value = history.join(','); 766 } 767 if (window.cookieObj && typeof window.cookieObj.deleteCookie === 'function') { 768 window.cookieObj.deleteCookie(recentSearchCookie);
769 if (value && typeof window.cookieObj.setCookie === 'function') { 770 window.cookieObj.setCookie(recentSearchCookie, value, { 771 expires: recentSearchCookieLifetime 772 }); 773 } 774 return; 775 } 776 document.cookie = recentSearchCookie + '=' + encodeURIComponent(value) 777 + '; path=/; SameSite=Lax; max-age=' 778 + (value ? recentSearchCookieLifetime : 0); 779 } 780 781 function showSearchLoading(form) { 782 if (!form || $(form).data('ai-search-loading')) return; 783 $(form).data('ai-search-loading', true).attr('aria-busy', 'true').addClass('is-search-loading'); 784 var input = $(form).find('input[name="keywords"]')[0]; 785 if (input) { 786 input.setAttribute('readonly', 'readonly'); 787 var controlsHost = input.parentNode; 788 if ($(form).hasClass('two-xu-smart-search') && controlsHost) { 789 $(controlsHost).addClass('smart-search-loading-controls'); 790 } 791 if ((' ' + form.className + ' ').indexOf(' smart-search-query-panel ') !== -1 792 && (!controlsHost || (' ' + controlsHost.className + ' ').indexOf(' smart-search-query-input-wrap ') === -1)) { 793 var inputWrap = document.createElement('div'); 794 inputWrap.className = 'smart-search-query-input-wrap'; 795 controlsHost.insertBefore(inputWrap, input); 796 inputWrap.appendChild(input); 797 controlsHost = inputWrap; 798 } 799 var cancel = form.querySelector('.smart-search-loading-cancel'); 800 if (!cancel) { 801 cancel = document.createElement('button'); 802 cancel.type = 'button'; 803 cancel.className = 'smart-search-loading-cancel'; 804 cancel.setAttribute('aria-label', '\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441'); 805 cancel.setAttribute('title', '\u041e\u0442\u043c\u0435\u043d\u0438\u0442\u044c \u043f\u043e\u0438\u0441\u043a \u0438 \u0438\u0437\u043c\u0435\u043d\u0438\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441'); 806 cancel.innerHTML = '×'; 807 cancel.onclick = function (event) { 808 event.preventDefault(); 809 event.stopPropagation(); 810 window.stop(); 811 clearSearchLoading(); 812 input.value = ''; 813 input.focus(); 814 }; 815 controlsHost.appendChild(cancel); 816 } 817 var loader = form.querySelector('.smart-search-input-loader'); 818 if (!loader) { 819 loader = document.createElement('span'); 820 loader.className = 'smart-search-input-loader'; 821 loader.setAttribute('aria-hidden', 'true'); 822 controlsHost.appendChild(loader); 823 } 824 } 825 try { $(input).autocomplete('close'); } catch (error) {} 826 827 var rightBlock = document.querySelector('.catalog-section-v2 .right-block'); 828 if (rightBlock && !rightBlock.querySelector('.smart-search-products-loader')) { 829 var productsLoader = document.createElement('div'); 830 productsLoader.className = 'smart-search-products-loader'; 831 productsLoader.setAttribute('role', 'status'); 832 productsLoader.setAttribute('aria-live', 'polite'); 833 productsLoader.innerHTML = '<span class="smart-search-loading-text">\u041f\u043e\u0434\u0431\u0438\u0440\u0430\u0435\u043c \u0442\u043e\u0432\u0430\u0440\u044b\u2026</span>' 834 + '<div class="smart-search-loading-toolbar"><i></i><i></i></div>' 835 + '<div class="smart-search-loading-grid">' 836 + '<i class="smart-search-loading-card"></i><i class="smart-search-loading-card"></i>' 837 + '<i class="smart-search-loading-card"></i><i class="smart-search-loading-card"></i>' 838 + '</div>'; 839 if (form.parentNode === rightBlock) rightBlock.insertBefore(productsLoader, form.nextSibling); 840 else rightBlock.insertBefore(productsLoader, rightBlock.firstChild); 841 } 842 $('html').addClass('smart-search-pending'); 843 } 844 845 function clearSearchLoading() { 846 $('html').removeClass('smart-search-pending'); 847 $('.smart-search-form, form.quick_find, form.home-smart-search').each(function () { 848 $(this).removeData('ai-search-loading').removeAttr('aria-busy').removeClass('is-search-loading'); 849 $(this).find('input[name="keywords"]').removeAttr('readonly'); 850 $(this).find('.smart-search-input-loader,.smart-search-loading-cancel').remove(); 851 $(this).find('.smart-search-loading-controls').removeClass('smart-search-loading-control
851s'); 852 }); 853 $('.smart-search-products-loader').remove(); 854 } 855 856 function mountLoadingStyles() { 857 if (loadingStylesMounted || document.getElementById('smart-search-pending-styles')) return; 858 loadingStylesMounted = true; 859 var style = document.createElement('style'); 860 style.id = 'smart-search-pending-styles'; 861 style.textContent = '' 862 + 'form.quick_find.kyocera-smart-search{overflow:visible!important;}' 863 + '#header .middle.has-smart-search-layer{z-index:1301!important;}' 864 + 'form.quick_find.kyocera-smart-search.has-smart-search-suggestions{border-color:#d9d9d9!important;border-top-left-radius:32px!important;border-top-right-radius:32px!important;border-bottom-left-radius:0!important;border-bottom-right-radius:0!important;}' 865 + 'html body form.quick_find.kyocera-smart-search.two-xu-smart-search.has-smart-search-suggestions{border-radius:0!important;}' 866 + 'form.quick_find.kyocera-smart-search.has-smart-search-suggestions input[name="keywords"]{background-color:transparent!important;}' 867 + '.smart-search-form.is-search-loading,form.quick_find.is-search-loading{position:relative;}' 868 + '.smart-search-query-input-wrap{position:relative;display:block;width:100%;}' 869 + '.smart-search-form.is-search-loading #smart-search-query,form.quick_find.is-search-loading input[name="keywords"]{padding-right:96px!important;}' 870 + '.smart-search-form.is-search-loading #smart-search-query::-webkit-search-cancel-button,form.quick_find.is-search-loading input[name="keywords"]::-webkit-search-cancel-button{display:none;}' 871 + 'form.quick_find.two-xu-smart-search.is-search-loading{position:absolute!important;top:100%!important;left:0!important;right:0!important;display:flex!important;visibility:visible!important;opacity:1!important;transform:translateY(0)!important;}' 872 + 'form.quick_find.two-xu-smart-search.is-search-loading .smart-search-loading-controls{position:relative;min-width:0;}' 873 + 'form.quick_find.two-xu-smart-search.is-search-loading>a.close{visibility:hidden!important;pointer-events:none!important;}' 874 + '.smart-search-input-loader{position:absolute;z-index:4;top:50%;right:56px;width:20px;height:20px;box-sizing:border-box;border:2px solid #bdbdbd;border-top-color:#171717;border-radius:50%;transform:translateY(-50%);animation:smart-search-loader-spin .7s linear infinite;pointer-events:none;}' 875 + '.smart-search-loading-cancel{position:absolute;z-index:6;top:50%;right:8px;display:flex;align-items:center;justify-content:center;width:34px;height:34px;margin:0;padding:0;border:0;border-radius:50%;background:transparent;color:#555;font:400 31px/34px Arial,sans-serif;transform:translateY(-50%);cursor:pointer;transition:background-color .15s ease,color .15s ease;}' 876 + '.smart-search-loading-cancel:hover,.smart-search-loading-cancel:focus{background:#ededed;color:#111;outline:none;}' 877 + 'form.quick_find.brd-smart-search.is-search-loading .input-group{background-color:#e9ecef!important;}' 878 + 'form.quick_find.brd-smart-search.is-search-loading .input-group-append{visibility:hidden!important;pointer-events:none!important;}' 879 + 'form.quick_find.brd-smart-search.is-search-loading .smart-search-input-loader{right:42px;}' 880 + 'form.quick_find.brd-smart-search.is-search-loading .smart-search-loading-cancel{right:0;visibility:visible!important;pointer-events:auto!important;}' 881 + 'form.quick_find.is-search-loading .reset{visibility:hidden!important;pointer-events:none!important;}' 882 + 'form.quick_find>.smart-search-suggestions,form.smart-search-form>.smart-search-suggestions,form.home-smart-search>.smart-search-suggestions{position:absolute!important;top:var(--smart-search-suggestions-top,100%)!important;left:0!important;right:auto!important;z-index:1200!important;box-sizing:border-box!important;width:100%!important;min-width:0!important;max-width:100%!important;max-height:480px;margin:0!important;padding:0!important;overflow-x:hidden;overflow-y:auto;list-style:none;background:#fff;border:1px solid #d9d9d9;border-top:0;border-radius:0 0 16px 16px;box-shadow:0 12px 22px rgba(0,0,0,.13);}' 883 + 'form.quick_find.two-xu-smart-search>.smart-search-suggestions{border-radius:0!important;}' 884 + '@media(min-width:1024px){form.quick_find.two-xu-smart-search>.smart-search-suggestions{left:0!important;width:100%!important;max-height:580px!important;}form.quick_find.two-xu-smart-search>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-layout{box-sizing:border-box;padding-left:var(--smart-search-suggestions-content-left,0px)!important;}}'
885 + '@media(max-width:1023px){html body form.quick_find.kyocera-smart-search.two-xu-smart-search.has-smart-search-suggestions{border-radius:0!important;border-top-left-radius:0!important;border-top-right-radius:0!important;border-bottom-right-radius:0!important;border-bottom-left-radius:0!important;}form.quick_find.two-xu-smart-search>.smart-search-suggestions{left:0!important;right:0!important;width:100%!important;max-width:none!important;border-radius:0!important;}}' 886 + 'form.quick_find>.smart-search-suggestions .ui-menu-item{box-sizing:border-box;width:100%;margin:0;padding:0;background:#fff;border:0;border-top:1px solid #e5e5e5;list-style:none;}' 887 + 'form.quick_find>.smart-search-suggestions .ui-menu-item.smart-search-product-suggestion-item{height:auto!important;min-height:0!important;}' 888 + 'form.quick_find>.smart-search-suggestions .ui-menu-item:first-child{border-top:0;}' 889 + 'form.quick_find>.smart-search-suggestions .ui-menu-item.smart-search-model-group{height:auto!important;background:#f5f5f5!important;color:#111!important;opacity:1!important;cursor:default!important;}' 890 + '.smart-search-model-group-title{box-sizing:border-box;padding:10px 14px;font-size:14px;font-weight:700;line-height:1.3;white-space:normal;}' 891 + 'form.quick_find>.smart-search-suggestions .suggestion{display:flex!important;align-items:center;justify-content:space-between;box-sizing:border-box;width:100%;min-height:44px;padding:10px 14px!important;color:#111!important;font-size:15px;text-decoration:none!important;}' 892 + 'form.quick_find>.smart-search-suggestions .smart-search-model-more .suggestion{justify-content:flex-start!important;color:#0a9bcd!important;font-size:14px;font-weight:600;}' 893 + 'form.quick_find>.smart-search-suggestions .suggestion:hover,form.quick_find>.smart-search-suggestions .suggestion.ui-state-focus{background:#f5f5f5!important;}' 894 + 'form.quick_find>.smart-search-suggestions .result{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}' 895 + 'form.quick_find>.smart-search-suggestions .result-count{flex:0 0 auto;margin-left:18px;color:#777;font-size:13px;}' 896 + '.smart-search-suggestions[data-smart-search-discovery="1"]{max-height:480px!important;}' 897 + '.advanced_search_result .banner>.two-xu-search-catalog-links{position:relative;z-index:51;align-self:center;box-sizing:border-box;width:calc(100% - 60px);max-width:1560px;margin:14px auto 0;padding:0;text-align:center;}' 898 + '.two-xu-search-catalog-links .smart-search-catalog-links-label{margin:0 0 8px;color:#111;font-size:15px;font-weight:400;line-height:1.3;text-align:center;}' 899 + '.two-xu-search-catalog-links .smart-search-catalog-links-list{display:flex;flex-wrap:wrap;align-items:center;justify-content:center;gap:8px;width:100%;margin:0;padding:0;}' 900 + '.two-xu-search-catalog-links .smart-search-catalog-link{display:inline-flex;align-items:center;min-height:34px;box-sizing:border-box;margin:0;padding:6px 12px;border:1px solid #dedede;border-radius:18px;background:#fff;color:#111;font-size:14px;line-height:20px;text-decoration:none;transition:background-color .15s ease,border-color .15s ease;}' 901 + '.two-xu-search-catalog-links .smart-search-catalog-link:hover,.two-xu-search-catalog-links .smart-search-catalog-link:focus{border-color:#bcbcbc;background:#f3f3f3;color:#111;outline:none;}' 902 + '.two-xu-search-catalog-links .smart-search-catalog-link-skeleton{display:block;width:150px;height:34px;border-radius:18px;background:#e5e5e5;animation:smart-search-loader-pulse 1.15s ease-in-out infinite;}' 903 + '.smart-search-discovery-header{display:flex;align-items:center;justify-content:space-between;gap:12px;box-sizing:border-box;width:100%;min-height:38px;margin:0;padding:10px 14px 7px;background:#fff;color:#111;font-size:14px;font-weight:700;}' 904 + '.smart-search-discovery-header:not(:first-child){border-top:1px solid #e5e5e5;}' 905 + '.smart-search-discovery-item{display:flex;align-items:center;box-sizing:border-box;width:100%;min-height:44px;margin:0;padding:0 8px 0 14px;background:#fff;color:#111;}' 906 + '.smart-search-discovery-item:hover{background:#f5f5f5;}' 907 + '.smart-search-discovery-query,.smart-search-history-clear,.smart-search-history-delete{margin:0;padding:0;border:0;background:transparent;color:#111;font:inherit;cursor:pointer;}' 908 + '.smart-search-discovery-query{display:flex;flex:1 1 auto;align-items:center;justify-content:flex-start!important;gap:10px;align-self:stretch;min-width:0;padding:9px 0;text-align:left!important;font-size:15px;}' 909 + '.smart-search-discovery-query-text{display:block;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}' 910 + '.smart-search-discovery-icon{display:flex;flex:0 0 20px;align-items:center;justify-content:center;width:20px;height:20px;color:#171717;}' 911 + '.smart-search-discovery-icon svg{display:block;width:18px;height:18px;fill:none;stroke:currentColor;stroke-width:1.6;stroke-linecap:round;stroke-linejoin:round;}' 912 + '.smart-search-discovery-popular .smart-search-discovery-icon{color:#aaa;}' 913 + '.smart-search-history-clear{flex:0 0 auto;color:#666;font-size:12px;text-decoration:underline;}' 914 + '.smart-search-history-delete{display:flex;flex:0 0 30px;align-items:center;justify-content:center;width:30px;height:30px;border-radius:50%;color:#888;font:400 22px/30px Arial,sans-serif;}' 915 + '.smart-search-discovery-query:hover,.smart-search-discovery-query:focus,.smart-search-history-clear:hover,.smart-search-history-clear:focus,.smart-search-history-delete:hover,.smart-search-history-delete:focus{color:#000;outline:none;}' 916 + '.smart-search-history-delete:hover,.smart-search-history-delete:focus{background:#e8e8e8;}' 917 + '.smart-search-discovery-skeleton{box-sizing:border-box;width:100%;height:42px;margin:0;padding:12px 14px;background:#fff;}' 918 + '.smart-search-discovery-skeleton i{display:block;width:55%;height:17px;border-radius:3px;background:linear-gradient(100deg,#ededed 20%,#f7f7f7 36%,#ededed 52%) 0 0/220% 100%;animation:smart-search-loader-shimmer 1.2s linear infinite;}' 919 + '.smart-search-discovery-empty{box-sizing:border-box;width:100%;padding:8px 14px 13px;background:#fff;color:#888;font-size:13px;}' 920 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-layout{display:block;box-sizing:border-box;width:100%;height:auto!important;margin:0!important;padding:0!important;border:0!important;background:#fff;list-style:none;}' 921 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-layout.has-two-columns{display:grid;grid-template-columns:minmax(250px,.75fr) minmax(0,2.25fr);align-items:start;}' 922 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column{box-sizing:border-box;min-width:0;width:100%;height:auto!important;margin:0;padding:0 0 10px;border:0!important;background:#fff;list-style:none;}' 923 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column>li{height:auto!important;margin:0!important;border:0!important;}' 924 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--queries .smart-search-discovery-header{justify-content:space-between;text-align:left;border:0!important;}' 925 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--queries .smart-search-discovery-item{justify-content:flex-start;text-align:left;border:0!important;}' 926 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-history .smart-search-history-delete{opacity:0;visibility:hidden;pointer-events:none;transition:opacity .15s ease;}' 927 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-history:hover,form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-history:focus-within{background:#f5f5f5;}' 928 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-history:hover .smart-search-history-delete,form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-history:focus-within .smart-search-history-delete{opacity:1;visibility:visible;pointer-events:auto;}' 929 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));align-content:start;gap:16px;padding:0 14px 16px;}' 930 + 'form.quick_find.two-xu-smart-search .smart-search-discovery-column--products,form.quick_find.two-xu-smart-search .smart-search-discovery-column--products>li{list-style:none!important;}' 931 + 'form.quick_find.two-xu-smart-search .smart-search-discovery-column--products>li::marker{content:"";}' 932 + 'form.quick_find.two-xu-smart-search .smart-search-suggestions li::before{content:none!important;display:none!important;}' 933 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products>.smart-search-discovery-header{grid-column:1/-1;text-align:left;border:0!important;}' 934 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products>.smart-search-product-suggestion-item{min-width:0;border:0!important;}' 935 + '.smart-search-product-suggestion-item{background:#fff;}' 936 + '.smart-search-suggestions .smart-search-product-suggestion{justify-content:flex-start!important;gap:14px;min-height:92px;padding:8px 14px!important;}' 937 + '.smart-search-product-suggestion-image{display:flex;flex:0 0 72px;align-items:center;justify-content:center;width:72px;height:78px;overflow:hidden;background:#f3f3f3;}' 938 + '.smart-search-product-suggestion-image img{display:block;width:100%;height:100%;object-fit:contain;}' 939 + '.smart-search-product-suggestion-image.is-empty:after{content:"";display:block;width:28px;height:20px;border:1px solid #bbb;}' 940 + '.smart-search-product-suggestion-info{display:flex;flex:1 1 auto;flex-direction:column;align-items:flex-start;justify-content:center;min-width:0;}' 941 + '.smart-search-product-suggestion-article{display:block;max-width:100%;margin:0 0 3px;overflow:hidden;color:#8b8b8b;font-size:12px;font-weight:400;line-height:1.2;text-overflow:ellipsis;white-space:nowrap;}' 942 + '.smart-search-product-suggestion-title{display:block;max-width:100%;overflow:hidden;color:#111;font-size:15px;font-weight:500;line-height:1.3;text-overflow:ellipsis;white-space:nowrap;}' 943 + '.smart-search-product-suggestion-title strong,.smart-search-suggestions .result strong{font-weight:800;}' 944 + '.smart-search-product-suggestion-prices{display:flex;align-items:baseline;gap:8px;margin-top:6px;line-height:1.2;}' 945 + '.smart-search-product-suggestion-price{display:block;color:#111;font-size:14px;font-weight:700;}' 946 + '.smart-search-product-suggestion-old-price{display:block;color:#8b8b8b;font-size:12px;font-weight:400;text-decoration:line-through;}' 947 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion{dis
947play:flex!important;flex-direction:column;align-items:stretch;justify-content:flex-start!important;gap:0;min-height:0;padding:0!important;background:#fff;}' 948 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion-image{display:flex;flex:0 0 auto;width:100%;height:auto;aspect-ratio:2/3;background:#f3f3f3;}' 949 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion-info{box-sizing:border-box;width:100%;padding:10px 4px 2px;}' 950 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion-article{display:none;}' 951 + 'form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion-title{display:-webkit-box;overflow:hidden;white-space:normal;-webkit-box-orient:vertical;-webkit-line-clamp:2;}' 952 + '.smart-search-products-loader{display:none;box-sizing:border-box;width:100%;min-height:570px;padding-top:2px;}' 953 + 'html.smart-search-pending .catalog-section-v2 .right-block>*:not(.smart-search-query-panel):not(.smart-search-products-loader){display:none!important;}' 954 + 'html.smart-search-pending .smart-search-products-loader{display:block;}' 955 + '.smart-search-loading-text{position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;}' 956 + '.smart-search-loading-toolbar{display:flex;align-items:center;gap:18px;height:34px;margin:0 0 10px;}' 957 + '.smart-search-loading-toolbar i{display:block;width:86px;height:18px;border-radius:3px;background:#e5e5e5;animation:smart-search-loader-pulse 1.15s ease-in-out infinite;}' 958 + '.smart-search-loading-toolbar i+ i{width:120px;}' 959 + '.smart-search-loading-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:24px;}' 960 + '.smart-search-loading-card{display:block;min-width:0;height:520px;background:linear-gradient(100deg,#ededed 20%,#f7f7f7 36%,#ededed 52%) 0 0/220% 100%;animation:smart-search-loader-shimmer 1.2s linear infinite;}' 961 + '@keyframes smart-search-loader-spin{to{transform:translateY(-50%) rotate(360deg)}}' 962 + '@keyframes smart-search-loader-pulse{0%,100%{opacity:.55}50%{opacity:1}}' 963 + '@keyframes smart-search-loader-shimmer{to{background-position:-220% 0}}' 964 + '@media(max-width:1023px){html.anta-mobile-search-open,html.anta-mobile-search-open body{overflow:hidden!important}html.anta-mobile-search-open body:before{content:"";position:fixed;inset:0;z-index:149;background:#fff}form.anta-search-discovery>.smart-search-suggestions{left:15px!important;right:15px!important;width:auto!important;max-width:none!important;max-height:calc(100vh - var(--smart-search-suggestions-viewport-top,55px))!important}form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-layout.has-two-columns{display:block}form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products{grid-template-columns:1fr;gap:0;padding:0 0 10px}form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion{flex-direction:row;align-items:center;gap:10px;min-height:82px;padding:7px 10px!important}form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion-image{flex:0 0 62px;width:62px;height:68px;aspect-ratio:auto}form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-column--products .smart-search-product-suggestion-info{width:auto;padding:0}form.anta-search-discovery>.smart-search-suggestions[data-smart-search-discovery="1"] .smart-search-discovery-history .smart-search-history-delete{opacity:1;visibility:visible;pointer-events:auto}}' 965 + '@media(max-width:991px){.smart-search-loading-grid{grid-template-columns:repeat(2,minmax(0,1fr));gap:12px}.smart-search-loading-card{height:430px}.smart-search-products-loader{min-height:480px}}' 966 + '@media(max-width:767px){.smart-search-input-loader{right:51px;width:18px;height:18px}.smart-search-loading-cancel{right:6px;width:32px;height:32px;font-size:29px;line-height:32px}.smart-search-discovery-header{padding-left:10px;padding-right:10px}.smart-search-discovery-item{padding-left:10px;padding-right:5px}.smart-search-discovery-query{font-size:14px}.smart-search-history-clear{font-size:12px}.smart-search-suggestions .smart-search-product-suggestion{gap:10px;min-height:82px;padding:7px 10px!important}.smart-search-product-suggestion-image{flex-basis:62px;width:62px;height:68px}.smart-search-product-suggestion-title{font-size:14px}.smart-search-product-suggestion-price{font-size:13px}.smart-search-product-suggestion-old-price{font-size:11px}.advanced_search_result .banner>.two-xu-search-catalog-links{width:calc(100% - 30px);margin-top:12px}.two-xu-search-catalog-links .smart-search-catalog-links-label{font-size:14px}.two-xu-search-catalog-links .smart-search-catalog-links-list{gap:6px}.two-xu-search-catalog-links .smart-search-catalog-link{min-height:32px;padding:5px 10px;font-size:13px}.two-xu-search-catalog-links .smart-search-catalog-link-skeleton{height:32px}.smart-search-products-loader{padding-top:0}.smart-search-loading-toolbar{height:30px;margin-bottom:8px}.smart-search-loading-grid{gap:8px}.smart-search-loading-card{height:360px}}' 967 + '@media(prefers-reduced-motion:reduce){.smart-search-input-loader,.smart-search-loading-toolbar i,.smart-search-loading-card{animation:none}}'; 968 document.head.appendChild(style); 969 } 970 971 function normalize(value) { 972 return $.trim((value || '').toLowerCase().replace(/\s+/g, ' ')); 973 } 974 975 function normalizeAntaSuggestions(items) { 976 var result = []; 977 var indexes = {}; 978 var hasModelGroups = $.grep(items, function (item) { 979 return item && item.type === 'model_group'; 980 }).length > 0; 981 982 $.each(items, function (_, item) { 983 if (!item || !item.value) return; 984
985 var value = String(item.value) 986 .replace(/(^|[^a-z0-9\u0430-\u044f\u0451])anta(?=$|[^a-z0-9\u0430-\u044f\u0451])/ig, '$1') 987 .replace(/\s+/g, ' '); 988 if (/<\s*\/?\s*[a-z][^>]*>|<\s*\/?\s*[a-z][^&]*>/i.test(value)) return; 989 990 value = $.trim(value).replace(/^[\s,.;:\/|()[\]{}+\-]+|[\s,.;:\/|()[\]{}+\-]+$/g, ''); 991 if (!value) return; 992 993 var key = hasModelGroups && item.type === 'model_more' && item.anchor 994 ? '$model-more:' + item.anchor 995 : hasModelGroups && item.type === 'product' && item.products_id 996 ? '$product:' + item.products_id 997 : '$' + normalize(value); 998 var count = parseInt(item.count, 10); 999 1000 if (indexes[key] !== undefined) { 1001 if (!isNaN(count)) { 1002 var previousCount = parseInt(result[indexes[key]].count, 10); 1003 result[indexes[key]].count = (isNaN(previousCount) ? 0 : previousCount) + count; 1004 } 1005 return; 1006 } 1007 1008 indexes[key] = result.length; 1009 result.push($.extend({}, item, {value: value})); 1010 }); 1011 1012 if (!hasModelGroups) { 1013 result.sort(function (first, second) { 1014 if (first.type === 'product' && second.type !== 'product') return -1; 1015 if (second.type === 'product' && first.type !== 'product') return 1; 1016 return (parseInt(second.count, 10) || 0) - (parseInt(first.count, 10) || 0); 1017 }); 1018 } 1019 1020 return result; 1021 } 1022 1023 function lookupTerm(term) { 1024 var tokens = term.split(' '); 1025 var stopWords = ' \u0434\u043e \u043e\u0442 \u0434\u043b\u044f \u043d\u0430 \u0438 \u0432 \u0432\u043e \u0441 \u0441\u043e \u043f\u043e \u0438\u0437 \u043f\u043e\u0434 \u043d\u0430\u0434 \u0431\u0435\u0437 \u043f\u0440\u0438 \u043a \u043a\u043e'.split(' '); 1026 for (var i = tokens.length - 1; i >= 0; i--) { 1027 var token = tokens[i]; 1028 if (token.length < 2 || /^\d+(?:[.,]\d+)?[\u043ak]?$/.test(token)) continue; 1029 if ($.inArray(token, stopWords) !== -1) continue; 1030 return token; 1031 } 1032 return term; 1033 } 1034 1035 function filterItems(items, term) { 1036 var tokens = term.split(' '); 1037 var matched = $.grep(items, function (item) { 1038 if (item && (item.type === 'product' || item.type === 'model_more')) return true; 1039 var value = normalize(item && item.value ? item.value : ''); 1040 for (var i = 0; i < tokens.length; i++) { 1041 if (tokens[i].length > 1 && value.indexOf(tokens[i]) === -1) return false; 1042 } 1043 return true; 1044 }); 1045 return matched.length ? matched : items; 1046 } 1047 1048 function readCache() { 1049 try { 1050 var value = window.sessionStorage.getItem(storageKey); 1051 return value ? JSON.parse(value) : {}; 1052 } catch (error) { 1053 return {}; 1054 } 1055 } 1056 1057 function writeCache(cache) { 1058 try { 1059 var keys = Object.keys(cache); 1060 while (keys.length > 50) delete cache[keys.shift()]; 1061 window.sessionStorage.setItem(storageKey, JSON.stringify(cache)); 1062 } catch (error) {} 1063 } 1064 1065})(window.jQuery, window);
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.