PageSourceSearch

https://www.pimkie.fr/cdn/shop/t/101/assets/ClrzNostoSearch.min.eyIOBXaI.js

js pimkie.fr collected 2026-09-24 20:02:43 UTC 6,465 bytes, 40 lines download raw bytes

1import{D as d}from"./DeferWebComponent.min.BrKhvwE6.js";import{F as c}from"./FixScroll.min.CEFs3W-g.js";class h extends d{constructor(){super()}ready(){this.header=document.querySelector("[data-header]"),this.navSidebar=document.querySelector("nav-sidebar"),this.openSearchBtns=document.querySelectorAll("[data-nosto-search-open]"),this.closeSearchBtns=document.querySelectorAll("[data-nosto-search-close]"),this.searchOverlay=document.querySelector("[data-nosto-search-overlay]"),this.inputSearch=this.querySelector("[data-nosto-search-input]"),this.suggestionsContainer=this.querySelector("[data-nosto-search-suggestions-container]"),this.suggestionsResults=this.querySelector("[data-nosto-search-suggestions-results]"),this.productsContainer=this.querySelector("[data-nosto-search-products-container]"),this.productsContainerNoResults=this.querySelector("[data-nosto-search-products-container-no-results]"),this.productsResults=this.querySelector("[data-nosto-search-products-results]"),this.searchForm=this.querySelector("form"),this.keywords=[],this.lastFetchedQuery="",this.debounceTimeout=null,this.isSubmitting=!1,this.bindEvents()}bindEvents(){this.openSearchBtns.forEach(t=>{t.addEventListener("click",this.open.bind(this))}),this.closeSearchBtns.forEach(t=>{t.addEventListener("click",this.close.bind(this))}),this.setupInputListener(),this.setupSubmitListener()}open(){this.classList.add("is-visible"),this.searchOverlay.classList.add("is-visible"),this.header.classList.add("is-search-open"),window.location.pathname==="/"&&this.header.classList.remove("is-transparent"),this.inputSearch.focus(),c.fix()}close(){this.classList.remove("is-visible"),this.searchOverlay.classList.remove("is-visible"),this.header.classList.remove("is-search-open"),window.location.pathname==="/"&&!this.navSidebar.classList.contains("is-open")&&this.header.classList.add("is-transparent"),this.inputSearch.value="",c.unFix()}setupInputListener(){this.inputSearch&&this.inputSearch.addEventListener("input",t=>{const s=t.target.value;clearTimeout(this.debounceTimeout),this.debounceTimeout=setTimeout(()=>{this.fetchResults(s)},500)})}setupSubmitListener(){this.searchForm&&this.searchForm.addEventListener("submit",async t=>{if(this.isSubmitting){t.preventDefault();return}const s=this.inputSearch.value.trim();if(!s){t.preventDefault();return}const e=this.getKeywordRedirectUrl(s);if(e){t.preventDefault(),window.location.href=e;return}if(!this.isKeywordCacheFresh(s)){t.preventDefault(),clearTimeout(this.debounceTimeout),this.isSubmitting=!0;try{const r=await this.fetchKeywordRedirectUrl(s);r?window.location.href=r:this.submitSearchForm()}catch{this.submitSearchForm()}finally{this.isSubmitting=!1}}})}isKeywordCacheFresh(t){return this.lastFetchedQuery&&this.lastFetchedQuery.trim().toLowerCase()===t.toLowerCase()}getKeywordRedirectUrl(t){if(!this.isKeywordCacheFresh(t))return null;const s=this.keywords.find(e=>e._redirect&&e.keyword.trim().toLowerCase()===t.toLowerCase());return(s==null?void 0:s._redirect)??null}fetchKeywordRedirectUrl(t){return fetch("https://search.nosto.com/v1/graphql",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:` {
2						search(
3							accountId: "${window.nostoStrings.account_id}"
4							query: "${t}"
5							keywords: { size: 8 }
6						) {
7							keywords {
8								hits {
9									keyword
10									_redirect
11								}
12							}
13						}
14					}`})}).then(s=>s.json()).then(s=>{var r;const e=((r=s.data.search.keywords)==null?void 0:r.hits)||[];return this.keywords=e,this.lastFetchedQuery=t,this.getKeywordRedirectUrl(t)})}submitSearchForm(){HTMLFormElement.prototype.submit.call(this.searchForm)}fetchResults(t,s=!0){fetch("https://search.nosto.com/v1/graphql",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:` {
15						search(
16							accountId: "${window.nostoStrings.account_id}"
17							query: "${t}"
18							products: { size: 8 },
19							keywords: { size: 8 }
20						) {
21							products {
22								hits {
23									productId
24									name
25                                    url
26								}
27								total
28							}
29							keywords {
30								hits {
31									keyword
32									_redirect
33									_highlight {
34										keyword
35									}
36								}
37							}
38							query
39						}
40					}`})}).then(e=>e.json()).then(async e=>{var i;const r=((i=e.data.search.keywords)==null?void 0:i.hits)||[];this.keywords=r,this.lastFetchedQuery=t,this.suggestionsResults.innerHTML="",r.length>0?(this.suggestionsContainer.style.display="block",r.forEach(o=>{this.renderSuggestion(o,e)})):this.suggestionsContainer.style.display="none";const n=e.data.search.products.hits;if(this.productsResults.innerHTML="",n.length>0){this.productsContainer.style.display="block",this.productsContainerNo
40Results.style.display="none";const o=n.map(a=>this.fetchProduct(a.url));(await Promise.all(o)).forEach(a=>{a&&this.productsResults.appendChild(a)}),document.dispatchEvent(new CustomEvent("nosto-loaded",{detail:{container:this.productsResults}}))}else this.productsContainer.style.display="none",this.productsContainerNoResults.style.display="block";s&&nostojs(o=>{o.recordSearch("autocomplete",{query:t},{products:e.data.search.products},{isKeyword:!1})})})}renderSuggestion(t,s){let e;t._redirect?(e=document.createElement("a"),e.href=t._redirect,e.textContent=t.keyword,e.classList.add("t-button")):(e=document.createElement("div"),e.textContent=t.keyword,e.classList.add("t-button")),e.addEventListener("click",()=>{this.autoComplete(t),nostojs(r=>{r.recordSearch("autocomplete",{query:t.keyword},{products:s.data.search.products},{isKeyword:!0})})}),this.suggestionsResults.appendChild(e)}autoComplete(t){this.inputSearch.value=t.keyword,this.fetchResults(t.keyword,!1)}async fetchProduct(t){const s=new URL(t);return s.searchParams.append("section_id","section-card-product"),fetch(s).then(e=>e.text()).then(e=>{const r=new DOMParser().parseFromString(e,"text/html").querySelector("[data-id=card-product]");if(!r)return null;r.addEventListener("click",()=>{nostojs(i=>{i.recordSearchClick("autocomplete",{productId:r.dataset.productId,url:r.dataset.productUrl})})});const n=r.querySelectorAll("product-form form");return n.length>0&&n.forEach(i=>{i.addEventListener("click",()=>{nostojs(o=>{o.recordSearchAddToCart("autocomplete",{productId:r.dataset.productId,url:r.dataset.productUrl})})})}),r})}}customElements.get("clrz-nosto-search")||customElements.define("clrz-nosto-search",h);

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.