PageSourceSearch

https://www.aliceandolivia.com/cdn/shop/t/292/assets/klaviyo-signup-form.REQn_Rcn.min.js

js aliceandolivia.com collected 2026-09-24 09:02:05 UTC 3,406 bytes, 1 lines download raw bytes

1import{B as t}from"./BaseElement.DADCq26n.min.js";import{c as e}from"./WithApiClient.D8EqDb9L.min.js";import{n as s,e as i,t as r}from"./vendor-lit.Dzz78LSH.min.js";import"./vendor.Cv8cRPQo.min.js";var o=Object.defineProperty,a=Object.getOwnPropertyDescriptor,n=(t,e,s,i)=>{for(var r,n=i>1?void 0:i?a(e,s):e,l=t.length-1;l>=0;l--)(r=t[l])&&(n=(i?r(e,s,n):r(n))||n);return i&&n&&o(e,s,n),n};let l=class extends t{constructor(){super(...arguments),this.companyId="",this.$klaviyoApi=e({baseUrl:"https://a.klaviyo.com/client",headers:{revision:"2024-07-15","Content-Type":"application/json"}})}get locale(){return this.getAttribute("locale")||"en"}get market(){return this.getAttribute("market")||"CA"}get country(){return this.getAttribute("country")||"Canada"}get listId(){return this.getAttribute("list-id")}get mode(){return"sms"===(this.getAttribute("mode")||"email").toLowerCase()?"sms":"email"}get isSmsMode(){return"sms"===this.mode}connectedCallback(){super.connectedCallback(),this.handleFormSubmit=this.handleFormSubmit.bind(this),this.form.addEventListener("submit",this.handleFormSubmit)}disconnectedCallback(){this.form.removeEventListener("submit",this.handleFormSubmit)}get companyIdFromScript(){const t=Array.from(document.scripts).find(t=>t.src.includes("static.klaviyo.com/onsite/js"));if(t){const e=new URL(t.src);return e.searchParams.get("company_id")||e.pathname.split("/")[4]||null}return null}async handleFormSubmit(t){t.preventDefault();const e=this.companyId||this.companyIdFromScript;if(!e||!this.listId)return;const s=new FormData(t.target),i={locale:this.locale,location:{country:this.country},properties:{locale:this.locale,locale_iso_code:`${this.locale}-${this.market}`,market:this.market,country:this.country}};if(this.isSmsMode){const t=s.get("phone_number");if(!t||"string"!=typeof t||!this.isValidPhoneNumber(t))return void this.showValidationErrorMessage();const e=this.formatPhoneNumber(t);i.phone_number=e}else{const t=s.get("email");if("string"!=typeof t||!t||!this.isValidEmail(t))return void this.showValidationErrorMessage();i.email=t}try{this.submitButton.disabled=!0,this.resetMessage();const t={method:"POST",body:{data:{type:"subscription",attributes:{profile:{data:{type:"profile",attributes:i}}},relationships:{list:{data:{type:"list",id:this.listId}}}}}};try{await this.$klaviyoApi(`/subscriptions/?company_id=${e}`,t),this.showSuccessMessage()}catch(r){if((null==r?void 0:r.errors)&&r.errors.length>0)return r.errors[0].detail,void this.showApiErrorMessage()}finally{setTimeout(()=>{this.form.reset(),this.resetMessage()},6e3)}}catch(o){this.showApiErrorMessage()}finally{this.submitButton.disabled=!1}}resetMessage(){this.dataset.state=""}showSuccessMessage(){this.dataset.state="success"}showValidationErrorMessage(){this.dataset.state="error-validation"}showApiErrorMessage(){this.dataset.state="error-api"}isValidEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}isValidPhoneNumber(t){const e=t.trim();if(!/^[\d\s().+-]+$/.test(e))return!1;const s=e.replace(/\D/g,"");return 10===s.length||11===s.length&&s.startsWith("1")}formatPhoneNumber(t){const e=t.replace(/\D/g,"");return e.startsWith("1")?`+${e}`:`+1${e}`}};n([s({type:String,attribute:"company-id"})],l.prototype,"companyId",2),n([i("form")],l.prototype,"form",2),n([i(".js-signup-form-submit")],l.prototype,"submitButton",2),l=n([r("klaviyo-signup-form")],l);export{l as KlaviyoSignupForm};

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.