PageSourceSearch

https://upsidedrinks.ca/cdn/shop/t/177/assets/ecomific-shopping-location.js?v=176571354023962957761790797252

js upsidedrinks.ca collected 2026-10-01 15:46:41 UTC 34,303 bytes, 2 lines download raw bytes

1(function(){"use strict";if(window.__ECOMIFIC_SHOPPING_LOCATION_INIT__)return;window.__ECOMIFIC_SHOPPING_LOCATION_INIT__=!0;var COOKIE_NAME="ecomific_shopping_location",DEFAULT_LOCATION="QC",VALID_LOCATIONS=["AB","BC","MB","NB","NL","NS","ON","PE","QC","SK","TERRITORIES","US"],WEST=["BC","AB","MB","SK"],SOURCE_COOKIE="ecomific_shopping_location_source",SOURCE_MANUAL="manual",SOURCE_LIQUID="liquid",SOURCE_DEFAULT="default",SOURCE_GEO="geo",SOURCE_HANDOFF="handoff",WEST_FALLBACK="BC",CA_HOSTS=["upsidedrinks.ca","www.upsidedrinks.ca"],COM_HOSTS=["upsidedrinks.com","www.upsidedrinks.com"],LABELS={QC:"Qu\xE9bec",ON:"Ontario",BC:"British Columbia",AB:"Alberta",MB:"Manitoba",SK:"Saskatchewan",NB:"New Brunswick",NS:"Nova Scotia",PE:"Prince Edward Island",NL:"Newfoundland & Labrador",TERRITORIES:"Territories (YT/NT/NU)",US:"United States"},COOKIE_MAX_AGE_DAYS=365,DROPDOWN_OPEN_CLASS="is-open",REGION_STATE_SELECTOR="#ecomific-region-state, script[data-ecomific-region-state]",GEO_ATTEMPT_KEY="ecomific_geo_attempt_ts",GEO_ATTEMPT_COOLDOWN_MS=300*1e3,PREVIEW_THEME_KEY="ecomific_preview_theme_id",REDIRECT_LOCK_KEY="ecomific_domain_redirect_lock",REDIRECT_LOCK_MS=1e4,LAST_CA_LOCATION_KEY="ecomific_last_ca_location",RETURN_CA_PARAM="ecomific_return_ca",SHOPIFY_COUNTRY_SYNC_KEY="ecomific_shopify_country_sync",SHOPIFY_COUNTRY_SYNC_MS=5e3,SHOPPING_LOCATION_CHANGED_EVENT="ecomific:shopping-location:changed",LOG_NS="ecomific",MODULE="shopping-location",BOT_RE=/bot\b|crawler|spider|crawling|googlebot|adsbot-google|storebot-google|googleother|google-inspectiontool|google-adwords-instant|mediapartners-google|bingbot|bingpreview|msnbot|adidxbot|duckduckbot|slurp|baiduspider|yandexbot|applebot|semrushbot|ahrefsbot|facebookexternalhit|linkedinbot|headlesschrome|lighthouse|pagespeed|selenium|puppeteer|playwright/i;if(window.ecomificShoppingLocation&&window.ecomificShoppingLocation.initialized)return;var currentLocation=null,currentRegion=null,locationSource=SOURCE_DEFAULT,root=null,dropdown=null,trigger=null,labelEl=null,uiController=null,currencyControllers=[];function isDebugEnabled(){if(typeof window=="undefined")return!1;if(window.ecomificDebug===!0||window.__ecomificDebug===!0)return!0;try{if(window.localStorage&&window.localStorage.getItem("ecomific_debug")==="1")return!0}catch(e){}try{if(window.location&&window.location.search){var params=new URLSearchParams(window.location.search);if(params.has("ecomificDebug"))return!0}}catch(e){}return!1}function isBotLikeVisitor(){var ua=typeof navigator!="undefined"&&navigator.userAgent||"";return BOT_RE.test(ua)}function fmt(level,msg){return"["+LOG_NS+"]["+level+"] "+MODULE+": "+msg}function logDebug(msg){if(isDebugEnabled()&&typeof console!="undefined"&&console.debug){var args=Array.prototype.slice.call(arguments,1);args.unshift(fmt("debug",msg)),console.debug.apply(console,args)}}function logInfo(msg){if(isDebugEnabled()&&typeof console!="undefined"&&console.info){var args=Array.prototype.slice.call(arguments,1);args.unshift(fmt("info",msg)),console.info.apply(console,args)}}function logWarn(msg){if(typeof console!="undefined"&&console.warn){var args=Array.prototype.slice.call(arguments,1);args.unshift(fmt("warn",msg)),console.warn.apply(console,args)}}function logError(msg){if(typeof console!="undefined"&&console.error){var args=Array.prototype.slice.call(arguments,1);args.unshift(fmt("error",msg)),console.error.apply(console,args)}}function getPinnedPreviewThemeId(){try{return window.sessionStorage&&window.sessionStorage.getItem(PREVIEW_THEME_KEY)||""}catch(e){return""}}function pinPreviewThemeIdFromUrl(url){try{var id=url&&url.searchParams?url.searchParams.get("preview_theme_id"):"";id&&window.sessionStorage&&window.sessionStorage.setItem(PREVIEW_THEME_KEY,id)}catch(e){}}function ensurePreviewThemeId(url){try{if(!url||!url.searchParams)return;var existing=url.searchParams.get("preview_theme_id");if(existing)return;var pinned=getPinnedPreviewThemeId();!pinned&&typeof window.__ECOMIFIC_PREVIEW_THEME_ID__=="string"&&(pinned=window.__ECOMIFIC_PREVIEW_THEME_ID__),pinned&&url.searchParams.set("preview_theme_id",pinned)}catch(e){}}function readRedirectLock(){try{var raw=window.sessionStorage&&window.sessionStorage.getItem(REDIRECT_LOCK_KEY);return raw?JSON.parse(raw):null}catch(e){return null}}function isRedirectLocked(fromOrigin,toOrigin,path){var lock=readRedirectLock();return!(!lock||Date.now()-(lock.ts||0)>REDIRECT_LOCK_MS||lock.from!==fromOrigin||lock.to!==toOrigin||lock.path&&path&&lock.path!==path)}function normalizeLocation(value){if(typeof value!="string")return null;var upper=value.trim().toUpperCase();return VALID_LOCATIONS.indexOf(upper)!==-1?upper:null}function normalizeRegion(value){if(typeof value!="string")return null;var normalized=value.trim().toLowerCase();return normalized==="east"||normalized==="west"?normalized:null}function normalizeSource(value){return value===SOURCE_MANUAL||value===SOURCE_LIQUID||value===SOURCE_DEFAULT||value===SOURCE_G
1EO||value===SOURCE_HANDOFF?value:null}function sourceToken(value){if(typeof value!="string")return"";var normalized=value.trim().toLowerCase();if(!normalized)return"";var idx=normalized.lastIndexOf(":");return idx===-1?normalized:normalized.slice(idx+1)}function isCaHost(){if(typeof window=="undefined"||!window.location||!window.location.hostname)return!1;var h=window.location.hostname.toLowerCase();return h==="upsidedrinks.ca"||h==="www.upsidedrinks.ca"}function isComHost(){if(typeof window=="undefined"||!window.location||!window.location.hostname)return!1;var h=window.location.hostname.toLowerCase();return h==="upsidedrinks.com"||h==="www.upsidedrinks.com"}function getCaOrigin(){var protocol=typeof window!="undefined"&&window.location&&window.location.protocol?window.location.protocol:"https:";return protocol+"//upsidedrinks.ca"}function getComOrigin(){var protocol=typeof window!="undefined"&&window.location&&window.location.protocol?window.location.protocol:"https:";return protocol+"//upsidedrinks.com"}function getLocationStateFromCookies(){var location=normalizeLocation(getCookie(COOKIE_NAME)),normalizedSource=normalizeSource(getCookie(SOURCE_COOKIE));return{location:location,source:normalizedSource}}function setLocationCookies(locationCode,source){if(locationCode){var normalizedSource=normalizeSource(source)||SOURCE_DEFAULT;setCookie(COOKIE_NAME,locationCode),setCookie(SOURCE_COOKIE,normalizedSource),locationCode!=="US"&&persistLastCanadianLocation(locationCode),locationSource=normalizedSource}}function persistLastCanadianLocation(locationCode){var normalized=normalizeLocation(locationCode);if(!(!normalized||normalized==="US"))try{window.localStorage&&window.localStorage.setItem(LAST_CA_LOCATION_KEY,normalized)}catch(e){}}function getLastCanadianLocation(){try{var stored=window.localStorage&&window.localStorage.getItem(LAST_CA_LOCATION_KEY),normalizedStored=normalizeLocation(stored);if(normalizedStored&&normalizedStored!=="US")return normalizedStored}catch(e){}var cookieState=getLocationStateFromCookies();if(cookieState.location&&cookieState.location!=="US")return cookieState.location;if(currentLocation&&currentLocation!=="US")return currentLocation;var browserFallback=deriveBrowserFallbackLocation();return browserFallback&&browserFallback!=="US"?browserFallback:DEFAULT_LOCATION}function getReturnCanadianLocationFromUrl(){if(typeof window=="undefined"||!window.location||!window.location.search)return null;try{var params=new URLSearchParams(window.location.search);return normalizeLocation(params.get(RETURN_CA_PARAM))}catch(e){return null}}function getExpectedShopifyCountry(locationCode){return normalizeLocation(locationCode)==="US"?"US":"CA"}function readShopifyCountrySyncLock(){try{var raw=window.sessionStorage&&window.sessionStorage.getItem(SHOPIFY_COUNTRY_SYNC_KEY);return raw?JSON.parse(raw):null}catch(e){return null}}function writeShopifyCountrySyncLock(countryCode){try{window.sessionStorage&&window.sessionStorage.setItem(SHOPIFY_COUNTRY_SYNC_KEY,JSON.stringify({country:countryCode,host:window.location.hostname,ts:Date.now()}))}catch(e){}}function isShopifyCountrySyncLocked(countryCode){var lock=readShopifyCountrySyncLock();return!lock||lock.country!==countryCode||lock.host!==window.location.hostname?!1:Date.now()-(lock.ts||0)<SHOPIFY_COUNTRY_SYNC_MS}function findLocalizationFormForCountry(){var inputs=document.querySelectorAll('[data-disclosure-form] input[name="country_code"][data-disclosure-input]');if(!inputs||!inputs.length)return null;for(var i=0;i<inputs.length;i+=1){var input=inputs[i],form=input.closest("[data-disclosure-form]");if(form)return{form:form,input:input}}return null}function syncShopifyCountryState(locationCode){var expectedCountry=getExpectedShopifyCountry(locationCode),localization=findLocalizationFormForCountry();if(!localization||!localization.form||!localization.input||String(localization.input.value||"").toUpperCase()===expectedCountry||isShopifyCountrySyncLocked(expectedCountry))return Promise.resolve(!1);var formData=new FormData(localization.form);return formData.set("country_code",expectedCountry),writeShopifyCountrySyncLock(expectedCountry),fetch(localization.form.getAttribute("action")||window.location.pathname+window.location.search,{method:"POST",body:formData,credentials:"same-origin",redirect:"follow",headers:{"X-Requested-With":"XMLHttpRequest"}}
1).then(function(){return localization.input.value=expectedCountry,logInfo("shopify country synced",{expectedCountry:expectedCountry,location:locationCode,host:window.location.hostname}),!0}).catch(function(error){return logWarn("Could not sync Shopify country state",{expectedCountry:expectedCountry,location:locationCode,message:error&&error.message}),!1})}function defaultLocationForRegion(region){return region==="west"?WEST_FALLBACK:DEFAULT_LOCATION}function fetchGeoFromEndpoint(timeoutMs){var url=window.ECOMIFIC_GEO_ENDPOINT_URL;if(!url)return Promise.resolve(null);try{var controller=typeof AbortController!="undefined"?new AbortController:null,timer=null;return controller&&(timer=setTimeout(function(){controller.abort()},typeof timeoutMs=="number"?timeoutMs:700)),fetch(url,{method:"GET",credentials:"omit",cache:"no-store",signal:controller?controller.signal:void 0}).then(function(res){return timer&&clearTimeout(timer),res.ok?res.json().catch(function(){return null}):null}).catch(function(){return null})}catch(e){return Promise.resolve(null)}}function normalizeEndpointGeo(payload){if(!payload||typeof payload!="object")return null;var regionCode=payload.region?String(payload.region).toUpperCase():null;return regionCode?{location:regionCode,source:SOURCE_GEO}:null}function parseRegionLiquidState(){var el=document.querySelector(REGION_STATE_SELECTOR);if(!el)return null;try{return JSON.parse(el.textContent||"{}")||null}catch(error){return logWarn("Failed to parse region state JSON",error),null}}function deriveDefaultLocationFromLiquid(){var state=parseRegionLiquidState();if(!state||!state.default_province_code)return{location:null,loggedIn:!1};var code=String(state.default_province_code).trim().toUpperCase();return{location:normalizeLocation(code),loggedIn:!!state.customer_logged_in}}function getBrowserLocaleCountry(){try{var locale=typeof navigator!="undefined"&&(navigator.language||navigator.languages&&navigator.languages[0])||"",match=String(locale).match(/-([A-Za-z]{2})$/);return match?match[1].toUpperCase():null}catch(e){return null}}function getBrowserTimeZone(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone||""}catch(e){return""}}function deriveBrowserFallbackLocation(){var timeZone=String(getBrowserTimeZone()||""),localeCountry=getBrowserLocaleCountry();if(timeZone){if(timeZone==="America/Vancouver"||timeZone==="America/Dawson"||timeZone==="America/Fort_Nelson")return"BC";if(timeZone==="America/Edmonton")return"AB";if(timeZone==="America/Regina"||timeZone==="America/Swift_Current")return"SK";if(timeZone==="America/Winnipeg"||timeZone==="America/Rainy_River")return"MB";if(timeZone==="America/Whitehorse"||timeZone==="America/Inuvik"||timeZone==="America/Yellowknife"||timeZone==="America/Cambridge_Bay")return"TERRITORIES";if(timeZone==="America/St_Johns"||timeZone==="America/Goose_Bay"||timeZone==="America/Blanc-Sablon")return"NL";if(timeZone==="America/Halifax"||timeZone==="America/Glace_Bay")return"NS";if(timeZone==="America/Moncton")return"NB";if(timeZone==="America/Toronto"||timeZone==="America/Nipigon"||timeZone==="America/Thunder_Bay")return localeCountry==="CA"&&String(navigator&&navigator.language||"").toLowerCase().indexOf("fr")===0?"QC":"ON"}if(localeCountry==="US")return"US";if(localeCountry==="CA"){try{var locale=String(navigator&&(navigator.language||navigator.languages&&navigator.languages[0])||"").toLowerCase();if(locale.indexOf("fr")===0)return"QC"}catch(e){}return"ON"}return null}function getGeoSeedLocation(){var geo=window.ecomificGeo;if(!geo||typeof geo!="object")return null;if(geo.location)return normalizeLocation(String(geo.location));if(geo.region){var r=normalizeRegion(String(geo.region));if(r)return defaultLocationForRegion(r)}return null}function locationToRegion(locationCode){var code=normalizeLocation(locationCode);return code?WEST.indexOf(code)!==-1?"west":"east":null}function geoDebugEnabled(){return isDebugEnabled()}function getCookie(name){if(typeof document=="undefined")return null;var pattern="; "+document.cookie,parts=pattern.split("; "+name+"=");return parts.length<2?null:parts.pop().split(";").shift()}function setCookie(name,value){if(typeof document!="undefined"){var expires=new Date;expires.setDate(expires.getDate()+COOKIE_MAX_AGE_DAYS),document.cookie=name+"="+encodeURIComponent(value)+"; Expires="+expires.toUTCString()+"; Path=/; SameSite=Lax"}}function getGeoCooldownTs(){if(typeof window=="undefined")return null;var raw=null;try{window.sessionStorage&&(raw=window.sessionStorage.getItem(GEO_ATTEMPT_KEY))}catch(error){raw=null}if(raw===null)try{window.localStorage&&(raw=window.localStorage.getItem(GEO_ATTEMPT_KEY))}catch(error){raw=null}if(raw===null)return null;var ts=Number(raw);return isFinite(ts)?ts:null}function setGeoCooldownTs(ts){if(typeof window!="undefined"&&!(typeof ts!="number"||!isFinite(ts))){var value=String(ts),stored=!1;try{window.sessionStorage&&(window.sessionStorage.setItem(GEO_ATTEMPT_KEY,value),stored=!0)}catch(error){}if(!stored)try{window.localStorage&&window.localStorage.setItem(GEO_ATTEMPT_KEY,value)}catch(error){}}}function clearGeoCooldownTs(){if(typeof window!="undefined"){try{window.sessionStorage&&window.sessionStorage.removeItem(GEO_ATTEMPT_KEY)}catch(error){}try{window.localStorage&&window.localStorage.removeItem(GEO_ATTEMPT_KEY)}catch(error){}}}function ensureShoppingLocation(){var cookieState=getLocationStateFromCookies(),cookieLocation=cookieState.location,cookieSource=normalizeSource(cookieState.source)||SOURCE_DEFAULT,liquidInfo=deriveDefaultLocationFromLiquid(),liquidLocation=liquidInfo.location,liquidLoggedIn=liquidInfo.loggedIn;if(cookieLocation)return locationSource=cookieSource,setCookie(SOURCE_COOKIE,locationSource),cookieLocation;if(liquidLoggedIn&&liquidLocation)return setLocationCookies(liquidLocation,SOURCE_LIQUID),liquidLocation;var geoLocation=getGeoSeedLocation();if(!liquidLoggedIn&&geoLocation)return setLocationCookies(geoLocation,SOURCE_GEO),geoLocation;var browserFallbackLocation=deriveBrowserFallbackLocation();return!liquidLoggedIn&&browserFallbackLocation?(setLocationCookies(browserFallbackLocation,SOURCE_DEFAULT),browserFallbackLocation):(setLocationCookies(DEFAULT_LOCATION,SOURCE_DEFAULT),DEFAULT_LOCATION)}function maybeSeedFromGeoEndpoint(timeoutMs){var debug=geoDebugEnabled(),start=Date.now(),cookieState=getLocationStateFromCookies(),cookieLocation=cookieState.location,cookieSource=normalizeSource(cookieState.source);function failWithCooldown(reason,extra){if(debug){var info={reason:reason};if(extra&&typeof extra=="object")for(var key in extra)Object.prototype.hasOwnProperty.call(extra,key)&&(info[key]=extra[key]);logInfo("geo skip",info)}return setGeoCooldownTs(Date.now()),!1}if(debug&&logInfo("geo start",{endpoint:window.ECOMIFIC_GEO_ENDPOINT_URL||null,timeoutMs:timeoutMs,existingLocationCookie:cookieLocation||null,existingSourceCookie:cookieSource||null}),cookieLocation&&cookieSource&&cookieSource!==SOURCE_DEFAULT)return debug&&logInfo("geo skip",{reason:"cookie-authoritative",source:cookieSource}),Promise.resolve(!1);var liquidState=parseRegionLiquidState();if(liquidState&&liquidState.customer_logged_in)return debug&&logInfo("geo skip",{reason:"customer-logged-in"}),Promise.resolve(!1);
1var endpoint=typeof window.ECOMIFIC_GEO_ENDPOINT_URL=="string"?window.ECOMIFIC_GEO_ENDPOINT_URL.trim():"";if(!endpoint)return debug&&logInfo("geo skip",{reason:"no-endpoint"}),Promise.resolve(!1);var lastAttemptTs=getGeoCooldownTs();if(lastAttemptTs!==null){var elapsedSinceLastAttempt=Date.now()-lastAttemptTs;if(elapsedSinceLastAttempt<GEO_ATTEMPT_COOLDOWN_MS){if(debug){var remainingMs=GEO_ATTEMPT_COOLDOWN_MS-elapsedSinceLastAttempt;logInfo("geo skip",{reason:"cooldown",remainingMs:remainingMs,remainingSeconds:Math.ceil(remainingMs/1e3)})}return Promise.resolve(!1)}}return setGeoCooldownTs(Date.now()),fetchGeoFromEndpoint(timeoutMs).then(function(payload){if(debug&&logInfo("geo response",{elapsedMs:Date.now()-start,payload:payload||null}),payload&&payload.debug&&payload.debug.error)return failWithCooldown("debug-error",{error:payload.debug.error,upstreamStatus:payload.debug.upstreamStatus||null});if(!payload||!payload.region)return failWithCooldown("missing-region");var normalized=normalizeEndpointGeo(payload);if(!normalized)return failWithCooldown("invalid-payload");window.ecomificGeo=normalized;var seeded=getGeoSeedLocation();if(seeded){debug&&logInfo("geo cookies-before",{location:cookieLocation||null,source:cookieSource||null}),setLocationCookies(seeded,SOURCE_GEO);try{localStorage.setItem("ecomific_geo_seeded","1")}catch(e){}return currentRegion=locationToRegion(seeded)||"east",currentLocation=seeded,clearGeoCooldownTs(),debug&&logInfo("geo seeded",{location:getCookie(COOKIE_NAME),source:getCookie(SOURCE_COOKIE),elapsedMs:Date.now()-start}),!0}return failWithCooldown("getGeoSeedLocation-null")},function(error){return failWithCooldown("fetch-error",{message:error&&error.message})})}
1function dispatchRegionSetRequest(region,source){if(region){var locationCode=currentLocation||defaultLocationForRegion(region),country=locationCode==="US"?"us":"ca",province=locationCode&&locationCode!=="US"?locationCode:"",requestedSource=sourceToken(source)||SOURCE_MANUAL;logInfo("dispatch set-request",{region:region,source:requestedSource,location:locationCode,country:country,province:province||""});try{window.dispatchEvent(new CustomEvent("ecomific:region:set-request",{detail:{region:region,country:country,province:province||"",source:requestedSource}}))}catch(error){logWarn("ecomific:region:set-request dispatch threw",error)}}}function updateLabel(labelEl2,locationCode){if(labelEl2){var label=LABELS[locationCode]||LABELS[DEFAULT_LOCATION]||locationCode||"";labelEl2.textContent=label}}function getCurrencyCountryForLocation(locationCode){return normalizeLocation(locationCode)==="US"?"US":"CA"}function updateCurrencyUI(rootEl,locationCode){if(rootEl){var countryCode=getCurrencyCountryForLocation(locationCode),labelNode=rootEl.querySelector("[data-ecomific-currency-label]"),flagNode=rootEl.querySelector("[data-ecomific-currency-flag]"),activeOption=rootEl.querySelector('[data-ecomific-currency-option][data-country-code="'+countryCode+'"]');if(labelNode&&activeOption){var optionLabel=activeOption.querySelector("[data-ecomific-currency-option-label]");labelNode.textContent=optionLabel?optionLabel.textContent.trim():activeOption.textContent.trim()}flagNode&&(flagNode.classList.remove("currency-flag--ca"),flagNode.classList.remove("currency-flag--us"),flagNode.classList.add("currency-flag--"+countryCode.toLowerCase()));for(var items=rootEl.querySelectorAll("[data-ecomific-currency-item]"),i=0;i<items.length;i+=1){var option=items[i].querySelector("[data-ecomific-currency-option]"),isCurrent=!!option&&option.getAttribute("data-country-code")===countryCode;items[i].classList.toggle("disclosure-list__item--current",isCurrent),option&&(isCurrent?option.setAttribute("aria-current","true"):option.removeAttribute("aria-current"))}}}function closeDropdown(root2,dropdown2,trigger2){dropdown2&&(dropdown2.hidden=!0,root2&&root2.classList.remove(DROPDOWN_OPEN_CLASS),trigger2&&trigger2.setAttribute("aria-expanded","false"))}function openDropdown(root2,dropdown2,trigger2){dropdown2&&(dropdown2.hidden=!1,root2&&root2.classList.add(DROPDOWN_OPEN_CLASS),trigger2&&trigger2.setAttribute("aria-expanded","true"))}function toggleDropdown(root2,dropdown2,trigger2){if(dropdown2){var isHidden=dropdown2.hidden!==!1;isHidden?openDropdown(root2,dropdown2,trigger2):closeDropdown(root2,dropdown2,trigger2)}}var OPTION_SELECTED_CLASS="ecomific-shopping-location__option--selected";function setRootAttrs(root2,locationCode,region,source){if(root2){root2.setAttribute("data-location-code",locationCode||""),root2.setAttribute("data-region",region||""),root2.setAttribute("data-location-source",source||"");var drop=root2.querySelector("[data-ecomific-shopping-location-dropdown]");if(drop&&locationCode)for(var opts=drop.querySelectorAll("[data-location-code]"),i=0;i<opts.length;i++){var isSelected=opts[i].getAttribute("data-location-code")===locationCode;opts[i].classList.toggle(OPTION_SELECTED_CLASS,isSelected),opts[i].setAttribute("aria-selected",isSelected?"true":"false"),isSelected?opts[i].setAttribute("data-active","true"):opts[i].removeAttribute("data-active")}}}function setReady(){root&&(root.dataset.ready="true",root.setAttribute("aria-busy","false"))}function bindUI(root2){if(!root2||(trigger=root2.querySelector("[data-ecomific-shopping-location-trigger]"),dropdown=root2.querySelector("[data-ecomific-shopping-location-dropdown]"),labelEl=root2.querySelector("[data-ecomific-shopping-location-label]"),!trigger||!dropdown))return null;var isOpen=!1;function handleDocumentClick(event){isOpen&&(root2.contains(event.target)||closeDropdown2())}function handleKeydown(event){isOpen&&(event.key==="Escape"||event.key==="Esc")&&closeDropdown2()}function openDropdown2(){dropdown&&(dropdown.hidden=!1,root2.classList.add(DROPDOWN_OPEN_CLASS),trigger.setAttribute("aria-expanded","true"),document.addEventListener("click",handleDocumentClick),document.addEventListener("keydown",handleKeydown),isOpen=!0)}function closeDropdown2(){dropdown&&(dropdown.hidden=!0,root2.classList.remove(DROPDOWN_OPEN_CLASS),trigger.setAttribute("aria-expanded","fal
1se"),document.removeEventListener("click",handleDocumentClick),document.removeEventListener("keydown",handleKeydown),isOpen=!1)}function toggleDropdown2(){dropdown.hidden!==!1?openDropdown2():closeDropdown2()}return updateLabel(labelEl,currentLocation),setRootAttrs(root2,currentLocation,currentRegion,locationSource),trigger.setAttribute("aria-expanded",trigger.getAttribute("aria-expanded")||"false"),trigger.addEventListener("click",function(event){event.preventDefault(),toggleDropdown2()}),dropdown.addEventListener("click",function(event){var option=event.target?event.target.closest("[data-location-code]"):null;if(option){event.preventDefault(),closeDropdown2();var code=option.getAttribute("data-location-code");if(code){var normalizedCode=normalizeLocation(code);normalizedCode&&selectLocation(normalizedCode)}}}),{close:closeDropdown2,updateLabel:function(locationCode){updateLabel(labelEl,locationCode)}}}function bindCurrencyUI(){var rootEls=document.querySelectorAll("[data-ecomific-currency-switcher]");if(!rootEls||!rootEls.length)return[];var controllers=[];function closeAllCurrencyDropdowns(exceptRoot){Array.prototype.forEach.call(document.querySelectorAll("[data-ecomific-currency-switcher]"),function(switcher){if(!(exceptRoot&&switcher===exceptRoot)){var list=switcher.querySelector("[data-ecomific-currency-list]"),toggle=switcher.querySelector("[data-ecomific-currency-trigger]");list&&(list.hidden=!0,list.classList.remove("disclosure-list--visible")),toggle&&toggle.setAttribute("aria-expanded","false"),switcher.classList.remove(DROPDOWN_OPEN_CLASS)}})}return window.__ECOMIFIC_CURRENCY_DELEGATED__||(document.addEventListener("click",function(event){var option=event.target&&event.target.closest?event.target.closest("[data-ecomific-currency-option]"):null;if(option){event.preventDefault();var optionRoot=option.closest("[data-ecomific-currency-switcher]");closeAllCurrencyDropdowns();var countryCode=String(option.getAttribute("data-country-code")||"").trim().toUpperCase();if(countryCode==="US"){selectLocation("US");return}countryCode==="CA"&&selectLocation(getLastCanadianLocation());return}var trigger2=event.target&&event.target.closest?event.target.closest("[data-ecomific-currency-trigger]"):null;if(trigger2){event.preventDefault();var root2=trigger2.closest("[data-ecomific-currency-switcher]"),list=root2&&root2.querySelector("[data-ecomific-currency-list]");if(!root2||!list)return;var willOpen=list.hidden!==!1;closeAllCurrencyDropdowns(willOpen?root2:null),list.hidden=!willOpen,list.classList.toggle("disclosure-list--visible",willOpen),trigger2.setAttribute("aria-expanded",willOpen?"true":"false"),root2.classList.toggle(DROPDOWN_OPEN_CLASS,willOpen);return}closeAllCurrencyDropdowns()},!0),document.addEventListener("keydown",function(event){(event.key==="Escape"||event.key==="Esc")&&closeAllCurrencyDropdowns()}),window.__ECOMIFIC_CURRENCY_DELEGATED__=!0),Array.prototype.forEach.call(rootEls,function(rootEl){var triggerEl=rootEl.querySelector("[data-ecomific-currency-trigger]"),listEl=rootEl.querySelector("[data-ecomific-currency-list]");if(!triggerEl||!listEl)return;function closeCurrencyDropdown(){listEl.hidden=!0,listEl.classList.remove("disclosure-list--visible"),triggerEl.setAttribute("aria-expanded","false"),rootEl.classList.remove(DROPDOWN_OPEN_CLASS)}updateCurrencyUI(rootEl,currentLocation),triggerEl.setAttribute("aria-expanded","false"),controllers.push({close:closeCurrencyDropdown,update:function(locationCode){updateCurrencyUI(rootEl,locationCode)}})}),controllers}function redirectToLocation(targetOrigin,normalizedCode){if(isBotLikeVisitor()){logInfo("cross-domain redirect suppressed for bot-like visitor",{targetOrigin:targetOrigin,location:normalizedCode});return}var currentUrl=new URL(window.location.href);pinPreviewThemeIdFromUrl(currentUrl);var pathname=currentUrl.pathname||"/",params=new URLSearchParams(currentUrl.search||"");params.set("ecomific_location",normalizedCode),normalizedCode==="US"&&currentLocation&&currentLocation!=="US"?params.set(RETURN_CA_PARAM,currentLocation):params.delete(RETURN_CA_PARAM);var targetUrl=new URL(pathname+(params.toString()?"?"+params.toString():""),targetOrigin);ensurePreviewThemeId(targetUrl);var fromOrigin=window.location.origin,toOrigin=targetUrl.origin,path=window.location.pathname||"/";if(isRedirectLocked(fromOrigin,toOrigin,path)){logInfo("redirect blocked by lock",{from:fromOrigin,to:toOrigin,path:path});return}window.location.assign(targetUrl.toString())}function selectLocation(normalizedCode){if(normalizedCode){if(normalizedCode==="US"&&isCaHost()){redirectToLocation(getComOrigin(),"US");return}if(normalizedCode!=="US"&&isComHost()){redirectToLocation(getCaOrigin(),normalizedCode);return}
1var previousRegion=currentRegion,nextRegion=locationToRegion(normalizedCode)||"east",regionChanged=nextRegion!==previousRegion||normalizedCode!==currentLocation;logDebug("select",{code:normalizedCode,nextRegion:nextRegion,previousRegion:previousRegion,regionChanged:regionChanged}),currentLocation=normalizedCode,currentRegion=nextRegion,locationSource=SOURCE_MANUAL,setLocationCookies(currentLocation,SOURCE_MANUAL),reflectUI(),emitShoppingLocationChanged("manual"),regionChanged&&dispatchRegionSetRequest(nextRegion,"shopping-location:manual")}}function reflectUI(){setRootAttrs(root,currentLocation,currentRegion,locationSource),updateLabel(labelEl,currentLocation),currencyControllers.forEach(function(controller){controller&&controller.update&&controller.update(currentLocation)}),setReady(),syncShopifyCountryState(currentLocation)}function emitShoppingLocationChanged(reason){typeof window=="undefined"||!window.dispatchEvent||typeof window.CustomEvent=="undefined"||window.dispatchEvent(new CustomEvent(SHOPPING_LOCATION_CHANGED_EVENT,{detail:{location:currentLocation,region:currentRegion,source:locationSource,reason:reason||""}}))}function reconcileState(nextRegion,source){var cookieState=getLocationStateFromCookies(),cookieLocation=cookieState.location,cookieSource=normalizeSource(cookieState.source)||SOURCE_DEFAULT,normalizedRegion=normalizeRegion(nextRegion)||currentRegion||"east",incomingSource=normalizeSource(source);if(cookieLocation){currentLocation=cookieLocation,currentRegion=locationToRegion(currentLocation)||normalizedRegion||"east",cookieSource===SOURCE_MANUAL||locationSource===SOURCE_MANUAL?locationSource=SOURCE_MANUAL:cookieSource?locationSource=cookieSource:locationSource=locationSource||SOURCE_DEFAULT,setCookie(SOURCE_COOKIE,locationSource),reflectUI();return}var nextLocation=defaultLocationForRegion(normalizedRegion),nextSource=incomingSource||cookieSource||locationSource||SOURCE_DEFAULT;setLocationCookies(nextLocation,nextSource),currentRegion=normalizedRegion,currentLocation=nextLocation,reflectUI()}function handleRegionChanged(event){var detail=event&&event.detail||{};reconcileState(detail.region,detail.source),uiController&&typeof uiController.close=="function"&&uiController.close()}function handleRegionReady(event){var detail=event&&event.detail||{};reconcileState(detail.region,detail.source)}function resolveInitialLocation(timeoutMs){var cookieState=getLocationStateFromCookies(),cookieLocation=cookieState.location,cookieSource=normalizeSource(cookieState.source),endpointAvailable=typeof window.ECOMIFIC_GEO_ENDPOINT_URL=="string"&&window.ECOMIFIC_GEO_ENDPOINT_URL.trim()!=="",geoAllowed=!cookieLocation;if(logInfo("boot decision",{currentLocation:cookieLocation||null,currentSource:cookieSource||null,geoAllowed:geoAllowed,endpoint:endpointAvailable}),cookieLocation&&cookieSource&&cookieSource!==SOURCE_DEFAULT)return locationSource=cookieSource,setCookie(SOURCE_COOKIE,locationSource),Promise.resolve(cookieLocation);if(cookieLocation&&!cookieSource)return locationSource=SOURCE_DEFAULT,setCookie(SOURCE_COOKIE,locationSource),Promise.resolve(cookieLocation);var startWithCookie=!!cookieLocation,geoSeedPromise=Promise.resolve(!1);return geoAllowed&&endpointAvailable&&(geoSeedPromise=maybeSeedFromGeoEndpoint(timeoutMs)),geoSeedPromise.catch(function(){return!1}).then(function(seeded){if(seeded){var nextState=getLocationStateFromCookies(),nextLocation=nextState.location||currentLocation||cookieLocation;if(locationSource=normalizeSource(nextState.source)||SOURCE_GEO,nextLocation)return nextLocation}return startWithCookie&&cookieLocation?(locationSource=cookieSource||SOURCE_DEFAULT,setCookie(SOURCE_COOKIE,locationSource),cookieLocation):ensureShoppingLocation()}).catch(function(){return startWithCookie&&cookieLocation?(locationSource=cookieSource||SOURCE_DEFAULT,setCookie(SOURCE_COOKIE,locationSource),cookieLocation):ensureShoppingLocation()})}function runInit(initialLocation){var normalizedLocation=normalizeLocation(initialLocation);normalizedLocation||(normalizedLocation=ensureShoppingLocation()),currentLocation=normalizedLocation,currentRegion=locationToReg
1ion(currentLocation)||"east",root&&(uiController=bindUI(root)),window.addEventListener("ecomific:region:changed",handleRegionChanged),window.addEventListener("ecomific:region:ready",handleRegionReady),reflectUI(),dispatchRegionSetRequest(currentRegion,locationSource),root&&setTimeout(function(){root&&root.dataset.ready==="false"&&setReady()},1500),window.ecomificShoppingLocation={initialized:!0,getLocation:function(){return currentLocation},getRegion:function(){return currentRegion},getSource:function(){return locationSource},selectLocation:selectLocation},typeof window!="undefined"&&window.dispatchEvent&&typeof window.CustomEvent!="undefined"&&window.dispatchEvent(new CustomEvent("ecomific:shopping-location:ready",{detail:{location:currentLocation,region:currentRegion,source:locationSource}})),logInfo("Initialized with",currentLocation,"\u2192",currentRegion,"("+locationSource+")")}function getHandoffLocationFromUrl(){if(typeof window=="undefined"||!window.location||!window.location.search)return null;try{var params=new URLSearchParams(window.location.search),value=params.get("ecomific_location");return normalizeLocation(value)}catch(e){return null}}function applyHandoffAndStripParam(locationCode){var region=locationToRegion(locationCode)||"east";setLocationCookies(locationCode,SOURCE_HANDOFF),currentLocation=locationCode,currentRegion=region,locationSource=SOURCE_HANDOFF,dispatchRegionSetRequest
1(region,"shopping-location:handoff");try{var params=new URLSearchParams(window.location.search);params.delete("ecomific_location"),params.delete(RETURN_CA_PARAM);var newSearch=params.toString(),newUrl=window.location.pathname+(newSearch?"?"+newSearch:"")+(window.location.hash||"");window.history&&typeof window.history.replaceState=="function"&&window.history.replaceState(null,"",newUrl)}catch(e){logWarn("Could not strip ecomific_location param",e)}}function init(){if(!(window.ecomificShoppingLocation&&window.ecomificShoppingLocation.initialized)){root=document.querySelector("[data-ecomific-shopping-location-root]")||document.querySelector("[data-ecomific-shopping-location]"),currencyControllers=bindCurrencyUI();var returnLocation=getReturnCanadianLocationFromUrl();returnLocation&&returnLocation!=="US"&&persistLastCanadianLocation(returnLocation);var handoff=getHandoffLocationFromUrl();if(handoff){applyHandoffAndStripParam(handoff),runInit(handoff);return}var cookieState=getLocationStateFromCookies();resolveInitialLocation(2e3).then(function(location){runInit(location)}).catch(function(){runInit(ensureShoppingLocation())})}}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",init):init()})();
2//# sourceMappingURL=/cdn/shop/t/177/assets/ecomific-shopping-location.js.map?v=176571354023962957761790797252

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.