PageSourceSearch

https://ooni.com/cdn/shop/t/621/assets/__vite-localization-ui.CZ12VAAu.js

js ooni.com collected 2026-09-24 09:06:20 UTC 9,948 bytes, 2 lines download raw bytes

1import{a as S,b as C,e as L,s as w}from"./__vite-utils.bEHj0ca_.js";import"./__vite-currency.CSCTdhpv.js";class A extends HTMLElement{constructor(){super(),this.persistDays=28,this.currentDomain=this.getAttribute("data-current-domain"),this.selectedRegion="",this.stores=JSON.parse(this.getAttribute("data-stores"));const t=window.themeVars.locale.market.handle;this.currentMarket=t==="UK"?"GB":window.themeVars.locale.market.handle,this.localizationForm=this.querySelector(".localization-ui__form"),this.modalCloseButton=this.querySelector("uwp-modal[modal-name='localization'] .modal__container [data-close-modal]"),this.countryForm=this.querySelector('[js-localization-ui="settings"]'),this.changeRegionButton=this.querySelector('[js-localization-ui="change-region"]'),this.countryChoice="",this.regionChoice="",this.languageChoice="",this.initialCountry="",this.initialRegion="",this.initialLanguage=""}connectedCallback(){this.checkUserLocaleOnLoad(),this.setEventListeners();const t=this.querySelector('uwp-custom-dropdown[name="country"]');if(t){const n=t.querySelectorAll(".custom-dropdown__option"),r=Array.from(n),l=r.find(a=>a.getAttribute("data-url")===this.currentDomain)||r[0];if(l&&!this.dropdownHasSelection(t)){this.applyOptionToDropdown(t,l);const a=l.getAttribute("data-value")??"";this.handleCountryChange({detail:{name:"country",value:a}})}}this.querySelectorAll('uwp-custom-dropdown[name^="region-"]').forEach(n=>{const r=n.querySelector(".custom-dropdown__option");r&&this.applyOptionToDropdown(n,r)}),this.querySelectorAll('uwp-custom-dropdown[name^="language-"]').forEach(n=>{const r=n.querySelector(".custom-dropdown__option");r&&!this.dropdownHasSelection(n)&&this.applyOptionToDropdown(n,r)})}applyOptionToDropdown(t,o){!t||!o||typeof t.applySelection=="function"&&t.applySelection(o)}dropdownHasSelection(t){var s;const o=t.querySelector('[js-custom-dropdown="selected-text"]');return!!((s=o?.textContent)!=null&&s.trim())}setEventListeners(){this.countryForm&&this.countryForm.addEventListener("submit",this.handleFormSubmit.bind(this)),this.changeRegionButton&&this.changeRegionButton.addEventListener("click",()=>{this.showSettingsUi()}),this.modalCloseButton&&this.modalCloseButton.addEventListener("click",()=>{this.persistCurrentSelection()}),document.addEventListener("custom-dropdown:change",this.handleInputChange.bind(this))}handleInputChange(t){if(!("detail"in t)||typeof t.detail!="object")return;const o=t.detail;if(o){if(o.name==="country"){this.handleCountryChange(t);return}if(o.name.includes("region")){this.handleRegionChange(t);return}}}handleRegionChange(t,o){if(!("detail"in t)||typeof t.detail!="object")return;const s=t.detail,n=s.name.split("-").at(-1),r=this.querySelector(`.localization-ui__form-select[name="region-${n}"]`),l=r?.querySelector(".custom-dropdown__option.selected");this.selectedRegion=l?.getAttribute("data-iso-code")||"";const a=this.querySelector(`.custom-dropdown__option[data-value="${s.value}"][data-languages]`),e=this.querySelector(`.localization-ui__subtitle[data-country='${n}']`),d=this.querySelectorAll('uwp-custom-dropdown[js-localization-ui="language-select"]'),i=this.querySelector(`uwp-custom-dropdown[js-localization-ui="language-select"][name="language-${s.value}"]`);if(!a)return;d.length>1&&d.forEach(u=>{u.classList.toggle("is-hidden",!0)});const c=a.getAttribute("data-languages");if(!c){i?.classList.toggle("is-hidden",!0),e?.classList.toggle("is-hidden",!0);return}const h=c.split("|").map(u=>u.replace(/"/g,""));if(!Array.isArray(h)||h.length===0){i?.classList.toggle("is-hidden",!0),e?.classList.toggle("is-hidden",!0);return}if(h?.length===1){if(i?.classList.toggle("is-hidden",!0),e?.classList.toggle("is-hidden",!0),this.querySelectorAll('.localization-ui__form-select[name^="language-"]').forEach(m=>{m.classList.toggle("is-hidden",!0)}),!i)return;i.classList.toggle("is-hidden",!0),e?.classList.toggle("is-hidden",!0);return}if(!i)return;i.classList.remove("is-hidden"),e?.classList.remove("is-hidden");const p=i.querySelectorAll(".localization-ui__country.custom-dropdown__option");let g=!1;p.forEach(u=>{const m=u.getAttribute("data-value");m&&!h.includes(m)?u.classList.add("is-hidden"):(u.classList.remove("is-hidden"),m===o?(p.forEac
1h(y=>{y.classList.remove("selected")}),u.classList.add("selected"),this.applyOptionToDropdown(i,u),g=!0):g?u.classList.remove("selected"):(p.forEach(y=>{y.classList.remove("selected")}),u.classList.add("selected"),this.applyOptionToDropdown(i,u),g=!0))})}handleCountryChange(t,o){if(!("detail"in t)||typeof t.detail!="object")return;const n=t.detail.value,r=this.querySelectorAll('.localization-ui__form-select[name^="region-"]'),l=this.querySelectorAll(".localization-ui__subtitle[data-country]"),a=this.querySelectorAll('.localization-ui__form-select[name^="language-"]');[...r,...l,...a].forEach(e=>{e.classList.add("is-hidden")}),r.forEach(e=>{if((e.getAttribute("name")||"").split("-").at(-1)===n){if(o){const m=Array.from(e.querySelectorAll(".custom-dropdown__option"));m.forEach(f=>{f.classList.remove("selected")});const y=m.find(f=>{var _;return(_=f.getAttribute("data-value"))==null?void 0:_.startsWith(o)})||m[0];y&&this.applyOptionToDropdown(e,y)}e.querySelectorAll(".custom-dropdown__option[data-languages]").length>1&&e.classList.remove("is-hidden");const c=e.getAttribute("name"),h=c?.split("-").at(-1),p=e.querySelector(".custom-dropdown__option.selected")||e.querySelector(".custom-dropdown__option"),g=p?.getAttribute("data-value");if(!c||!g)return;const u={detail:{name:`region-${h}`,value:g||""}};this.handleRegionChange(u)}})}handleFormSubmit(t){t.preventDefault();const o=this.querySelector('uwp-custom-dropdown[name="country"]');let s="",n="",r="",l="";if(o){const a=o.querySelector(".custom-dropdown__option.selected");if(a){s=a.getAttribute("data-value")||"";const e=this.localizationForm.querySelector(`.localization-ui__form-select[name="region-${s}"]`);let d="";if(e){const i=e.querySelector(".localization-ui__country.selected");r=i?.getAttribute("data-value")||"";const c=i?.getAttribute("data-languages");if(!c)return;const h=c?.split("|").map(u=>u.replace(/"/g,""));h?.length===1&&(l=h[0]);const p=this.localizationForm.querySelector(`.localization-ui__form-select[name='language-${r}']`),g=p?.querySelector(".localization-ui__country.selected");d=g?.getAttribute("data-url")||"",l=g?.getAttribute("data-value")||""}if(!d){const i=this.localizationForm.querySelector(`.single-language-region[name='language-${r}']`);d=i?.getAttribute("data-url")||"",l=i?.getAttribute("data-value")||""}if(n=d,window.location.pathname.includes("/products")){const i=window.location.pathname.substring(window.location.pathname.indexOf("/products"));n=`${n}${i}`}}}if(s&&r&&l){this.setLocaleChoiceCookie({country:s,region:r,language:l});const a=this.localizationForm,e=a.querySelector('input[name="country_code"]');if(e&&this.selectedRegion){e.value=this.selectedRegion;const d=new FormData(a);d.set("country_code",this.selectedRegion);const i=new URLSearchParams;d.forEach((c,h)=>{typeof c=="string"&&i.append(h,c)}),fetch(a.action||"/localization",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded; charset=UTF-8",Accept:"*/*"},body:i.toString(),credentials:"include"}).catch(()=>{}).finally(()=>{n?location.href=n:location.reload()});return}return}}async checkUserLocaleOnLoad(){const t=await S();if(!t)return;const o=t.detected_values.country.handle,s=C("localization-choice"),n=this.stores.find(a=>a.url===this.currentDomain)||this.stores[0];if(s){const a=s.split("-"),e=a[0],d=a[1],i=a[2];this.countryChoice=e,this.regionChoice=d,this.languageChoice=i,e&&d&&i&&this.setSelectedOptions({country:e,region:d,language:i})}if(o===this.currentMarket)return;const r=s?.split("-")[0]??"";if(s&&r===n.name)return;const l=this.getUserCountryName(t.detected_values.country.name);if(l&&!s){this.initialCountry=l,this.initialRegion=t.detected_values.country.name;const a=this.localizationForm.querySelector(`.localization-ui__form-select[name="region-${this.initialCountry}"]`),e=a?.querySelector(`.localization-ui__country.custom-dropdown__option[data-value="${this.initialRegion}"]`),i=(e?.getAttribute("data-languages")||"").split("|").map(c=>c.replace(/"/g,"")).filter(Boolean);this.initialLanguage=i.length?i[0]:"English",this.setSelectedOptions({country:this.initialCountry,region:this.initialRegion,language:this.initialLanguage}),L({eventName:"modal:show:localization",action:"dispatch"}),this.showSettingsUi()}}getUserCountryName(t){return this.stores.map(({name:s})=>s).includes(t)?t:t==="Mexico"?"United States":"Europe"}persistCurrentSelection(){this.stores.find(o=>o.url===this.currentDomain)&&this.setLocaleChoiceCookie({country:this.countryChoice,region:this.regionChoice,language:this.languageChoice})}setSelectedOptions({country:t,region:o,language:s}){const n=this.querySelector('uwp-custom-dropdown[name="country"]');if(n){const r=n.querySelectorAll(".custom-dropdown__option"),l=Array.from(r);
1l.forEach(e=>{e.classList.remove("selected")});const a=l.find(e=>e.getAttribute("data-value")===t);a&&(this.applyOptionToDropdown(n,a),this.handleCountryChange({detail:{name:"country",value:t}},o),this.handleRegionChange({detail:{name:`region-${t}`,value:o}},s))}}showSettingsUi(){const t=this.querySelector('[js-localization-ui="choice"]');t&&(t.classList.add("is-hidden"),t.setAttribute("aria-hidden","true"));const o=this.querySelector('[js-localization-ui="settings"]');o&&(o.classList.remove("is-hidden"),o.removeAttribute("aria-hidden")),this.localizationForm.classList.remove("is-hidden")}setLocaleChoiceCookie({country:t,region:o,language:s}){let n="";t&&o&&s?n+=`${t}-${o}-${s}`:n+=`${this.initialCountry}-${this.initialRegion}-${this.initialLanguage}`,w("localization-choice",n,this.persistDays,void 0,"ooni.com",!0,"None")}}customElements.define("uwp-localization-ui",A);
2//# sourceMappingURL=/cdn/shop/t/621/assets/__vite-localization-ui.CZ12VAAu.js.map

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.