PageSourceSearch

https://chiaracordelia.com/cdn/shop/t/38/assets/predictive-search.js?v=95048802422789577271785828463

js chiaracordelia.com collected 2026-10-04 03:13:44 UTC 4,941 bytes, 1 lines download raw bytes

1class PredictiveSearch extends HTMLElement{constructor(){super(),this.input=this.querySelector("input.field__input"),this.predictiveSearchResults=this.querySelector("[data-predictive-search]"),this.predictiveSearchResultsArticle=this.querySelector("[data-predictive-search-article]"),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),$("form.search-modal__form .predictive-search-content").css("display","none"),$(".header__search-form .close-search-form").css("display","none")),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(),fetch(`${routes.predictive_search_url}?q=${encodeURIComponent(e)}&${encodeURIComponent("resources[type]")}=product&section_id=predictive-search`).then((e=>{if(!e.ok){var t=new Error(e.status);throw this.close(),t}return e.text()})).then((e=>{const s=(new DOMParser).parseFromString(e,"text/html").querySelector("#predictive-search-product").innerHTML;this.renderSearchResults(s,t)})).catch((e=>{throw this.close(),e})),fetch(`${routes.predictive_search_url}?q=${encodeURIComponent(e)}&${encodeURIComponent("resources[type]")}=article&section_id=predictive-search`).then((e=>{if(!e.ok){var t=new Error(e.status);throw this.close(),t}return e.text()})).then((e=>{const s=(new DOMParser).parseFromString(e,"text/html").querySelector("#predictive-search-blog").innerHTML;this.renderSearchResultsArticle(s,t)})).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,t){this.predictiveSearchResults.innerHTML=e,this.setAttribute("results",!0),this.setLiveRegionResults();var s="/search?q="+t+"&type=product";$("[data-predictive-search] [data-view-all-product]").attr("href",s),this.open()}renderSearchResultsArticle(e,t){if(this.predictiveSearchResultsArticle){this.predictiveSearchResultsArticle.innerHTML=e,this.setAttribute("results",!0);var s="/search?q="+t+"&type=article";$("[data-predictive-search-article] [data-view-all-article]").attr("href",s),this.setLiveRegionResults(),this.open()}}setLiveRegionResults(){this.removeAttribute("loading")}getResultsMaxHeight(){return this.resultsMaxHeight=window.innerHeight-document.getElementById("shopify-section-header").getBoundingClientRect().bottom,this.resultsMaxHeight}open(){this.setAttribute("open",!0),this.input.setAttribute("aria-expanded",!0),$("form.search-modal__form .predictive-search-content").removeAttr("style"),$(".header__search-form .close-search-form").css("display","block")}close(e=!1){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)}}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.