https://www.getfussy.com/cdn/shop/t/321/assets/location-selector.js?v=158634403484432596761746785254
1customElements.get("location-selector")||customElements.define("location-selector",class extends ModalDialog{constructor(){super(),this.shopUrl=window.shopUrl,this.shopLocation=window.shopLocation,this.form=this.querySelector("form"),this.countries=this.querySelector("#countries"),this.eventListeners=[]}async connectedCallback(){Shopify.designMode||await this.initLocationSelector()}disconnectedCallback(){this.removeEventListeners()}countryList(){try{const countries=this.countries.textContent.trim(),parsedData=JSON.parse(countries);return parsedData&&parsedData.countries&&Array.isArray(parsedData.countries)?parsedData.countries:(console.error("Invalid countries data structure:",parsedData),[])}catch(error){return console.error("Error parsing countries JSON:",error,this.countries.textContent),[]}}async initLocationSelector(){const selectedLocation=this.getLocationCookie("country"),urlParams=new URLSearchParams(window.location.search);if(!selectedLocation||selectedLocation!==this.shopLocation){if(urlParams.get("country")||this.getLocationCookie("country_override"))return;const userLocation=await this.getUserLocation();if(!userLocation)return;userLocation.handle!==this.shopLocation&&this.show(),this.setupSuggestedCountry(userLocation.name),this.setupModalCloseButton(),this.attachFormChangeListener(userLocation)}}async getUserLocation(){const url=`${this.shopUrl}/browsing_context_suggestions.json`;try{return(await(await fetch(url)).json()).detected_values.country}catch(error){return console.error("Error fetching user location:",error),null}}getLocationCookie(name){const parts=`; ${document.cookie}`.split(`; ${name}=`);if(parts.length===2)return parts.pop().split(";").shift()}setLocationCookie(name,value,days){const expiryDate=new Date;expiryDate.setTime(expiryDate.getTime()+days*24*60*60*1e3);const expires=`expires=${expiryDate.toUTCString()}`;document.cookie=`${name}=${value}; ${expires}; path=/`}setupSuggestedCountry(userLocationName){this.querySelectorAll("[data-suggested]").forEach(element=>{element.textContent=userLocationName})}setupModalCloseButton(){const modalCloseButtons=this.querySelectorAll("[data-close]");if(modalCloseButtons.length>0){const closeListener=()=>{this.setLocationCookie("country",this.shopLocation,30),this.hide()};modalCloseButtons.forEach(button=>{button.addEventListener("click",closeListener),this.eventListeners.push({target:button,type:"click",listener:closeListener})})}}attachFormChangeListener(userLocation){if(!this.form)return;const languageInput=this.form.querySelector('input[name="language_code"]'),countryInput=this.form.querySelector('input[name="country_code"]');if(!languageInput||!countryInput)return;const submitButton=this.form.querySelector("[data-submit]"),closeButton=this.form.querySelector("[data-close]");if(submitButton){const submitClickListener=event=>{event.preventDefault();try{const countries=this.countryList();if(!Array.isArray(countries)){console.error("Countries is not an array:",countries);return}const selectedCountry=countries.find(country=>country.country===userLocation.handle);
1if(!selectedCountry||!selectedCountry.languages||!selectedCountry.languages.length){console.error("Invalid country data:",selectedCountry);return}languageInput.value=selectedCountry.languages[0].toLowerCase(),countryInput.value=userLocation.handle,this.setLocationCookie("country",userLocation.handle,30),fetch(this.form.action,{method:this.form.method,body:new FormData(this.form)}).then(()=>{const language=selectedCountry.languages[0].toLowerCase(),redirectUrl=language==="en"?window.location.origin:`${window.location.origin}/${language}`;window.location.href=redirectUrl}).catch(error=>{console.error("Error submitting form:",error)})}catch(error){console.error("Error in submit handler:",error)}};submitButton.addEventListener("click",submitClickListener),this.eventListeners.push({target:submitButton,type:"click",listener:submitClickListener})}if(closeButton){const closeClickListener=event=>{event.preventDefault(),this.setLocationCookie("country",this.shopLocation,30),this.hide()};closeButton.addEventListener("click",closeClickListener),this.eventListeners.push({target:closeButton,type:"click",listener:closeClickListener})}}removeEventListeners(){this.eventListeners.forEach(({target,type,listener})=>{target.removeEventListener(type,listener)}),this.eventListeners=[]}}); 2//# sourceMappingURL=/cdn/shop/t/321/assets/location-selector.js.map?v=158634403484432596761746785254
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.