1$('document').ready(function(){function CatalogSearch(){let url='';let searchStringParam='search_string';let perPageParam='per_page';let searchResults={};let $element=null;let $searchForm=null;let $templateElement=null;let $resultElement=null;let allResultButtonSelector='#search-results-show-btn';let maxResultsCount=15;let template=null;let beforeCloseInterval=200;init();function init(){let formSelector='#search-form';$searchForm=$(formSelector);url='/udata:/'+$searchForm.data('action')+'.json' 2$element=$searchForm.find('input[name=search_string]');$templateElement=$('#search-result-template');$resultElement=$('.search-content',$searchForm.parent());$resultElement.hide();if(!$searchForm.length||!$element.length||!$templateElement.length){return;} 3template=_.template($templateElement.html());$element.on('input',function(){let searchString=$element.val();search(searchString,function(response){if(!isValidResult(response)){return;} 4onSearchResult(searchString,response['items']);});});$element.on('blur',function(){setTimeout(function(){$resultElement.html('');$resultElement.hide();},beforeCloseInterval);});} 5function onSearchResult(searchString,result){saveResult(searchString,result);$resultElement.html('');let data=processResult(result);if(!data.length){$resultElement.hide();return;} 6let resultHtml=template({typesList:data});$resultElement.html(resultHtml);$resultElement.show();let list=document.querySelectorAll('.search-results__item');list.forEach((item,index)=>{$.getJSON(result.item[index].href,(data)=>{let oldPrice='';let currentPrice='';let href='';let vendor='';let id=data.page.id;let groups=data.page.properties.group;Object.keys(groups).forEach((key)=>{if(groups[key].name==='cenovye_svojstva'){let prices=groups[key].property;Object.keys(prices).forEach((key)=>{if(prices[key].name==='old_price'){oldPrice=parseInt(prices[key].value.value);}else if(prices[key].name==='price'){currentPrice=parseInt(prices[key].value.value);}});}else if(groups[key].name==='opisanie_tovara'){Object.keys(groups[key].property).forEach((sKey)=>{if(groups[key].property[sKey].name==='photo'){href=groups[key].property[sKey].value.path;}});}else if(groups[key].name==='general_info'){Object.keys(groups[key].property).forEach((sKey)=>{if(groups[key].property[sKey].name==='article'){vendor=groups[key].property[sKey].value.value;}});}});$.getJSON('/udata://emarket/price/'+id+'.json',(data)=>{if(data.discount!==undefined&&data.discount!==''){oldPrice=currentPrice;currentPrice=data.price.actual?parseInt(data.price.actual):0;} 7if(oldPrice!==0&&oldPrice!==''&&oldPrice!==undefined){$(item.querySelector('.search-results-item-price__old')).text(oldPrice.toLocaleString('ru-RU')+' ÑÑб. ');} 8if(currentPrice>0)$(item.querySelector('.search-results-item-price__new')).text(currentPrice.toLocaleString('ru-RU')+' ÑÑб. ');});
8$.getJSON('/udata://system/makeThumbnail/('+href+')/80/auto.json',(data)=>{let img=document.createElement('img');img.setAttribute('src',data.filepath.slice(1));img.classList.add('search-results-item-img');$(item.querySelector('.search-results-item-img-wrapper')).empty() 9item.querySelector('.search-results-item-img-wrapper').appendChild(img);});$(item).find('.search-results-item-content__article span').text(vendor);});});$(allResultButtonSelector).on('click',function(e){e.preventDefault();$searchForm.submit();});} 10function processResult(result){let items=result['item'];if(!items){return[];} 11return getDataByCategories(items);function getDataByCategories(items){let data=$.extend(true,{},items);let typesList=[];let type=null;_.each(data,function(element){type=element['type'];if(!type){type={id:0,name:''};} 12if(type.module==='СÑÑÑкÑÑÑа'){type.module='СÑÑаниÑÑ';} 13let addedType=_.findWhere(typesList,{id:type.id});if(!addedType){typesList.push(type);} 14type=addedType||type;type['elements']=type['elements']||[];type['elements'].push(element);});return typesList;}} 15function isValidResult(data){data=data||{};return!!data['items'];} 16function getHash(str){let hash=0;if(str.length===0){return hash;} 17let char='';for(let i=0;i<str.length;i++){char=str.charCodeAt(i);hash=((hash<<5)-hash)+char;hash=hash&hash;} 18return hash;} 19function saveResult(searchString,result){if(searchString){searchResults[getHash(searchString)]=result;}} 20function search(string,callback){if(!string){return;} 21callback=typeof callback==='function'?callback:function(){};let request={};request[searchStringParam]=string;request[perPageParam]=maxResultsCount;let possibleResult=searchResults[getHash(string)];if(typeof possibleResult!=='undefined'){return onSearchResult(string,possibleResult);} 22$.ajax({url:url,type:'get',dataType:'json',data:request,success:callback});}} 23let catalogSearch=new CatalogSearch;});
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.