https://upsidedrinks.ca/cdn/shop/t/177/assets/ecomific-region-vari…?v=145926928771094934881790797251
1(function(){"use strict";if(window.__ECOMIFIC_REGION_VARIANT_SELECT__)return;window.__ECOMIFIC_REGION_VARIANT_SELECT__=!0;var REGION_KEY="ecomific_region",TIMEOUT_MS=4500,MAX_INFLIGHT=4,availCache={},inFlight={},fetchQueue=[],running=0;try{var style=document.createElement("style");style.setAttribute("data-ecomific-cascade-style","1"),style.textContent='[data-ecomific-cascade="pending"] .grid-product__notify-me,[data-ecomific-cascade="pending"] .klaviyo-bis-trigger{display:none !important;}',(document.head||document.documentElement).appendChild(style)}catch(e){}function getCookie(name){var m=document.cookie.match(new RegExp("(?:^|; )"+name+"=([^;]*)"));return m?decodeURIComponent(m[1]):""}function getRegion(){try{var ls=localStorage.getItem(REGION_KEY);if(ls)return ls.trim().toLowerCase()}catch(e){}return getCookie(REGION_KEY).trim().toLowerCase()}function getEndpoint(){var cfg=window.ecomificAvailabilityConfig&&typeof window.ecomificAvailabilityConfig=="object"?window.ecomificAvailabilityConfig:{},base=cfg.endpointBase||cfg.inventoryApiBase||"";if(!base||!/^https?:\/\//i.test(base))return"";var head=String(base).split(/[?#]/)[0].replace(/\/+$/,"");return/\/inventory$/.test(head)||(head+="/inventory"),head}function drain(){for(;running<MAX_INFLIGHT&&fetchQueue.length;){var job=fetchQueue.shift();running++,job().then(function(){running--,drain()})}}function throttled(task){return new Promise(function(resolve){fetchQueue.push(function(){return task().then(resolve,function(){resolve(null)})}),drain()})}function isAvailable(variantId,region,endpoint){var key=variantId+"|"+region;if(availCache[key]!==void 0)return Promise.resolve(availCache[key]);if(inFlight[key])return inFlight[key];var p=throttled(function(){var url=endpoint+"?variant_id="+encodeURIComponent(variantId)+"®ion="+encodeURIComponent(region),ac="AbortController"in window?new AbortController:null,timer=ac?setTimeout(function(){try{ac.abort()}catch(e){}},TIMEOUT_MS):null;return fetch(url,{credentials:"omit",signal:ac?ac.signal:void 0}).then(function(r){return r.json()}).then(function(j){var ok=!!(j&&j.ok===!0&&j.available===!0);return availCache[key]=ok,timer&&clearTimeout(timer),ok}).catch(function(){return timer&&clearTimeout(timer),null})}).then(function(v){return delete inFlight[key],v});return inFlight[key]=p,p}function selectOption(select,variantId){for(var i=0;i<select.options.length;i++)if(select.options[i].value==variantId)return select.selectedIndex!==i&&(select.selectedIndex=i,select.dispatchEvent(new Event("change",{bubbles:!0}))),!0;return!1}function snapshot(card,select){card.__ecomificOrigOpts||(card.__ecomificOrigOpts=Array.prototype.slice.call(select.options))}function restoreOptions(card,select){if(card.__ecomificOrigOpts){for(;select.options.length;)select.remove(0);for(var i=0;i<card.__ecomificOrigOpts.length;i++)select.appendChild(card.__ecomificOrigOpts[i]);select.disabled=!1}}function removeOption(select,opt){opt&&opt.parentNode===select&&select.removeChild(opt)}function soldOutLabel(card){var el=card.querySelector("[data-ecomific-sold-out-text]"),t=(el&&el.getAttribute("data-ecomific-sold-out-text")||"").trim();return t||"Sold Out"}function showSoldOut(card,select){for(var origOpts=card.__ecomificOrigOpts,firstId=origOpts&&origOpts[0]?origOpts[0].value:"";select.options.length;)select.remove(0);var o=document.createElement("option");o.value=firstId,o.textContent=soldOutLabel(card),o.selected=!0,select.appendChild(o),select.disabled=!0}function metafieldFallback(card,region,select){try{var raw=card.getAttribute("data-region-variants");if(!raw)return;var id=JSON.parse(raw)[region];id&&selectOption(select,id)}catch(e){}}function resolveCard(card,region,endpoint){if(card.__ecomificCascadeRegion===region)return;card.__ecomificCascadeRegion=region;var select=card.querySelector('select[name="id"]');if(!select||select.options.length<1){card.setAttribute("data-ecomific-cascade","done");return}if(select.options.length===1&&/coming soon/i.test(select.options[0].textContent||"")){card.setAttribute("data-ecomific-cascade","done");return}snapshot(card,select);var opts=Array.prototype.slice.call(select.options);card.setAttribute("data-ecomific-cascade","pending");var idx=0,selected=!1,removedAny=!1,sawUnknown=!1;function step(){if(idx>=opts.length){selected||(sawUnknown?(removedAny&&restoreOptions(card,select),metafieldFallback(card,region,select)):showSoldOut(card,select)),card.setAttribute("data-ecomific-cascade","done");return}var opt=opts[idx++];isAvailable(opt.value,region,endpoint).then(function(av){av===!1?(removeOption(select,opt),removedAny=!0):av===!0?selected||(selectOption(select,opt.value),selected=!0,card.setAttribute("data-ecomific-cascade","done")):sawUnknown=!0,step()})}step()}function run(root){var region=getRegion();if(!(region!=="east"&®ion!=="west")){var endpoint=getEndpoint(),cards=(root||document).querySelectorAll("[data-ecomific-product]");if(!endpoint){for(var i=0;i<cards.length;i++){var sel=cards[i].querySelector('select[name="id"]');sel&&metafieldFallback(cards[i],region,sel)}return}for(var k=0;k<cards.length;k++)resolveCard(cards[k],region,endpoint)}}if(window.addEventListener("ecomific:region:ready",function(){run()}),window.addEventListener("ecomific:region:changed",function(){for(var cards=document.querySelectorAll("[data-ecomific-product]"),i=0;i<cards.length;i++){cards[i].__ecomificCascadeRegion=null;var sel=cards[i].querySelector('select[name="id"]');sel&&restoreOptions(cards[i],sel)}run()}),typeof MutationObserver!="undefined"){var obs=new MutationObserver(function(muts){for(var i=0;i<muts.length;i++){var added=muts[i].addedNodes;if(added)for(var j=0;j<added.length;j++){var n=added[j];if(n.nodeType===1&&(n.matches&&n.matches("[data-ecomific-product]")||n.querySelector&&n.querySelector("[data-ecomific-product]"))){run(n.parentElement||document);return}}}});document.body?obs.observe(document.body,{childList:!0,subtree:!0}):document.addEventListener("DOMContentLoaded",function(){obs.observe(document.body,{childList:!0,subtree:!0})})}function onReady(){run()}document.addEventListener("DOMContentLoaded",onReady),document.readyState!=="loading"&&onReady()})();
2//# sourceMappingURL=/cdn/shop/t/177/assets/ecomific-region-variant-select.js.map?v=145926928771094934881790797251
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.