PageSourceSearch

https://shop.startrek.com/cdn/shop/t/109/assets/predictive-search.js?v=181106228012359498731772044469

js startrek.com collected 2026-09-24 08:30:27 UTC 4,692 bytes, 1 lines download raw bytes

1class PredictiveSearch extends HTMLElement{constructor(){super(),this.cachedResults={},this.input=this.querySelector('input[type="search"]'),this.predictiveSearchResults=this.querySelector("[data-predictive-search]"),this.isOpen=!1,this.setupEventListeners()}setupEventListeners(){this.querySelector("form.search").addEventListener("submit",this.onFormSubmit.bind(this)),this.input.addEventListener("input",debounce((e=>{this.onChange(e)}),300).bind(this)),this.input.addEventListener("focus",this.onFocus.bind(this)),this.addEventListener("focusout",this.onFocusOut.bind(this)),this.addEventListener("keyup",this.onKeyup.bind(this)),this.addEventListener("keydown",this.onKeydown.bind(this))}getQuery(){return this.input.value.trim()}onChange(){const e=this.getQuery();e.length?this.getSearchResults(e):this.close(!0)}onFormSubmit(e){this.getQuery().length&&!this.querySelector('[aria-selected="true"] a')||e.preventDefault()}onFocus(){const e=this.getQuery();e.length&&("true"===this.getAttribute("results")?this.open():this.getSearchResults(e))}onFocusOut(){setTimeout((()=>{this.contains(document.activeElement)||this.close()}))}onKeyup(e){switch(this.getQuery().length||this.close(!0),e.preventDefault(),e.code){case"ArrowUp":this.switchOption("up");break;case"ArrowDown":this.switchOption("down");break;case"Enter":this.selectOption()}}onKeydown(e){"ArrowUp"!==e.code&&"ArrowDown"!==e.code||e.preventDefault()}switchOption(e){if(!this.getAttribute("open"))return;const t="up"===e,s=this.querySelector('[aria-selected="true"]'),i=this.querySelectorAll("li");let r=this.querySelector("li");t&&!s||(this.statusElement.textContent="",!t&&s?r=s.nextElementSibling||i[0]:t&&(r=s.previousElementSibling||i[i.length-1]),r!==s&&(r.setAttribute("aria-selected",!0),s&&s.setAttribute("aria-selected",!1),this.setLiveRegionText(r.textContent),this.input.setAttribute("aria-activedescendant",r.id)))}selectOption(){const e=this.querySelector('[aria-selected="true"] a, [aria-selected="true"] button');e&&e.click()}getSearchResults(e){const t=e.replace(" ","-").toLowerCase();this.setLiveRegionLoadingState(),this.cachedResults[t]?this.renderSearchResults(this.cachedResults[t]):fetch(`${routes.predictive_search_url}?q=${encodeURIComponent(e)}&${encodeURIComponent("resources[type]")}=product,page,collection,article&${encodeURIComponent("resources[limit]")}=${this.predictiveSearchResults.dataset.limit}&${encodeURIComponent("resources[limit_scope]")}=each&section_id=predictive-search`).then((e=>{if(!e.ok){var t=new Error(e.status);throw this.close(),t}return e.text()})).then((e=>{let s=(new DOMParser).parseFromString(e,"text/html").querySelector("#shopify-section-predictive-search"),i=s.innerHTML;if(document.cookie.indexOf("isAnAdult")>-1){console.log("Adult content available");const e=s.querySelectorAll(".nsfw");console.log(e),e.forEach((e=>{e.classList.remove("nsfw")})),i=s.innerHTML}const r=i;this.cachedResults[t]=r,this.renderSearchResults(r)})).catch((e=>{throw this.close(),e}))}setLiveRegionLoadingState(){this.statusElement=this.statusElement||this.querySelector(".predictive-search-status"),this.loadingText=this.loadingText||this.getAttribute("data-loading-text"),this.setLiveRegionText(this.loadingText),this.setAttribute("loading",!0)}setLiveRegionText(e){this.statusElement.setAttribute("aria-hidden","false"),this.statusElement.textContent=e,setTimeout((()=>{this.statusElement.setAttribute("aria-hidden","true")}),1e3)}renderSearchResults(e){this.predictiveSearchResults.innerHTML=e,this.setAttribute("results",!0),this.setLiveRegionResults(),this.open()}setLiveRegionResults(){this.removeAttribute("loading"),this.setLiveRegionText(this.querySelector("[data-predictive-search-live-region-count-value]").textContent)}getResultsMaxHeight(){return this.resultsMaxHeight=window.innerHeight-document.getElementById("shopify-section-header").getBoundingClientRect().bottom,this.resultsMaxHeight}open(){this.predictiveSearchResults.style.maxHeight=this.resultsMaxHeight||`${this.getResultsMaxHeight()}px`,this.setAttribute("open",!0),this.input.setAttribute("aria-expanded",!0),this.isOpen=!0,window.postMessage({type:"predictive_search",action:"open_search"},"*")}close(e=!1){window.postMessage({type:"predictive_search",action:"close_search"},"*"),e&&(this.input.value="",this.removeAttribute("results"));const t=this.querySelector('[aria-selected="true"]');t&&t.setAttribute("aria-selected",!1),this.input.setAttribute("aria-activedescendant",""),this.removeAttribute("open"),this.input.setAttribute("aria-expanded",!1),this.resultsMaxHeight=!1,this.predictiveSearchResults.removeAttribute("style"),this.isOpen=!1}}customElements.define("predictive-search",PredictiveSearch);

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.