PageSourceSearch

https://odin.ru/jscript/search-suggest/search-suggest.js?v=1.2.0

js odin.ru collected 2026-10-02 06:04:51 UTC 15,731 bytes, 2 lines download raw bytes

1!function(t,e){"use strict";if(!t.SearchSuggest){var i=["input[data-suggest]",'form[action*="/main/search.asp"] input[name="q"]','form[role="search"] input[name="q"]','.search-form input[name="q"]'].join(","),s={url:"/main/suggest.asp",src:"",minChars:2,delay:250,submitItem:!0,anchor:null},n=e.currentScript,o=t.SearchSuggestCss||(n&&n.src?n.src.replace(/search-suggest(?:\.src)?\.js(\?.*)?$/,"search-suggest.css$1"):"/jscript/search-suggest/search-suggest.css"),r=0,a=!1,h=new Map,u=new WeakMap,c=0;g.prototype.build=function(){var t=this.input;this.listId=l("list"),this.hintId=l("hint"),this.hint=p("span","Подсказки появятся при наборе. Выбор — стрелками вверх и вниз, Enter — перейти, Escape — закрыть."),this.hint.id=this.hintId,this.status=p("span"),this.status.setAttribute("role","status"),this.status.setAttribute("aria-live","polite"),this.popup=d("div","ss-popup"),this.popup.hidden=!0,this.notice=d("div","ss-notice"),this.notice.hidden=!0,this.list=d("div","ss-list"),this.list.id=this.listId,this.list.setAttribute("role","listbox"),this.list.setAttribute("aria-label","Подсказки поиска"),this.empty=d("div","ss-empty"),this.empty.hidden=!0,this.popup.appendChild(this.notice),this.popup.appendChild(this.list),this.popup.appendChild(this.empty),e.body.appendChild(this.popup),e.body.appendChild(this.hint),e.body.appendChild(this.status),t.setAttribute("role","combobox"),t.setAttribute("aria-autocomplete","list"),t.setAttribute("aria-haspopup","listbox"),t.setAttribute("aria-expanded","false"),t.setAttribute("aria-controls",this.listId),t.setAttribute("autocomplete","off"),t.hasAttribute("enterkeyhint")||t.setAttribute("enterkeyhint","search");var i=t.getAttribute("aria-describedby");t.setAttribute("aria-describedby",(i?i+" ":"")+this.hintId),t.hasAttribute("aria-label")||t.hasAttribute("aria-labelledby")||t.labels&&t.labels.length||t.setAttribute("aria-label",t.getAttribute("placeholder")||"Поиск по сайту"),t.classList.add("ss-input")},g.prototype.bind=function(){var i=this,s=this.input;s.addEventListener("input",(function(){i.composing||i.schedule()})),s.addEventListener("compositionstart",(function(){i.composing=!0})),s.addEventListener("compositionend",(function(){i.composing=!1,i.schedule()})),s.addEventListener("keydown",(function(t){i.onKeydown(t)})),s.addEventListener("focus",(function(){i.lastData&&i.lastQuery===i.value()&&i.render(i.lastData,i.lastQuery)})),s.addEventListener("blur",(function(){t.setTimeout((function(){e.activeElement!==s&&i.close()}),120)})),this.popup.addEventListener("mousedown",(function(t){t.preventDefault()})),this.list.addEventListener("click",(function(t){var e=t.target.closest?t.target.closest('[role="option"]'):null;if(e){var s=i.indexOf(e);s>-1&&i.choose(s)}})),this.list.addEventListener("pointermove",(function(t){var e=t.target.closest?t.target.closest('[role="option"]'):null;if(e){var s=i.indexOf(e);s>-1&&s!==i.active&&i.setActive(s,!1)}})),this.onViewport=function(){i.isOpen&&i.position()},t.addEventListener("resize",this.onViewport),t.addEventListener("scroll",this.onViewport,!0),this.form&&this.form.addEventListener("submit",(function(){i.close(),i.abort()}))},g.prototype.value=function(){return this.input.value.replace(/\s+/g," ").trim()},g.prototype.indexOf=function(t){for(var e=0;e<this.options.length;e++)if(this.options[e].node===t)return e;return-1},g.prototype.schedule=function(){var e=this,i=this.value();if(t.clearTimeout(this.timer),i.length<this.o.minChars||0===m(i).length)return this.abort(),this.close(),this.lastQuery=null,void(this.lastData=null);var s=function(t){if(!h.has(t))return null;var e=h.get(t);return h.delete(t),h.set(t,e),e}(this.cacheKey(i));return s?(this.abort(),this.lastQuery=i,this.lastData=s,void this.render(s,i)):Date.now()<c?(this.abort(),void this.close()):void(this.timer=t.setTimeout((function(){e.fetch(i)}),this.o.delay))},g.prototype.cacheKey=function(t){return this.o.url+"|"+this.o.src+"|"+this.o.ctx+"|"+f(t)},g.prototype.abort=function(){this.ctrl&&(this.ctrl.abort(),this.ctrl=null),this.list.removeAttribute("aria-busy")},g.prototype.fetch=function(i){var s=this;this.abort();var n="function"==typeof AbortController?new AbortController:null;this.ctrl=n,this.list.setAttribute("aria-busy","true");var o=this.o.url+(this.o.url.indexOf("?")>-1?"&":"?")+"q="+encodeURIComponent(i);this.o.src&&(o+="&src="+encodeURIComponent(this.o.src)),this.o.ctx&&(o+="&ctx="+encodeURIComponent(this.o.ctx)),t.fetch(o,{method:"GET",credentials:"same-origin",headers:{"X-Requested-With":"XMLHttpRequest",Accept:"application/json"},signal:n?n.signal:void 0}).then((function(t){if(429===t.status||503===t.status){var e=parseInt(t.headers.get("Retry-After"),10);e>0||(e=5),c=Date.now()+1e3*Math.min(e,60)}if(!t.ok)throw new Error("HTTP "+t.status);return t.json()})).then((function(t){var o,r;s.ctrl===n&&(s.ctrl=null,s.list.removeAttribute("aria-busy"),t=function(t){var e={fixed:"",groups:[]};if(!t||"object"!=typeof t)return e;"string"==typeof t.fixed&&(e.fixed=t.fixed.slice(0,200));
1return Array.isArray(t.groups)?(t.groups.slice(0,6).forEach((function(t){if(t&&Array.isArray(t.items)){var i=[];t.items.slice(0,10).forEach((function(t){if(t&&"string"==typeof t.title&&t.title){var e={};t.data&&"object"==typeof t.data&&Object.keys(t.data).slice(0,20).forEach((function(i){!/^[a-z][a-z0-9_]{0,30}$/.test(i)||"string"!=typeof t.data[i]&&"number"!=typeof t.data[i]||(e[i]=String(t.data[i]))})),i.push({title:t.title.slice(0,300),url:v(t.url),img:v(t.img),descr:"string"==typeof t.descr?t.descr.slice(0,200):"",kind:"string"==typeof t.kind?t.kind.slice(0,60):"",data:e})}})),i.length&&e.groups.push({code:"string"==typeof t.code?t.code:"",name:"string"==typeof t.name?t.name.slice(0,60):"",items:i})}})),e):e}(t),o=s.cacheKey(i),r=t,h.set(o,r),h.size>60&&h.delete(h.keys().next().value),i===s.value()&&(s.lastQuery=i,s.lastData=t,e.activeElement===s.input&&s.render(t,i)))})).catch((function(t){t&&"AbortError"===t.name||s.ctrl===n&&(s.ctrl=null,s.list.removeAttribute("aria-busy"),e.activeElement===s.input&&s.renderError(i))}))},g.prototype.render=function(t,e){var i,s,n,o,r,a,h=this,u=m(t.fixed||e),c=0;if(this.list.textContent="",this.options=[],this.active=-1,this.input.removeAttribute("aria-activedescendant"),t.fixed?(this.notice.textContent="Показаны подсказки для «"+t.fixed+"»",this.notice.hidden=!1):this.notice.hidden=!0,t.groups.forEach((function(t){var e=d("div","ss-group"),i=l("group");if(e.setAttribute("role","group"),t.name){var s=d("div","ss-group__title",t.name);s.id=i,s.setAttribute("role","presentation"),e.appendChild(s),e.setAttribute("aria-labelledby",i)}t.items.forEach((function(i){var s=h.createOption(i,u);e.appendChild(s),h.options.push({node:s,item:i,group:{code:t.code,name:t.name},kind:"item"}),c+=1})),h.list.appendChild(e)})),this.o.submitItem&&(this.form||c)){var p=d("div","ss-option ss-option--search");p.id=l("opt"),p.setAttribute("role","option"),p.setAttribute("aria-selected","false"),p.appendChild(d("span","ss-option__title","Найти «"+e+"»")),p.appendChild(d("span","ss-option__meta",this.isSiteSearch()?"по всему сайту":"в этом разделе")),this.list.appendChild(p),this.options.push({node:p,item:{title:e},group:null,kind:"search"})}0===c?(this.empty.textContent="Подсказок нет. Нажмите Enter, чтобы искать по сайту.",this.empty.hidden=!1,this.announce("Подсказок нет")):(this.empty.hidden=!0,this.announce(c+" "+(s="подсказка",n="подсказки",o="подсказок",a=(i=c)%100,(1===(r=i%10)&&11!==a?s:r>=2&&r<=4&&(a<12||a>14)?n:o)+". Выбор — стрелками вверх и вниз."))),this.open()},g.prototype.renderError=function(){this.list.textContent="",this.options=[],this.active=-1,this.notice.hidden=!0,this.close()},g.prototype.createOption=function(t,i){var s=d("div","ss-option");if(s.id=l("opt"),s.setAttribute("role","option"),s.setAttribute("aria-selected","false"),t.img){var n=d("img","ss-option__img");n.alt="",n.loading="lazy",n.decoding="async",n.width=48,n.height=48,n.src=t.img,n.onerror=function(){n.parentNode&&n.parentNode.removeChild(n)},s.appendChild(n),s.classList.add("ss-option--img")}var o=d("span","ss-option__title");o.appendChild(function(t,i){var s=e.createDocumentFragment(),n=f(t),o=[];i.forEach((function(t){if(t)for(var e,i,s=0;-1!==(e=n.indexOf(t,s));)0!==e&&(i=n.charAt(e-1),/[0-9a-zа-яё]/i.test(i))||o.push([e,e+t.length]),s=e+t.length})),o.sort((function(t,e){return t[0]-e[0]}));var r=[];o.forEach((function(t){var e=r[r.length-1];e&&t[0]<=e[1]?e[1]=Math.max(e[1],t[1]):r.push([t[0],t[1]])}));var a=0;return r.forEach((function(i){i[0]>a&&s.appendChild(e.createTextNode(t.slice(a,i[0]))),s.appendChild(d("mark","ss-mark",t.slice(i[0],i[1]))),a=i[1]})),a<t.length&&s.appendChild(e.createTextNode(t.slice(a))),s}(t.title,i)),s.appendChild(o);
1var r=[t.kind,t.descr].filter(Boolean).join(" · ");return r&&s.appendChild(d("span","ss-option__meta",r)),t.url&&s.classList.add("ss-option--link"),s},g.prototype.isSiteSearch=function(){var t=this.form&&this.form.getAttribute("action")||"";return!this.form||/\/main\/search\.asp/i.test(t)},g.prototype.announce=function(e){var i=this.status;t.clearTimeout(this.announceTimer),this.announceTimer=t.setTimeout((function(){i.textContent=e}),400)},g.prototype.open=function(){this.options.length||!this.empty.hidden?(this.popup.hidden=!1,this.isOpen=!0,this.input.setAttribute("aria-expanded","true"),this.position()):this.close()},g.prototype.close=function(){this.isOpen&&(this.popup.hidden=!0,this.isOpen=!1,this.active=-1,this.input.setAttribute("aria-expanded","false"),this.input.removeAttribute("aria-activedescendant"))},g.prototype.anchorElement=function(){var t=null;if(this.o.anchor)try{t=e.querySelector(this.o.anchor)}catch(e){t=null}return t||this.input.closest(".btn-group, .input-group, .search-form__panel")||this.input},g.prototype.position=function(){var i=this.anchorElement().getBoundingClientRect(),s=this.input.getBoundingClientRect();if(s.width||s.height){var n=e.documentElement.clientWidth,o=t.innerHe
1ight,r=Math.min(Math.max(i.width,280),n-16),a=Math.min(Math.max(i.left,8),n-r-8),h=o-i.bottom-4-8,u=i.top-4-8,c=this.popup.style;c.fontSize=t.getComputedStyle(this.input).fontSize,c.left=a+"px",c.width=r+"px",h<200&&u>h?(c.top="",c.bottom=o-i.top+4+"px",c.maxHeight=Math.min(u,480)+"px",this.popup.classList.add("ss-popup--above")):(c.bottom="",c.top=i.bottom+4+"px",c.maxHeight=Math.min(h,480)+"px",this.popup.classList.remove("ss-popup--above"))}else this.close()},g.prototype.setActive=function(t,e){if(this.active>-1&&this.options[this.active]&&(this.options[this.active].node.setAttribute("aria-selected","false"),this.options[this.active].node.classList.remove("ss-option--active")),this.active=t,t<0||!this.options[t])this.input.removeAttribute("aria-activedescendant");else{var i=this.options[t].node;i.setAttribute("aria-selected","true"),i.classList.add("ss-option--active"),this.input.setAttribute("aria-activedescendant",i.id),!1!==e&&i.scrollIntoView&&i.scrollIntoView({block:"nearest"})}},g.prototype.move=function(t){var e=this.options.length;if(e){var i=this.active+t;i>=e?i=-1:i<-1&&(i=e-1),this.setActive(i)}},g.prototype.onKeydown=function(t){if(!t.isComposing&&229!==t.keyCode)switch(t.key){case"ArrowDown":case"Down":if(this.isOpen)this.move(1);else if(this.lastData&&this.lastQuery===this.value()?this.render(this.lastData,this.lastQuery):this.schedule(),t.altKey)return void t.preventDefault();t.preventDefault();break;case"ArrowUp":case"Up":this.isOpen&&(this.move(-1),t.preventDefault());break;case"Enter":this.isOpen&&this.active>-1&&(t.preventDefault(),this.choose(this.active));break;case"Escape":case"Esc":this.isOpen&&(t.preventDefault(),t.stopPropagation(),this.close());break;case"Tab":this.close()}},g.prototype.choose=function(i){var s=this.options[i];if(s){var n=this.value();if(this.close(),"search"!==s.kind){var o,r={item:s.item,group:s.group,query:n,input:this.input};try{o=new CustomEvent("searchsuggest:select",{bubbles:!0,cancelable:!0,detail:r})}catch(t){(o=e.createEvent("CustomEvent")).initCustomEvent("searchsuggest:select",!0,!0,r)}this.input.dispatchEvent(o)&&(s.item.url?t.location.assign(s.item.url):(this.input.value=s.item.title,this.submit(s.item.title)))}else this.submit(n)}},g.prototype.submit=function(e){this.abort(),this.form?"function"==typeof this.form.requestSubmit?this.form.requestSubmit():this.form.submit():t.location.assign("/main/search.asp?q="+encodeURIComponent(e))},g.prototype.destroy=function(){this.abort(),t.clearTimeout(this.timer),t.removeEventListener("resize",this.onViewport),t.removeEventListener("scroll",this.onViewport,!0),[this.popup,this.hint,this.status].forEach((function(t){t.parentNode&&t.parentNode.removeChild(t)})),u.delete(this.input)},t.SearchSuggest={version:"1.2.0",init:y,attach:b},"loading"===e.readyState?e.addEventListener("DOMContentLoaded",A):A()}function l(t){return"ss-"+t+"-"+(r+=1)}function p(t,e){var i=d(t,"ss-sr",e);return i.style.cssText="position:absolute;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0",i}function d(t,i,s){var n=e.createElement(t);return i&&(n.className=i),null!=s&&(n.textContent=s),n}function f(t){return String(t||"").toLowerCase().replace(/ё/g,"е")}function m(t){return f(t).match(/[0-9a-zа-я]+/g)||[]}function v(e){if("string"!=typeof e||!e)return"";try{var i=new URL(e,t.location.href);return"http:"!==i.protocol&&"https:"!==i.protocol?"":i.href}catch(t){return""}}function g(e,i){var n;this.input=e,this.o=function(t,e){var i,n={},o=t.dataset;for(i in s)n[i]=s[i];if(o.suggest&&"on"!==o.suggest&&(n.src=o.suggest),o.suggestUrl&&(n.url=o.suggestUrl),o.suggestMin&&+o.suggestMin>0&&(n.minChars=+o.suggestMin),o.suggestDelay&&+o.suggestDelay>=0&&(n.delay=+o.suggestDelay),"0"===o.suggestSubmit&&(n.submitItem=!1),o.suggestAnchor&&(n.anchor=o.suggestAnchor),null!=o.suggestCtx&&(n.ctx=o.suggestCtx),e)for(i in e)Object.prototype.hasOwnProperty.call(e,i)&&(n[i]=e[i]);return n}(e,i),this.form=e.form||null,null==this.o.ctx&&(this.o.ctx=this.isSiteSearch()?"":(n=/^\/([^\/?#]+)\//.exec(t.location.pathname||""))?decodeURIComponent(n[1]):""),this.o.ctx=String(this.o.ctx).toLowerCase().replace(/[^a-z0-9_-]/g,"").slice(0,40),this.options=[],this.active=-1,this.isOpen=!1,this.timer=0,this.ctrl=null,this.lastQuery=null,this.lastData=null,this.composing=!1,this.build(),this.bind()}
1function b(i,s){if(!i||"INPUT"!==i.tagName)return null;if(u.has(i))return u.get(i);if("off"===i.dataset.suggest||"hidden"===i.type||i.disabled||i.readOnly)return null;if(i.classList.contains("suggestions-input"))return null;if("function"!=typeof t.fetch||"function"!=typeof Map)return null;!function(){if(!a){a=!0;for(var t=e.querySelectorAll('link[rel="stylesheet"]'),i=0;i<t.length;i++)if(/search-suggest\.css/.test(t[i].href))return;var s=e.createElement("link");s.rel="stylesheet",s.href=o,e.head.appendChild(s)}}();var n=new g(i,s);return u.set(i,n),n}function y(t){for(var s=(t=t||e).querySelectorAll?t.querySelectorAll(i):[],n=0;n<s.length;n++)b(s[n])}function A(){if(y(e),"function"==typeof MutationObserver){var s=0;new MutationObserver((function(n){for(var o=0;o<n.length;o++)for(var r=n[o].addedNodes,a=0;a<r.length;a++){var h=r[a];if(!(1!==h.nodeType||h.closest&&h.closest(".ss-popup"))&&(h.matches&&h.matches(i)||h.querySelector&&h.querySelector(i)))return t.clearTimeout(s),void(s=t.setTimeout((function(){y(e)}),100))}})).observe(e.body,{childList:!0,subtree:!0})}}}(window,document);
2//# sourceMappingURL=search-suggest.js.map

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.