PageSourceSearch

https://soldejaneiro.com/cdn/shop/t/562/assets/ia-filter-core.js?v=174743597902557132021788807072

js soldejaneiro.com collected 2026-10-02 07:40:24 UTC 4,940 bytes, 2 lines download raw bytes

1import{EVENTS,publish,subscribe}from"ia-util-pubsub";let pushStateHooked=!1;function hookPushState(){if(pushStateHooked)return;pushStateHooked=!0;const original=history.pushState;history.pushState=function(...args){original.apply(history,args),setTimeout(()=>publish(EVENTS.urlChanged,{}),0)}}class IaFilterEngine extends HTMLElement{connectedCallback(){const config=this.readConfig(this);config?.sectionId&&(this.sectionId=config.sectionId,this.filterData=new Map,this.currentPage=1,this.totalPages=config.totalPages||null,this.totalProducts=config.totalProducts||null,this.isLoading=!1,this.requestId=0,this.controller=null,hookPushState(),this._onPopState||=()=>this.onURLChange(),window.addEventListener("popstate",this._onPopState),this.unsubscribers=[subscribe(EVENTS.loadMoreRequested,()=>this.handleLoadMore()),subscribe(EVENTS.urlChanged,()=>this.onURLChange()),subscribe(EVENTS.filtersApply,({detail})=>this.applyFilters(detail?.forms||[]))])}disconnectedCallback(){window.removeEventListener("popstate",this._onPopState),this.unsubscribers?.forEach(off=>off?.()),this.unsubscribers=null,this.controller?.abort()}readConfig(scope){const node=scope.querySelector("[data-ia-collection-data]");if(!node)return null;try{return JSON.parse(node.textContent)}catch{return null}}updateStateFromDOM(html){const dom=new DOMParser().parseFromString(html,"text/html"),config=this.readConfig(dom);config&&(this.totalPages=config.totalPages||null,this.totalProducts=config.totalProducts||null)}isValidFormValue(key,value){return!(key.includes("filter.v.price")&&!value||!value||value==="default")}onURLChange(){this.sectionId&&(this.currentPage=1,this.fetchDataForCurrentURL())}handleLoadMore(){if(this.sectionId){if(this.isLoading||this.totalPages!==null&&this.currentPage>=this.totalPages){publish(EVENTS.filtersUpdate,{detail:{currentPage:this.currentPage,totalPages:this.totalPages,append:!1,html:null}});return}this.currentPage=this.currentPage+1,this.fetchDataForCurrentURL()}}async performFetch(url,useCache,signal){const response=await fetch(url,{method:"GET",headers:{Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8","X-Requested-With":"XMLHttpRequest"},credentials:"same-origin",signal});if(!response.ok)throw new Error(`HTTP error! status: ${response.status} for URL: ${url}`);const html=await response.text();return useCache&&this.filterData.set(url,html),html}setLoadingState(isLoading){this.isLoading=isLoading,publish(EVENTS.loadingStateChange,{detail:{isLoading}})}async fetchDataForCurrentURL(){if(!this.sectionId)return;const currentParams=new URLSearchParams(window.location.search),baseUrl=window.location.pathname;baseUrl.includes("/search")&&!currentParams.has("type")&&currentParams.set("type","product");const isLoadMore=this.currentPage>1;currentParams.set("page",String(isLoadMore?this.currentPage:1)),currentParams.set("section_id",this.sectionId);const url=`${baseUrl}?${currentParams.toString()}`;this.controller?.abort(),this.controller=new AbortController;const requestId=++this.requestId,isCurrent=()=>requestId===this.requestId,remembered=isLoadMore?void 0:this.filterData.get(url);if(remembered){this.updateStateFromDOM(remembered),publish(EVENTS.filtersUpdate,{detail:{html:remembered,sectionId:this.sectionId,searchParams:window.location.search.slice(1),append:!1,currentPage:this.currentPage,totalPages:this.totalPages,totalProducts:this.totalProducts}}),this.setLoadingState(!1);return}this.setLoadingState(!0);try{const html=await this.performFetch(url,!isLoadMore,this.controller.signal);if(!isCurrent())return;this.updateStateFromDOM(html),publish(EVENTS.filtersUpdate,{detail:{html,sectionId:this.sectionId,searchParams:window.location.search.slice(1),append:isLoadMore,currentPage:this.currentPage,totalPages:this.totalPages,totalProducts:this.totalProducts}})}catch(error){error?.name!=="AbortError"&&isCurrent()&&(isLoadMore&&(this.currentPage=Math.max(1,this.currentPage-1)),publish(EVENTS.filtersError,{detail:{error}}))}finally{isCurrent()&&this.setLoadingState(!1)}}applyFilters(forms){const currentParams=new URLSearchParams(window.location.search),finalParams=new URLSearchParams;
1for(const[key,value]of currentParams)!key.startsWith("filter.")&&key!=="sort_by"&&key!=="page"&&finalParams.append(key,value);forms.forEach(form=>{if(!form.hasAttribute("data-ia-filter-form")&&!form.hasAttribute("data-ia-sort-form"))return;new FormData(form).forEach((value,key)=>{this.isValidFormValue(key,value)&&(key.startsWith("filter.")?finalParams.append(key,value):finalParams.set(key,value))})}),finalParams.set("page","1");const url=`${window.location.pathname}${finalParams.toString()?"?"+finalParams.toString():""}`;history.pushState({searchParams:finalParams.toString()},"",url)}}customElements.get("ia-filter-engine")||customElements.define("ia-filter-engine",IaFilterEngine);
2//# sourceMappingURL=/cdn/shop/t/562/assets/ia-filter-core.js.map?v=174743597902557132021788807072

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.