1const SELECTORS={trigger:"[data-klaviyo-notify-trigger]",form:"[data-klaviyo-notify-form]",email:"[data-klaviyo-notify-email]",submit:"[data-klaviyo-notify-submit]",message:"[data-klaviyo-notify-message]"};let notifyRelationshipId=0;export function isValidEmail(email){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)}export function backInStockPayload(email,variantId){return{data:{type:"back-in-stock-subscription",attributes:{profile:{data:{type:"profile",attributes:{email}}},channels:["EMAIL"]},relationships:{variant:{data:{type:"catalog-variant",id:`$shopify:::$default:::${variantId}`}}}}}}export async function submitBackInStock({request,companyId,revision,email,variantId}){return request(`https://a.klaviyo.com/client/back-in-stock-subscriptions/?company_id=${companyId}`,{method:"POST",headers:{"Content-Type":"application/json",revision},body:JSON.stringify(backInStockPayload(email,variantId))})}export function ensureNotifyRelationships(scope){if(!(scope instanceof Element))return null;const container=scope.matches("[data-klaviyo-notify-scope], .tsf-product-card")?scope:scope.closest("[data-klaviyo-notify-scope], .tsf-product-card"),form=scope.matches(SELECTORS.form)?scope:container?.querySelector(SELECTORS.form);if(!form)return null;const trigger=container?.querySelector(SELECTORS.trigger),email=form.querySelector(SELECTORS.email),message=form.querySelector(SELECTORS.message);return form.id||(form.id=`TsfNotifyForm-${++notifyRelationshipId}`),trigger&&trigger.setAttribute("aria-controls",form.id),message&&(message.id||(message.id=`${form.id}-message`),email&&email.setAttribute("aria-describedby",message.id)),{trigger,form,email,message}}function setMessage(form,text,state){const email=form.querySelector(SELECTORS.email);email&&(state==="error"?email.setAttribute("aria-invalid","true"):email.removeAttribute("aria-invalid"));const message=form.querySelector(SELECTORS.message);message&&(message.textContent=text,message.hidden=!text,state?message.dataset.state=state:delete message.dataset.state)}function notifyScope(trigger){return trigger.closest("[data-klaviyo-notify-scope], .tsf-product-card")}function toggleForm(trigger){const form=ensureNotifyRelationships(notifyScope(trigger))?.form;if(!form)return;const wasHidden=form.hidden;form.hidden=!wasHidden,trigger.setAttribute("aria-expanded",String(wasHidden)),wasHidden&&form.querySelector(SELECTORS.email)?.focus()}async function handleSubmit(submit,{request=fetch}={}){const settings=window.KlaviyoBackInStockSettings,form=submit.closest(SELECTORS.form);if(!settings?.companyId||!form)return;const emailInput=form.querySelector(SELECTORS.email),email=emailInput?.value.trim()||"",variantId=form.dataset.variantId;if(!email||!isValidEmail(email)){setMessage(form,"Please enter a valid email address.","error"),emailInput?.focus();return}if(!variantId){setMessage(form,"This option is unavailable right now.","error");return}const originalLabel=submit.textContent;submit.disabled=!0,submit.textContent="Submitting\u2026",form.setAttribute("aria-busy","true"),setMessage(form,"","");try{(await submitBackInStock({request,companyId:settings.companyId,revision:settings.revision,email,variantId})).ok?(setMessage(form,"You're in! We'll email you when it's back.","success"),emailInput.value=""):setMessage(form,"Something went wrong. Please try again.","error")}catch{setMessage(form,"Network error. Please try again.","error")}finally{submit.disabled=!1,submit.textContent=originalLabel,form.removeAttribute("aria-busy")}}export function handleClick(event){if(!window.KlaviyoBackInStockSettings?.companyId)return;const trigger=event.target.closest(SELECTORS.trigger);if(trigger){event.preventDefault(),toggleForm(trigger);return}const submit=event.target.closest(SELECTORS.submit);submit&&handleSubmit(submit)}export function handleKeydown(event){if(event.key!=="Enter")return;const input=event.target;!(input instanceof Element)||!input.matches(SELECTORS.email)||(event.preventDefault(),input.closest(SELECTORS.form)?.querySelector(SELECTORS.submit)?.click())}
1export function syncProductNotify(scope,resource){if(!(scope instanceof Element))return;const trigger=scope.querySelector(SELECTORS.trigger),form=scope.querySelector(SELECTORS.form);if(!trigger||!form)return;ensureNotifyRelationships(scope);const variantId=resource?.id==null?"":String(resource.id),unavailable=!!variantId&&resource.available===!1;trigger.hidden=!unavailable,trigger.setAttribute("aria-expanded","false"),form.hidden=!0,unavailable?form.dataset.variantId=variantId:delete form.dataset.variantId}const notifyRequestByScope=new WeakMap;function handleProductSelect(event){const scope=event.target instanceof Element?event.target.closest(".shopify-section")?.querySelector("[data-klaviyo-notify-scope]"):null;if(!scope||!event.promise?.then)return;const request={};notifyRequestByScope.set(scope,request),event.promise.then(({detail})=>{notifyRequestByScope.get(scope)===request&&syncProductNotify(scope,detail?.resource)}).catch(()=>{})}document.querySelectorAll("[data-klaviyo-notify-scope], .tsf-product-card").forEach(ensureNotifyRelationships),document.addEventListener("shopify:section:load",event=>{event.target.querySelectorAll?.("[data-klaviyo-notify-scope], .tsf-product-card").forEach(ensureNotifyRelationships)}),document.addEventListener("click",handleClick),document.addEventListener("keydown",handleKeydown),document.addEventListener("shopify:product:select",handleProductSelect); 2//# sourceMappingURL=/cdn/shop/t/67/assets/thinslim-klaviyo-notify.js.map?v=177084972268687049431790074119
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.