PageSourceSearch

https://saboskirt.com/cdn/shop/t/489/assets/early-access.js?v=10467623691143836171785995049

js saboskirt.com collected 2026-09-25 18:42:17 UTC 13,626 bytes, 2 lines download raw bytes

1import{fetchConfig}from"@theme/utilities";import{CartUpdateEvent,ThemeEvents}from"@theme/events";const LS_UNLOCKED="ea_unlocked",LS_CODE="ea_code",LS_CAMPAIGN="ea_campaign",LS_INFLUENCER="ea_influencer",LS_SESSION_ID="ea_session_id",LS_UNLOCKS_V2="ea_unlocks_v2";function normalizeCampaign(v){return String(v||"").trim().toLowerCase()}function normalizeMode(v){const mode=String(v||"").trim().toLowerCase();return mode==="code"||mode==="loyalty"||mode==="either"?mode:""}function getPrimaryUnlockRoot(){const el=document.querySelector("[data-ea-unlock]");return el instanceof HTMLElement?el:null}function getUnlockDatasetValue(root,key){return root?.dataset?.[key]||document.body?.dataset?.[key]||""}function getPageUnlockScope(){const root=getPrimaryUnlockRoot();return root?{campaign:root.dataset.eaCampaign||document.body?.dataset?.eaCampaign||"",collectionHandle:root.dataset.eaCollection||"",context:root.dataset.eaContext||"",mode:root.dataset.eaMode||document.body?.dataset?.eaMode||""}:{campaign:document.body?.dataset?.eaCampaign||"",collectionHandle:document.body?.dataset?.eaCollection||"",context:document.body?.dataset?.eaContext||"",mode:document.body?.dataset?.eaMode||""}}function getUnlockMap(){try{const raw=localStorage.getItem(LS_UNLOCKS_V2)||"",json=raw?JSON.parse(raw):null;return json&&typeof json=="object"?json:{}}catch{return{}}}function setUnlockMap(map){try{localStorage.setItem(LS_UNLOCKS_V2,JSON.stringify(map||{}))}catch{}}function getCookie(name){const match=document.cookie.match(new RegExp(`(?:^|; )${name.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")}=([^;]*)`));return match&&match[1]?decodeURIComponent(match[1]):null}function setCookie(name,value,days=30){const maxAge=days*24*60*60;document.cookie=`${encodeURIComponent(name)}=${encodeURIComponent(value)}; Max-Age=${maxAge}; Path=/; SameSite=Lax`}function getOrCreateSessionId(){const existing=localStorage.getItem(LS_SESSION_ID);if(existing)return existing;const sid=crypto?.randomUUID?crypto.randomUUID():`${Date.now()}-${Math.random().toString(16).slice(2)}`;return localStorage.setItem(LS_SESSION_ID,sid),sid}function getUnlockState(scopeCampaign="",scopeMode=""){const scopeKey=normalizeCampaign(scopeCampaign),mode=normalizeMode(scopeMode||document.body?.dataset?.eaMode||""),root=getPrimaryUnlockRoot();let loyaltyUnlocked=getUnlockDatasetValue(root,"eaLoyaltyMember")==="true"||getUnlockDatasetValue(root,"eaLoyaltyVip")==="true"||getUnlockDatasetValue(root,"eaLoyaltyTier")==="VIP",loyaltyStatus=getUnlockDatasetValue(root,"eaLoyaltyStatus");const codeUnlocked=localStorage.getItem(LS_UNLOCKED)==="1"||getCookie("ea_unlocked")==="1",unlockMap=getUnlockMap(),scoped=scopeKey?unlockMap[scopeKey]:null,legacyCode=localStorage.getItem(LS_CODE)||getCookie("ea_code")||"",legacyCampaign=localStorage.getItem(LS_CAMPAIGN)||getCookie("ea_campaign")||"",legacyInfluencer=localStorage.getItem(LS_INFLUENCER)||"",legacyKey=normalizeCampaign(legacyCampaign);mode!=="loyalty"&&scopeKey&&!scoped&&codeUnlocked&&legacyKey&&legacyKey===scopeKey&&(unlockMap[scopeKey]={code:legacyCode||"",campaign:legacyCampaign||scopeCampaign||"",influencer:legacyInfluencer||"",unlockedAt:Date.now()},setUnlockMap(unlockMap));let effectiveCodeUnlocked=codeUnlocked,code=legacyCode,campaign=legacyCampaign;const influencer=localStorage.getItem(LS_INFLUENCER)||"";if(scopeKey){const v2=getUnlockMap()[scopeKey];effectiveCodeUnlocked=!!(v2&&(v2.code||v2.influencer)),code=v2&&v2.code||"",campaign=v2&&v2.campaign||scopeCampaign||""}let unlocked=loyaltyUnlocked||effectiveCodeUnlocked;return mode==="loyalty"?(unlocked=loyaltyUnlocked,code="",campaign=scopeCampaign||campaign||""):mode==="code"?(unlocked=effectiveCodeUnlocked,loyaltyUnlocked=!1,loyaltyStatus=""):mode==="either"&&(unlocked=loyaltyUnlocked||effectiveCodeUnlocked),{unlocked,loyaltyUnlocked,codeUnlocked:effectiveCodeUnlocked,code,campaign,influencer,loyaltyStatus}}function setUnlockState({code,campaign,influencer}){localStorage.setItem(LS_UNLOCKED,"1"),localStorage.setItem(LS_CODE,code),setCookie("ea_unlocked","1"),setCookie("ea_code",code),campaign&&(localStorage.setItem(LS_CAMPAIGN,campaign),setCookie("ea_campaign",campaign)),influencer&&localStorage.setItem(LS_INFLUENCER,influencer);const key=normalizeCampaign(campaign);if(key){const map=getUnlockMap();map[key]={code,campaign,influencer:influencer||"",unlockedAt:Date.now()},setUnlockMap(map)}}function setBodyUnlockClasses(){const scope=getPageUnlockScope(),{unlocked}=getUnlockState(scope.campaign,scope.mode);document.body.classList.toggle("ea-unlocked",unlocked),document.body.classList.toggle("ea-locked",!unlocked)}function syncEarlyAccessLineItemProperties(){const scope=getPageUnlockScope(),state=getUnlockState(scope.campaign,scope.mode);document.querySelectorAll('[data-ea-required="1"]').forEach(wrapper=>{if(!(wrapper instanceof HTMLElement))return;wrapper.querySelectorAll('form[data-type="add-to-cart-form"]').forEach(form=>{if(!(form instanceof HTMLFormElement))return;const codeEl=form.querySelector('input[data-ea-line-prop="code"]'),accessLabelEl=form.querySelector('input[data-ea-line-prop="access-label"]'),campaignEl=form.querySelector('input[data-ea-line-prop="campaign"]'),methodEl=form.querySelector('input[data-ea-line-prop="method"]'),loyaltyStatusEl=form.querySelector('input[data-ea-line-prop="loyalty-status"]');codeEl instanceof HTMLInputElement&&(codeEl.value=state.code||""),accessLabelEl instanceof HTMLInputElement&&(accessLabelEl.value=state.loyaltyUnlocked?"SABO Resort Loyalty":""),campaignEl instanceof HTMLInputElement&&(campaignEl.value=state.campaign||""),methodEl instanceof HTMLInputElement&&(methodEl.value=state.loyaltyUnlocked?"loyalty":state.code?"code":""),loyaltyStatusEl instanceof HTMLInputElement&&(loyaltyStatusEl.value=state.loyaltyUnlocked?state.loyaltyStatus||"enrolled":"")}
1)})}function getCartSectionIds(){const ids=new Set;return document.querySelectorAll("cart-items-component").forEach(el=>{el instanceof HTMLElement&&el.dataset.sectionId&&ids.add(el.dataset.sectionId)}),Array.from(ids)}async function removeEarlyAccessCartItemsIfLocked(){const scope=getPageUnlockScope();if(getUnlockState(scope.campaign,scope.mode).unlocked||typeof Theme>"u"||!Theme?.routes?.cart_change_url)return;const rows=Array.from(document.querySelectorAll('[data-ea-cart-item="1"][data-ea-cart-line]')).map(el=>{if(!(el instanceof HTMLElement))return null;const line=parseInt(el.dataset.eaCartLine||"",10);return Number.isFinite(line)&&line>0?{line}:null}).filter(v=>v!==null);if(rows.length===0)return;const lines=Array.from(new Set(rows.map(r=>r.line))).sort((a,b)=>b-a),sections=getCartSectionIds(),primarySectionId=sections[0]||"";for(const line of lines){const body=JSON.stringify({line,quantity:0,sections:sections.join(","),sections_url:window.location.pathname}),text=await(await fetch(`${Theme.routes.cart_change_url}`,fetchConfig("json",{body}))).text();let json=null;try{json=JSON.parse(text)}catch{}if(!json?.sections||!primarySectionId)continue;let itemCount=0;try{const newCount=new DOMParser().parseFromString(json.sections[primarySectionId],"text/html").querySelector('[ref="cartItemCount"]')?.textContent;itemCount=newCount?parseInt(newCount,10):0}catch{}document.dispatchEvent(new CartUpdateEvent({},primarySectionId,{itemCount,source:"early-access",sections:json.sections}))}}function preventEarlyAccessAddToCartIfLocked(){document.addEventListener("submit",e=>{const scope=getPageUnlockScope();if(getUnlockState(scope.campaign,scope.mode).unlocked)return;const form=e.target;if(!(form instanceof HTMLFormElement)||form.dataset.type!=="add-to-cart-form"||!form.closest('[data-ea-required="1"]'))return;e.preventDefault(),e.stopPropagation(),document.querySelector("[data-ea-unlock]")?.scrollIntoView?.({behavior:"smooth",block:"center"})},!0)}async function updateCartAttributes({code,campaign,influencer}){if(typeof Theme>"u"||!Theme?.routes?.cart_update_url)return;const attrs={early_access_code:code||"",early_access_campaign:"",early_access_influencer:""};campaign&&(attrs.early_access_campaign__=campaign),influencer&&(attrs.early_access_influencer__=influencer);const body=JSON.stringify({attributes:attrs});await fetch(Theme.routes.cart_update_url,fetchConfig("json",{body}))}async function callProxyUnlock(root,code){const params=new URLSearchParams;params.set("code",code),params.set("campaign",root.dataset.eaCampaign||""),params.set("collectionHandle",root.dataset.eaCollection||""),params.set("shop",root.dataset.eaShop||Shopify?.shop||""),params.set("countryCode",root.dataset.eaCountry||""),params.set("sessionId",getOrCreateSessionId());const url=`/apps/early-access?${params.toString()}`,res=await fetch(url,{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});let json=null;try{json=await res.json()}catch{}if(!res.ok||!json){const msg=json?.error||"Unable to validate code. Please try again.";throw new Error(msg)}if(json.ok!==!0){const msg=json?.error||"Invalid code.";throw new Error(msg)}return json}function fireKlaviyoUnlockEvent({code,campaign,collectionHandle}){const learnq=window._learnq;Array.isArray(learnq)&&learnq.push(["track","Early Access Unlocked",{code,campaign:campaign||"",collection_handle:collectionHandle||"",page_url:window.location.href}])}function mountUnlockForm(root){const form=root.querySelector("[data-ea-unlock-form]"),msg=root.querySelector("[data-ea-message]");if(!(form instanceof HTMLFormElement)||!(msg instanceof HTMLElement))return;const details=root.querySelector(".ea-unlock__details"),panel=root.querySelector(".ea-unlock__panel"),inner=panel instanceof HTMLElement?panel.querySelector(".ea-unlock__panel-inner"):null,syncPanelHeight=()=>{if(!(panel instanceof HTMLElement))return;if(!(details instanceof HTMLDetailsElement)||!details.open){panel.style.setProperty("--ea-panel-max-height","0px");return}const h=(inner instanceof HTMLElement?inner.scrollHeight:panel.scrollHeight)||0;panel.style.setProperty("--ea-panel-max-height",`${h+16}px`)};details instanceof HTMLDetailsElement&&details.addEventListener("toggle",()=>{requestAnimationFrame(syncPanelHeight)}),requestAnimationFrame(syncPanelHeight);const rafSync=()=>requestAnimationFrame(syncPanelHeight);let ro=null;typeof ResizeObserver<"u"&&inner instanceof HTMLElement&&(ro=new ResizeObserver(()=>rafSync()),ro.observe(inner));const onResize=()=>rafSync();window.addEventListener("resize",onResize,{passive:!0}),form.addEventListener("submit",async e=>{e.preventDefault();const fd=new FormData(form),code=String(fd.get("code")||"").trim().toUpperCase();if(msg.hidden=!0,msg.textContent="",msg.removeAttribute("data-ea-status"),!!code){form.querySelector('button[type="submit"]')?.setAttribute("aria-busy","true");try{const resp=await callProxyUnlock(root,code),campaign=resp.campaign||root.dataset.eaCampaign||"",influencer=resp.influencer||"";setUnlockState({code,campaign,influencer}),syncEarlyAccessLineItemProperties(),await updateCartAttributes({code,campaign,influencer}),fireKlaviyoUnlockEvent({code,campaign,collectionHandle:root.dataset.eaCollection||""}),msg.dataset.eaStatus="success",msg.textContent="Unlocked. Happy shopping.",msg.hidden=!1,window.setTimeout(()=>{setBodyUnlockClasses()},450)}catch(err){details instanceof HTMLDetailsElement&&(details.open=!0),requestAnimationFrame(syncPanelHeight),msg.dataset.eaStatus="error",msg.textContent=err instanceof Error?err.message:"Invalid code.",msg.hidden=!1}finally{form.querySelector('button[type="submit"]')?.removeAttribute("aria-busy")}}});const mo=new MutationObserver(()=>{document.body.contains(root)||(window.removeEventListener("resize",onResize),ro?.disconnect?.(),mo.disconnect())});mo.observe(document.body,{childList:!0,subtree:!0})}function preventIosZoomOnUnlockInput(){if(!(typeof navigator<"u"&&/iP(hone|ad|od)/.test(navigator.platform||"")||typeof navigator<"u"&&(navigator.userAgent||"").includes("Mac")&&typeof document<"u"&&"ontouchend"in document))return;const viewport=document.querySelector('meta[name="viewport"]');if(!(viewport instanceof HTMLMetaElement))return;const original=viewport.getAttribute("content")||"width=device-width, initial-scale=1",locked=/maximum-scale/.test(original)?original:`${original}, maximum-scale=1`,isUnlockInput=target=>target instanceof HTMLElement&&!!target.closest(".ea-unlock__input"),lock=()=>viewport.setAttribute("content",locked),restore=()=>viewport.setAttribute("content",original);document.addEventListener("touchstart",e=>{isUnlockInput(e.target)&&lock()},{capture:!0,passive:!0}),document.addEventListener("focusin",e=>{isUnlockInput(e.target)&&lock()},!0),document.addEventListener("focusout",e=>
1{isUnlockInput(e.target)&&restore()},!0)}function init(){if(!document.body)return;setBodyUnlockClasses(),preventIosZoomOnUnlockInput(),preventEarlyAccessAddToCartIfLocked(),syncEarlyAccessLineItemProperties(),removeEarlyAccessCartItemsIfLocked().catch(()=>{});const scope=getPageUnlockScope(),state=getUnlockState(scope.campaign,scope.mode);state.unlocked&&state.code?updateCartAttributes({code:state.code,campaign:state.campaign,influencer:state.influencer}).catch(()=>{}):state.unlocked&&state.loyaltyUnlocked&&updateCartAttributes({code:"",campaign:state.campaign,influencer:state.influencer}).catch(()=>{}),document.addEventListener(ThemeEvents.variantUpdate,()=>syncEarlyAccessLineItemProperties()),document.querySelectorAll("[data-ea-unlock]").forEach(root=>{root instanceof HTMLElement&&mountUnlockForm(root)})}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",init,{once:!0}):init();
2//# sourceMappingURL=/cdn/shop/t/489/assets/early-access.js.map?v=10467623691143836171785995049

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.