PageSourceSearch

https://www.hv71.se/assets/ShopProductSearch-Bi4IPmgm.js

js hv71.se collected 2026-10-02 10:00:39 UTC 12,071 bytes, 6 lines download raw bytes

1import{aZ as V,a1 as H,ak as F,a5 as O,T as N,o as U,h as k,t as B,r as z,z as T,B as R,C as y,D as x,E as P,I as C,J as v,a7 as j,a8 as Q,aa as K,F as L,N as M,S as Z,K as J,O as Y}from"./index-NU9DPTTF.js";import{u as G}from"./shop.api-B0zRFo91.js";const c={currentPage:1,pageSize:40,isLoading:!1,hasMoreItems:!0,enablePagination:!0,init(){this.enablePagination=!0,window.addEventListener("scroll",V(this.handleScroll.bind(this),100))},disablePagination(){this.enablePagination=!1},async handleScroll(){if(this.isLoading||!this.hasMoreItems||!this.enablePagination)return;const{scrollHeight:e}=document.documentElement,t=window.scrollY||document.documentElement.scrollTop,{clientHeight:i}=document.documentElement;t+i>=e-800&&(this.currentPage+=1,await q.updateResults(!0))},reset(){this.currentPage=1,this.hasMoreItems=!0,this.isLoading=!1}},w={minValue:0,maxValue:35e3,isOpen:!1,hasBeenSelected:!1,initialMinValue:0,initialMaxValue:35e3,init(){this.cacheDOM(),this.bindEvents(),this.setPriceRangeFromProducts(),this.updateSliderDisplay()},cacheDOM(){this.dropdown=document.querySelector(".price-range-dropdown"),this.button=document.querySelector(".price-range-button"),this.content=document.querySelector(".price-range-dropdown-content"),this.minRange=document.querySelector(".min-range"),this.maxRange=document.querySelector(".max-range"),this.priceSlider=document.querySelector(".price-slider"),this.priceText=document.querySelector(".price-range-text")},setPriceRangeFromProducts(){const e=Array.from(document.querySelectorAll(".product-price")).map(t=>{const i=t.textContent.trim();return parseInt(i.replace(/[^0-9]/g,""),10)}).filter(t=>!Number.isNaN(t));e.length>0&&(this.initialMinValue=Math.min(...e),this.initialMaxValue=Math.max(...e),this.minValue=this.initialMinValue,this.maxValue=this.initialMaxValue,this.minRange.min=this.initialMinValue,this.minRange.max=this.initialMaxValue,this.minRange.value=this.initialMinValue,this.maxRange.min=this.initialMinValue,this.maxRange.max=this.initialMaxValue,this.maxRange.value=this.initialMaxValue,this.updateButtonText())},bindEvents(){this.button.addEventListener("click",a=>{a.stopPropagation(),this.toggleDropdown()}),document.addEventListener("click",a=>{this.dropdown.contains(a.target)||this.closeDropdown()});const e=()=>{const a=parseInt(this.minRange.value,10),o=parseInt(this.maxRange.value,10);a>o&&(this.minRange===document.activeElement?this.maxRange.value=a:this.minRange.value=o),this.minValue=parseInt(this.minRange.value,10),this.maxValue=parseInt(this.maxRange.value,10),this.updateSliderDisplay(),this.updateButtonText()},t=V(()=>{this.hasBeenSelected=!0,q.updateResults()},1e3);this.minRange.addEventListener("input",()=>{e(),t()}),this.maxRange.addEventListener("input",()=>{e(),t()});const i=document.querySelector(".product-list-container");i&&new MutationObserver(()=>{this.hasBeenSelected||(this.setPriceRangeFromProducts(),this.updateSliderDisplay())}).observe(i,{childList:!0})},toggleDropdown(){this.isOpen=!this.isOpen,this.dropdown.classList.toggle("active",this.isOpen)},closeDropdown(){this.isOpen=!1,this.dropdown.classList.remove("active")},updateSliderDisplay(){const e=this.maxRange.max-this.minRange.min,t=(this.minValue-this.minRange.min)/e*100,i=(this.maxValue-this.minRange.min)/e*100;this.priceSlider.style.left=`${t}%`,this.priceSlider.style.width=`${i-t}%`,this.priceText.textContent=`${this.minValue} - ${this.maxValue} kr`},updateButtonText(){this.hasBeenSelected?this.button.textContent=`${this.minValue} - ${this.maxValue} kr`:this.button.textContent="Select Price Range"},reset(){this.minValue=this.initialMinValue,this.maxValue=this.initialMaxValue,this.minRange.value=this.initialMinValue,this.maxRange.value=this.initialMaxValue,this.hasBeenSelected=!1,this.updateSliderDisplay(),this.updateButtonText(),this.closeDropdown()}},q={async updateResults(e=!1){var t,i,a,o,h,u;try{e||c.reset();const n=document.querySelector(".product-list-container");if(!n)return console.warn(".product-list-container not found. Delaying filter update."),new Promise(r=>setTimeout(()=>r(this.updateResults(e)),500));const l=(t=document.getElementById("api-key"))==null?void 0:t.value,b=(i=document.querySelector('input[name="store_name"]'))==null?void 0:i.value,g=(a=document.querySelector('input[name="query"]'))==null?void 0:a.value;if(!l||!b)throw new Error("Missing required parameters: API key or store name");const d=new URLSearchParams,s={availability:((o=document.getElementById("availability"))==null?void 0:o.value)||"",sort:((h=document.getElementById("sort"))==null?void 0:h.value)||"",price_min:w.minValue.toString(),price_max:w.maxValue.toString(),query:g,storeName:b,a
1piKey:l,page:c.currentPage,page_size:c.pageSize},_=new URLSearchParams,p={availability:s.availability,sort:s.sort,price_min:s.price_min,price_max:s.price_max,query:g};g&&_.set("query",g),Object.entries(p).forEach(([r,m])=>{if(r!=="query"&&m){const S=r.replace(/([A-Z])/g,"_$1").toLowerCase();_.set(S,m)}});const f=`${window.location.origin}${window.location.pathname}#?${_.toString()}`;if(window.history.replaceState({},"",f),Object.entries(s).forEach(([r,m])=>{if(m){const S=r.replace(/([A-Z])/g,"_$1").toLowerCase();d.set(S,m)}}),c.isLoading=!0,!e)n.innerHTML='<div style="text-align: center; padding: 20px;">Loading...</div>';else{const r=document.createElement("div");r.id="loading-more",r.style.textAlign="center",r.style.padding="20px",r.innerHTML="Loading more products...",n.appendChild(r)}const A=`https://search.enode.se/search?${d.toString()}`,I=await fetch(A);if(!I.ok)throw new Error(`Server responded with status: ${I.status}`);const D=await I.text(),E=(u=new DOMParser().parseFromString(D,"text/html").querySelector(".product-list-container"))==null?void 0:u.innerHTML;if((!E||E.trim()==="")&&(c.hasMoreItems=!1),e){const r=document.getElementById("loading-more");r&&r.remove();const m=document.createElement("div");m.innerHTML=E;const S=m.children;for(;S.length>0;)n.appendChild(S[0])}else n.innerHTML=E;$.attachProductListeners(),this.updateAppliedFiltersDisplay(s)}catch(n){if(console.error("Error updating results:",n),!e){const l=document.querySelector(".product-list-container");l&&(l.innerHTML=`
2                                <div style="text-align: center; padding: 20px; color: #721c24; background-color: #f8d7da; border: 1px solid #f5c6cb; border-radius: 4px;">
3                                    <h3>No products found on the select search</h3>
4                                    <p>Please try with different search or search filters.</p>
5                                </div>
6                            `)}}finally{c.isLoading=!1}},updateAppliedFiltersDisplay(e){const t=[];e.availability&&t.push(`Availability: ${e.availability}`),e.sort&&t.push(`Sorted by ${e.sort.replace(/_/g," ")}`),w.hasBeenSelected&&t.push(`Price: ${e.price_min} - ${e.price_max} kr`);const i=document.getElementById("applied-filters"),a=document.getElementById("reset-filters"),o=document.getElementById("applied-filters-content");t.length>0?(o.textContent=t.join(", "),i.style.display="block",a.style.display="inline-block"):(i.style.display="none",a.style.display="none")},resetFilters(){try{const e={availability:document.getElementById("availability"),sort:document.getElementById("sort")};e.availability&&(e.availability.selectedIndex=0),e.sort&&(e.sort.selectedIndex=0),w.reset(),c.reset(),this.updateResults()}catch(e){console.error("Error resetting filters:",e)}}},$={init(e,t){var a;const i=(a=document.querySelector('input[name="query"]'))==null?void 0:a.value;e&&(c.pageSize=e),i&&i.trim()!==""&&(this.attachFilterListeners(),w.init(),t&&(c.reset(),c.init())),this.attachProductListeners()},attachFilterListeners(){const e={availability:document.getElementById("availability"),sort:document.getElementById("sort")};Object.values(e).forEach(i=>{i&&i.addEventListener("change",()=>q.updateResults())});const t=document.getElementById("reset-filters");t&&t.addEventListener("click",()=>{q.resetFilters()})},attachProductListeners(){document.querySelectorAll(".product-card").forEach(e=>{const t=e.getAttribute("data-rec-store-name"),i=e.getAttribute("data-rec-url");if(!t||!i){console.error("Missing store_name or url for product card:",e);return}e.removeEventListener("click",this.productClickHandler),e.addEventListener("click",a=>this.productClickHandler(a,i))})},productClickHandler(e,t){e.preventDefault(),window.open(t,"_blank")}},W={name:"ProductSearch",components:{SdpLoader:F,SdpStreamlineIcon:H},props:{productCount:{type:Number,default:40},enablePagination:{type:Boolean,default:!1}},emits:["updateSearch"],setup(e,{emit:t}){const i=G(),a=O(),o=z(),{productCount:h,enablePagination:u}=N(e),n=k({query:"",lastQuery:"",isInitialSearch:!0,hasError:!1,isResultEmpty:!1,displayShowAll:!1,isLoading:!1}),l=async()=>
6{if(n.query===n.lastQuery)return;const d=document.getElementById("search-results-container");if(!d){console.error("Search results container not found.");return}const s=new URLSearchParams;s.set("query",n.query);const _=new URLSearchParams(window.location.hash.slice(1));for(const[p,f]of _)p!=="query"&&s.set(p,f);if(a.push({hash:`#?${s}`}),s.set("page_size",h.value.toString()),n.isInitialSearch)try{n.isLoading=!0;const p=await i.searchProducts(s.toString());d.innerHTML=p,$.init(h.value,u.value);const f=document.querySelectorAll("#search-results-container .product-item").length;n.isResultEmpty=!B(n.query)&&f===0,n.displayShowAll=!B(n.query)&&f===h.value,t("updateSearch",n.query,n.displayShowAll)}catch(p){console.error(p),n.hasError=!0}n.isLoading=!1,n.lastQuery=n.query,n.isInitialSearch=!1},b=V(()=>{n.hasError=!1,l()},500),g=()=>{n.query="",a.push({hash:""});const d=document.getElementById("search-results-container");if(!d){console.error("Search results container not found.");return}d.innerHTML=""};return U(()=>{const s=new URLSearchParams(window.location.hash.slice(1)).get("query");u.value||c.disablePagination(),s&&(o.value.focus(),n.query=decodeURIComponent(s),l())}),{state:n,handleInputSearch:b,removeQuery:g,searchInput:o}}},X={class:"search-bar"},ee=["placeholder"],te={key:0,class:"h-96 flex"},ae={class:"m-auto flex items-center justify-center"},ne={key:1,class:"info-msg"},ie={key:2,class:"info-msg"};function se(e,t,i,a,o,h){const u=R("sdp-streamline-icon"),n=R("sdp-loader");return y(),x("div",null,[P("div",X,[a.state.query?v("",!0):(y(),C(u,{key:0,class:"search icon",icon:"search",size:18})),j(P("input",{ref:"searchInput","onUpdate:modelValue":t[0]||(t[0]=l=>a.state.query=l),"aria-label":"search-input",type:"text",placeholder:e.$t("shop.search_product"),class:K(["search-input",a.state.query?"pl-4":""]),onInput:t[1]||(t[1]=(...l)=>a.handleInputSearch&&a.handleInputSearch(...l))},null,42,ee),[[Q,a.state.query,void 0,{trim:!0}]]),a.state.query?(y(),C(u,{key:1,class:"close icon",icon:"closeIcon",size:18,onClick:a.removeQuery},null,8,["onClick"])):v("",!0)]),a.state.isLoading?(y(),x("div",te,[P("span",ae,[L(n)])])):v("",!0),t[2]||(t[2]=P("div",{id:"search-results-container"},null,-1)),a.state.hasError?(y(),x("div",ne,M(e.$t("shop.search_error")),1)):v("",!0),a.state.isResultEmpty?(y(),x("div",ie,M(e.$t("shop.no_search_results")),1)):v("",!0)])}const re=T(W,[["render",se],["__scopeId","data-v-43d78328"]]),oe={name:"ShopProductSearch",components:{SyButton:Z,ProductSearch:re},setup(){const e=k({query:"",displayShowAll:!1});return{state:e,updateSearchState:(i,a)=>{e.query=i,e.displayShowAll=a}}}},le={class:"product-search"},ce={key:0,class:"btn-container"};function ue(e,t,i,a,o,h){const u=R("product-search"),n=R("sy-button");return y(),x("div",le,[L(u,{"product-count":6,onUpdateSearch:a.updateSearchState},null,8,["onUpdateSearch"]),a.state.displayShowAll?(y(),x("div",ce,[L(n,{primary:"",to:`shop/search-results#?query=${a.state.query}`},{default:J(()=>[Y(M(e.$t("shop.show_all")),1)]),_:1},8,["to"])])):v("",!0)])}const de=T(oe,[["render",ue],["__scopeId","data-v-73a2bd60"]]),ge=Object.freeze(Object.defineProperty({__proto__:null,default:de},Symbol.toStringTag,{value:"Module"}));export{re as P,de as S,ge as a};

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.