1const SSP_DEV_PREVIEW_THANKYOU=!1,SSP_DEV_PREVIEW_STEP="thank-you-member";function registerSubscriptionSidebarPopup(){if(!window.Alpine||window.__sspAlpineRegistered)return!1;const root=document.getElementById("subscription-sidebar-popup");if(!root)return!1;if(!window.theme?.emailSubscription)return console.warn("[SSP] theme.emailSubscription is missing"),!1;const{apiUrl,acceptedLanguage,apiKey,xAppid}=theme.emailSubscription,{customerTags,customerEmail,popupDelayDays,popupDelaySeconds,popupSubscribed,autoShowPopup,enableSms,enableRegistration,scrollIdleMs,storagePrefix}=root.dataset,LS_DELAY=`${storagePrefix}_delay_date`,LS_TAB_DISMISSED=`${storagePrefix}_tab_dismissed`;return Alpine.data("subscriptionSidebarPopup",()=>({subscriptionBtnText:"",showTriggerTab:!0,showPopup:!1,tabHiddenByScroll:!1,showStep:"subscription",email:"",phoneCode:"+1",phoneNumber:"",disclaimerChecked:!0,smsDisclaimerChecked:!1,errMsg:"",loading:!1,popupDelayDate:null,isLogin:!1,isSubscribed:!1,isSmsSubscribed:!1,isMember:!1,enableSms:!0,enableRegistration:!0,scrollIdleTimer:null,lastScrollY:0,shouldPageActive:{subscription:!0,sms:!0,"thank-you":!0,"thank-you-member":!0,"thank-you-sms":!0},dismissTab(){this.showPopup=!1,this.showTriggerTab=!1,localStorage.setItem(LS_TAB_DISMISSED,"true")},togglePopup(){if(this.showPopup=!this.showPopup,!this.showPopup){const targetDay=new Date;targetDay.setHours(0,0,0,0),targetDay.setDate(new Date().getDate()+this.popupDelayDate),localStorage.setItem(LS_DELAY,targetDay),this.resetActivePage(),this.setStep("subscription"),this.email=customerEmail||"",this.errMsg=""}},resetActivePage(){if(this.isLogin){this.shouldPageActive={subscription:!this.isSubscribed,sms:!this.isSmsSubscribed&&this.enableSms,"thank-you":!this.isMember&&this.enableRegistration,"thank-you-member":!0,"thank-you-sms":!0};return}this.shouldPageActive={subscription:!0,sms:!0,"thank-you":!0,"thank-you-member":!0,"thank-you-sms":!0}},setStep(step){if(this.showStep=step,step.indexOf("thank-you")>-1){const closeEl=document.getElementById("ssp_thank_you_close_popup"),delayEl=document.getElementById("ssp_thank_you_close_popup_delay");closeEl&&delayEl&&closeEl.value==="true"&&delayEl.value&&setTimeout(()=>this.togglePopup(),Number(delayEl.value))}},getActiveStep(step){const steps=Object.keys(this.shouldPageActive);let index=steps.indexOf(step);for(;index<steps.length;){if(this.shouldPageActive[steps[index]])return steps[index];index++}return null},goNextStep(expectedNextStep){this.setStep(this.getActiveStep(expectedNextStep))},getUsageOptionValues(){const values=[];return root.querySelectorAll(".ssp__tag input[type='checkbox']").forEach(item=>{item.checked&&values.push(parseInt(item.value,10))}),values},async submitEmailForm(){this.errMsg="";const isEmailValid=validateEmail(this.email);if(this.email===""){this.errMsg="Please enter your email address.";return}if(!isEmailValid){this.errMsg="Please enter a valid email address (Example: [email protected])";return}if(!this.disclaimerChecked){this.errMsg="Please agree to the Privacy Policy and Terms of Service.";return}const{data}=await this.fetchCustomerInfo(this.email);this.shouldPageActive={...this.shouldPageActive,sms:!data.acceptsMarketingSms&&this.enableSms,"thank-you":!data.registerUser&&this.enableRegistration};const fieldsArray=createFieldsArray(subscriptionSidebarPopupSettingJsons),usageOption=document.getElementById("ssp_usage_option")?.value;usageOption&&fieldsArray.push({id:usageOption,type:"multiple",value:this.getUsageOptionValues(),overwrite:!1});const contactListId=getContactListId(subscriptionSidebarPopupSettingJsons),subscribeInfoCookie=window.getCookieForEmarsys("subscribe_info");let eventTracking=null;if(subscribeInfoCookie)try{eventTracking=JSON.parse(decodeURIComponent(subscribeInfoCookie)),delete eventTracking.ts}catch(error){console.warn("Failed to parse subscribe_info cookie:",error)}const apiBody={email:this.email,contactListId,smsContactListId:subscriptionSidebarPopupSettingJsons.contact_list_id_sms,fields:fieldsArray,...eventTracking&&{eventTracking}};try{this.loading=!0,(await(await fetch(apiUrl,{method:"POST",headers:{"Content-Type":"application/json",apiKey,traceId,"X-appid":xAppid,"Accepted-Language":acceptedLanguage},body:JSON.stringify(apiBody)})).json()).message==="Success"?(this.goNextStep("sms"),this.email===customerEmail&&(this.shouldPageActive.subscription=!1,this.isSubscribed=!0)):this.errMsg="Oops... Something went wrong, please refresh and try again."}catch(error){this.errMsg="Oops... Something went wrong, please refresh and try again.",console.log(error)}finally{this.loading=!1}},async submitSmsForm(){this.errMsg="";const phone=`${this.phoneCode}${this.phoneNumber}`,isPhoneNumberValid=()=>{const phoneNumberRegex=/^(?=.{9,15}$)\+\d(-?\d)*$/,containOnlyOneOrNoHyphen=phone.split("-").length-1<=1;return phoneNumberRegex.test(phone)&&containOnlyOneOrNoHyphen};if(!this.smsDisclaimerChecked){this.errMsg="Please tick agreement box to proceed.";return}if(this.phoneNumber===""){this.errMsg="Please enter your phone number.";return}if(!isPhoneNumberValid(phone)){this.errMsg="Please enter a valid phone number";return}const{s_id_sms,s_value_sms,s_overwrite_sms,t_id_sms,t_value_sms,t_overwrite_sms,m_id_sms,m_value_sms,m_overwrite_sms,m_2_id_sms,m_2_value_sms,m_2_overwrite_sms,contact_list_id_sms}=subscriptionSidebarPopupSettingJsons;let fieldsArray=createFieldsArray(subscriptionSidebarPopupSettingJsons);const contactListId=getContactListId(subscriptionSidebarPopupSettingJsons);fieldsArray=[...fieldsArray,...s_id_sms?[{id:s_id_sms,type:"single",value:Number(s_value_sms),overwrite:JSON.parse(s_overwrite_sms)}]:[],...t_id_sms?[{id:t_id_sms,type:"text",value:Number(t_value_sms),overwrite:JSON.parse(t_over
1write_sms)}]:[],...m_id_sms?[{id:m_id_sms,type:"multiple",value:m_value_sms.split(",").map(item=>Number(item)),overwrite:JSON.parse(m_overwrite_sms)}]:[],...m_2_id_sms?[{id:m_2_id_sms,type:"multiple",value:m_2_value_sms.split(",").map(item=>Number(item)),overwrite:JSON.parse(m_2_overwrite_sms)}]:[]];const subscribeInfoCookie=window.getCookieForEmarsys("subscribe_info");let eventTracking=null;if(subscribeInfoCookie)try{eventTracking=JSON.parse(decodeURIComponent(subscribeInfoCookie)),delete eventTracking.ts}catch(error){console.warn("Failed to parse subscribe_info cookie:",error)}const apiBody={email:this.email===""?customerEmail:this.email,phone,contactListId,smsContactListId:contact_list_id_sms,fields:fieldsArray,...eventTracking&&{eventTracking}};try{if(this.loading=!0,(await this.fetchCustomerInfo(this.email===""?customerEmail:this.email,encodeURIComponent(phone))).data.registerPhone){this.errMsg="This phone number is already registered.";return}if((await(await fetch(apiUrl,{method:"POST",headers:{"Content-Type":"application/json",apiKey,traceId,"X-appid":xAppid,"Accepted-Language":acceptedLanguage},body:JSON.stringify(apiBody)})).json()).message==="Success"){const shouldSmsPageActive=this.email===""?!1:this.email!==customerEmail;this.shouldPageActive={...this.shouldPageActive,sms:shouldSmsPageActive,"thank-you":!this.isMember&&this.enableRegistration,"thank-you-member":!1},this.isSmsSubscribed=!shouldSmsPageActive,this.goNextStep("thank-you")}else this.errMsg="Oops... Something went wrong, please refresh and try again."}catch(error){this.errMsg="Oops... Something went wrong, please refresh and try again.",console.log(error)}finally{this.loading=!1}},async fetchCustomerInfo(email,phone){try{this.loading=!0;const phoneQuery=phone?`&phone=${phone}`:"";return await(await fetch(`https://api-a.ecoflow.com/website/subscribe/searchSubInfo?email=${email}${phoneQuery}`,{method:"GET",headers:{"X-appid":xAppid}})).json()}catch(error){throw new Error(error)}finally{this.loading=!1}},parseBool(value,fallback){if(value==null||value==="")return fallback;try{return JSON.parse(value)}catch{return fallback}},initScrollBehavior(){const idleMs=Number(scrollIdleMs)||2e3,trigger=root.querySelector(".ssp__trigger");if(!trigger)return;const onScroll=()=>{const currentY=window.scrollY;Math.abs(currentY-this.lastScrollY)>5&&(this.tabHiddenByScroll=!0,trigger.classList.add("ssp--hidden")),this.lastScrollY=currentY,clearTimeout(this.scrollIdleTimer),this.scrollIdleTimer=setTimeout(()=>{this.showTriggerTab&&!this.showPopup&&(this.tabHiddenByScroll=!1,trigger.classList.remove("ssp--hidden"))},idleMs)};window.addEventListener("scroll",onScroll,{passive:!0})},init(){if(this.subscriptionBtnText=root.dataset.subscriptionBtnText||"Subscribe",this.email=customerEmail||"",this.isLogin=!!customerEmail,this.isMember=!!customerEmail,this.enableSms=this.parseBool(enableSms,!1),this.enableRegistration=this.parseBool(enableRegistration,!1),this.popupDelayDate=Number(popupDelayDays)||0,this.shouldPageActive={...this.shouldPageActive,sms:this.enableSms,"thank-you":this.enableRegistration},localStorage.getItem(LS_TAB_DISMISSED)==="true"){this.showTriggerTab=!1;return}this.showTriggerTab=!0,customerEmail&&(async()=>{try{const data=await this.fetchCustomerInfo(customerEmail);if(data.message==="Success"){const{acceptsMarketing}=data.data;acceptsMarketing&&(this.subscriptionBtnText="Submit"),this.enableSms||(this.shouldPageActive.sms=!1),this.enableRegistration||(this.shouldPageActive["thank-you"]=!1),this.goNextStep("subscription")}}catch(error){console.warn("[SSP] fetchCustomerInfo failed:",error)}})();const now=new Date,delayDate=localStorage.getItem(LS_DELAY),isDelayDateValid=delayDate&&now.getTime()<new Date(delayDate).getTime(),parsedAutoShowPopup=this.parseBool(autoShowPopup,!1);!this.isSubscribed&&!isDelayDateValid&&parsedAutoShowPopup&&setTimeout(()=>{this.showPopup=!0},Number(popupDelaySeconds)*1e3),this.initScrollBehavior()},phoneCodeList:["+1","+7","+20","+27","+30","+31","+32","+33","+34","+36","+39","+40","+41","+43","+44","+45","+46","+47","+48","+49","+51","+52","+53","+54","+55","+56","+57","+58","+60","+61","+62","+63","+64","+65","+66","+81","+82","+84","+86","+90","+91","+92","+94","+95","+98","+211","+212","+213","+216","+218","+220","+221","+222","+223","+224","+225","+226","+227","+228","+229","+230","+231","+232","+233","+234","+235","+236","+237","+238","+239","+240","+241","+242","+243","+244","+245","+246","+248","+249","+250","+251","+252","+253","+254","+255","+256","+257","+258","+260","+261","+262","+263","+264","+265","+266","+267","+268","+269","+290","+29
11","+297","+298","+299","+350","+351","+352","+353","+354","+355","+356","+357","+358","+359","+370","+371","+372","+373","+374","+375","+376","+377","+378","+379","+380","+381","+382","+383","+385","+386","+387","+389","+420","+421","+423","+500","+501","+502","+503","+504","+505","+506","+507","+508","+509","+590","+591","+592","+593","+594","+595","+596","+597","+598","+599","+670","+672","+673","+674","+675","+676","+677","+678","+679","+680","+681","+682","+683","+685","+686","+687","+688","+689","+690","+691","+692","+850","+852","+853","+855","+856","+870","+880","+886","+960","+961","+962","+963","+964","+965","+966","+967","+968","+970","+971","+972","+973","+974","+975","+976","+977","+992","+993","+994","+995","+996","+998"]})),window.__sspAlpineRegistered=!0,!0}function bootSubscriptionSidebarPopup(){if(!registerSubscriptionSidebarPopup())return;const root=document.getElementById("subscription-sidebar-popup");!root||typeof Alpine.initTree!="function"||(root._x_dataStack?.length&&typeof Alpine.destroyTree=="function"&&Alpine.destroyTree(root),Alpine.initTree(root))}document.addEventListener("alpine:init",bootSubscriptionSidebarPopup),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",bootSubscriptionSidebarPopup):bootSubscriptionSidebarPopup(); 2//# sourceMappingURL=/cdn/shop/t/1497/assets/subscription-sidebar-popup-alpine.js.map?v=7887116584747262421781251358
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.