1(function(){const sectionID=document.currentScript.dataset.id,section=document.querySelector(`[data-section="${sectionID}"]`);if(!section){console.warn(`Product section with ID ${sectionID} not found.`);return}const product=JSON.parse(section.querySelector(".productV22JSON").textContent);let activeVariant=JSON.parse(section.querySelector(".productV22VariantJSON").textContent);const variantIDtoOngoingPrice=JSON.parse(section.querySelector(".productV22VariantIDtoOngoingPriceJSON").textContent);let thumbsSwiper=new Swiper(section.querySelector(".productV22VisualThumbs"),{slidesPerView:5,spaceBetween:4}),productV22Swiper=new Swiper(section.querySelector(".productV22VisualSwiper"),{slidesPerView:1,spaceBetween:20,loop:!0,navigation:{nextEl:section.querySelector(".productV22VisualSwiper .productV22VisualSwiperNext"),prevEl:section.querySelector(".productV22VisualSwiper .productV22VisualSwiperPrev")},thumbs:{swiper:thumbsSwiper}});section.querySelectorAll(".productV22VisualSwiperSlide").forEach(element=>{element.addEventListener("click",function(){const video=this.closest(".productV22VisualSwiperSlide").querySelector("video");video&&(this.querySelector(".productV22VisualSwiperSlidePlay")?.remove(),video.controls=!0,video.play())})}),section.querySelectorAll(".productV22InfoDropdownTop")?.forEach(element=>{element.addEventListener("click",function(){this.classList.toggle("active")})}),section.querySelectorAll("input").forEach(function(element){element.addEventListener("change",function(){updateProduct()})});function updateProduct(){let sellingPlanExists=section.querySelector(".productV22Selling")||!1;if(product.variants.length===1)activeVariant=product.variants[0];else{let options=[];section.querySelectorAll(".productV22OptionItem").forEach(group=>{options.push(group.querySelector("input:checked").value)}),activeVariant=product.variants.find(variant=>JSON.stringify(variant.options)===JSON.stringify(options))}if(activeVariant==null){section.querySelector(".productV22ATC").disabled=!0,section.querySelector(".productV22ATC").textContent="not available";return}activeVariant.available?(section.querySelector(".productV22ATC").classList.add("primary"),section.querySelector(".productV22ATC").disabled=!1,section.querySelector(".productV22ATC").textContent="add to cart"):(section.querySelector(".productV22ATC").classList.remove("primary"),section.querySelector(".productV22ATC").disabled=!0,section.querySelector(".productV22ATC").textContent="sold out");const payInstallmentsInput=section.querySelector(".productV22PaymentsInput"),shopifyPaymentTerms=section.querySelector("shopify-payment-terms");payInstallmentsInput&&(payInstallmentsInput.value=activeVariant.id),shopifyPaymentTerms&&(shopifyPaymentTerms.dataset.variantId=activeVariant.id,shopifyPaymentTerms.setAttribute("variant-id",activeVariant.id)),section.querySelectorAll(".productV22OptionItemValuesLabelBodyWrapInnerWrap.once").forEach(element=>{element.classList.add("active")}),section.querySelectorAll(".productV22OptionItemValuesLabelBodyWrapInnerWrap.sub").forEach(element=>{element.classList.remove("active")}),section.querySelector(".productV22SellingLabelInput.sub")?.checked&&(section.querySelectorAll(".productV22OptionItemValuesLabelBodyWrapInnerWrap.once").forEach(element=>{element.classList.remove("active")}),section.querySelectorAll(".productV22OptionItemValuesLabelBodyWrapInnerWrap.sub").forEach(element=>{element.classList.add("active")})),updateSellingPlan(sellingPlanExists,activeVariant);let url=new URL(window.location.href);url.searchParams.set("variant",activeVariant.id),window.history.replaceState({},"",url)}function updateSellingPlan(sellingPlanExists=!0,activeVariant2){if(!sellingPlanExists)return;let activeVariantPlan=activeVariant2.selling_plan_allocations[0],optionsHTML="";activeVariant2.selling_plan_allocations.forEach(sellingPlanAllocation=>{let sellingPlan=getSellingPlanById(sellingPlanAllocation.selling_plan_id);sellingPlanAllocation.selling_plan_group_id!=="91e7beddcc2b25a88da97e3b201deec8db7b43bb"&&(optionsHTML+=`<option value="${sellingPlan.id}">${sellingPlan.name}</option>`)}),section.querySelectorAll(".productV22SellingLabelBodyBottomWrapContentSelect").forEach(select=>
1{select.innerHTML=optionsHTML});let save=(1-activeVariantPlan.price/activeVariant2.price)*100;const once=section.querySelector(".productV22SellingLabelBody.once"),sub=section.querySelector(".productV22SellingLabelBody.sub");activeVariant2.compare_at_price>activeVariant2.price?once.querySelector(".productV22SellingLabelBodyPriceCompare").textContent=price(activeVariant2.compare_at_price*quantity,!0):once.querySelector(".productV22SellingLabelBodyPriceCompare").textContent="",sub.querySelector(".productV22SellingLabelBodyPriceCompare").textContent=price(activeVariant2.compare_at_price*quantity,!0),activeVariantPlan.compare_at_price>activeVariant2.compare_at_price&&(sub.querySelector(".productV22SellingLabelBodyPriceCompare").textContent=price(activeVariantPlan.compare_at_price*quantity,!0)),once.querySelector(".productV22SellingLabelBodyPriceReal").textContent=price(activeVariant2.price*quantity,!0),sub.querySelector(".productV22SellingLabelBodyPriceReal").textContent=price(activeVariantPlan.price*quantity,!0),once.querySelector(".productV22SellingLabelBodyPriceReal").classList.remove("sale"),activeVariant2.compare_at_price>activeVariant2.price&&once.querySelector(".productV22SellingLabelBodyPriceReal").classList.add("sale"),section.querySelector(".productV22SellingLabelInput:checked").value==="sub"?section.querySelector(".productV22OptionItemValuesLabelBodyWrapSave.active").textContent="Save $46":section.querySelector(".productV22OptionItemValuesLabelBodyWrapSave.active").textContent="Save $15",product.handle==="brainstorm-journal"?once.querySelector(".productV22SellingLabelBodyBottomWrapContentTxt").innerHTML="<strong>DOES NOT INCLUDE</strong> THE ILLUSTRATED PLANNER OR FREE SHIPPING":product.handle==="happy-ending-x-dipsea"?once.querySelector(".productV22SellingLabelBodyBottomWrapContentTxt").innerHTML="<strong>DOES NOT INCLUDE</strong> FREE SHIPPING, EXTRA 25% OFF, OR FREE SUBSCRIPTION TO DIPSEA AUDIOBOOKS":once.querySelector(".productV22SellingLabelBodyBottomWrapContentTxt").innerHTML="<strong>DOES NOT INCLUDE</strong> NIGHTCAP STARTER KIT, FREE SHIPPING, SLEEP DIGITAL PLAYBOOK OR GUIDED SLEEP MEDITATIONS",section.querySelector(".productV22OptionItemValuesLabelInput:checked").value==="4"&§ion.querySelector(".productV22SellingLabelInput:checked").value==="once"&&once.querySelector(".productV22SellingLabelBodyBottomWrapContentBullets.once")?.classList.add("active"),section.querySelectorAll(".productV22SellingLabelBodyBottomWrapContentBulletsItem.subOnly")?.forEach(element=>{element.classList.remove("active")}),section.querySelector(".productV22SellingLabelInput:checked").value==="sub"&§ion.querySelectorAll(".productV22SellingLabelBodyBottomWrapContentBulletsItem.subOnly")?.forEach(element=>{element.classList.add("active")}),section.querySelector(".productV22OptionItemValuesLabelInput:checked").value==="4"&&(section.querySelectorAll(".productV22SellingLabelBodyBottomWrapContentBulletsItem.fourTinsOnly").forEach(element=>{element.classList.add("active")}),section.querySelectorAll(".productV22SellingLabelBodyBottomWrapContentBulletsItem.twoTinsOnly").forEach(element=>{element.classList.remove("active")})),section.querySelector(".productV22OptionItemValuesLabelInput:checked").value==="2"&&(section.querySelectorAll(".productV22SellingLabelBodyBottomWrapContentBulletsItem.twoTinsOnly").forEach(element=>{element.classList.add("active")}),section.querySelectorAll(".productV22SellingLabelBodyBottomWrapContentBulletsItem.fourTinsOnly").forEach(element=>{element.classList.remove("active")})),section.dispatchEvent(new CustomEvent("mainProduct:update"))}let quantity=1;updateProduct();async function addToCart(button){button.classList.add("loading");let formData={items:[{quantity,id:activeVariant.id}]};if(section.querySelector(".productV22SellingLabelInput.sub")?.checked){let activeVariantPlan=activeVariant.selling_plan_allocations[0];for(let plan of activeVariant.selling_plan_allocations)plan.selling_plan_id===parseInt(section.querySelector(".productV22SellingLabelBodyBottomWrapContentSelect").value)&&(activeVariantPlan=plan);formData.items[0].selling_plan=activeVariantPlan.selling_plan_id}else product.handle==="nightcap-starter-kit"?formData.items[0].id=activeVariant.id===43225179062409?40815844589705:40815844622473:product.handle==="brainstorm-journal"?formData.items[0].id=activeVariant.id===43278816968841?40815834464393:40815834497161:product.handle==="happy-ending-x-dipsea"&&(formData.items[0].id=activeVariant.id===43316629635209?41711203844233:41711203877001);await addProduct(formData),button.classList.remove("loading"),await openCart()}section.querySelector(".productV22ATC").addEventListener("click",function(){addToCart(this)});const productV22Sticky=document.querySelector(`.productV22Sticky[data-product-sticky="${sectionID}"]`);if(productV22Sticky){let ownsSticky2=function(){const owner=[...document.querySelectorAll("[data-product-sticky]")].find(bar=>{const barSection=document.querySelector(`[data-section="${bar.dataset.productSticky}"], [id="${bar.dataset.productSticky}"]`);return barSection&&barSection.offsetParent!==null});return owner!=null&&owner.dataset.productSticky===sectionID},toggleStickyVisibility2=function(){const rect=productV22ATCEl.getBoundingClientRect(),inView=rect.bottom>0&&rect.top<window.innerHeight;productV22Sticky.classList.toggle("visible",!inView&&ownsSticky2())},updateProductSticky2=function(){const subChecked=productV22StickySubInput.checked;productV22StickyDose.classList.toggle("active",subChecked);const fourPack=section.querySelector(".productV22OptionItemValuesLabelInput:checked")?.value==="4";if(productV22StickyDose.textContent=fourPack?"$1.38/dose":"$1.37/dose",subChecked){const subPrice=price(activeVariant.selling_plan_allocations[0].price*quantity,!0);let ongoingPrice=activeVariant.selling_plan_allocations[0].price;const ongoingPriceMetafield=variantIDtoOngoingPrice[activeVariant.id];ongoingPriceMetafield!=null&&(ongoingPrice=Math.round(parseFloat(ongoingPriceMetafield))),productV22StickyPrice.innerHTML=`<strong>${subPrice} </strong>+ FREE shipping* - <em>${price(ongoingPrice,!0)}
1/mo after, cancel anytime</em>`}else{const oncePrice=price(activeVariant.price*quantity,!0);productV22StickyPrice.innerHTML=`<strong>${oncePrice}</strong> + $9.99 shipping*`}};var ownsSticky=ownsSticky2,toggleStickyVisibility=toggleStickyVisibility2,updateProductSticky=updateProductSticky2;const productV22ATCEl=section.querySelector(".productV22ATC"),productV22StickySubInput=productV22Sticky.querySelector('.productV22StickyTopLeftBodyOptionsLabelInput[value="sub"]'),productV22StickyDose=productV22Sticky.querySelector(".productV22StickyBottomDose"),productV22StickyPrice=productV22Sticky.querySelector(".productV22StickyBottomPrice"),productV22StickyATC=productV22Sticky.querySelector(".productV22StickyTopATC");window.addEventListener("scroll",toggleStickyVisibility2,{passive:!0}),toggleStickyVisibility2(),productV22Sticky.querySelectorAll(".productV22StickyTopLeftBodyOptionsLabelInput").forEach(input=>{input.addEventListener("change",function(){const mainInput=section.querySelector(`.productV22SellingLabelInput.${this.value}`);mainInput&&(mainInput.checked=!0,mainInput.dispatchEvent(new Event("change",{bubbles:!0})))})}),productV22StickyATC.addEventListener("click",function(){addToCart(this)}),section.addEventListener("mainProduct:update",updateProductSticky2),updateProductSticky2()}function getSellingPlanById(sellingPlanId){let sellingPlan=null;return product.selling_plan_groups.forEach(group=>{group.selling_plans.forEach(plan=>{plan.id===sellingPlanId&&(sellingPlan=plan)})}),sellingPlan}document.addEventListener("DOMContentLoaded",async function(){customElements.whenDefined("shopify-payment-terms").then(()=>{customElements.whenDefined("shop-pay-installments-banner").then(()=>{const bannerBold=section.querySelector("shopify-payment-terms")?.shadowRoot?.querySelector("shop-pay-installments-banner")?.shadowRoot?.querySelector("b");bannerBold&&(bannerBold.style="font-weight: 400;")})})});function initializeCustomSelect(){const selectElement=section.querySelector(".productV22SellingLabelBodyBottomWrapContentSelect"),detailsElement=section.querySelector(".customDetails");if(!selectElement||!detailsElement)return;const summaryElement=detailsElement.querySelector(".customDetailsTitle"),optionElements=detailsElement.querySelectorAll(".customOption"),initialOption=selectElement.options[selectElement.selectedIndex],initialValue=initialOption?initialOption.value:"";summaryElement&&(summaryElement.firstElementChild.textContent=initialOption?initialOption.textContent:""),optionElements.forEach((option,index)=>{const value=selectElement.options[index]?.value||"";option.setAttribute("data-value",value),option.classList.toggle("selected",value===initialValue)}),optionElements.forEach(option=>{option.addEventListener("click",()=>{const value=option.dataset.value,text=option.textContent.trim();selectElement.value=value,summaryElement&&(summaryElement.firstElementChild.textContent=text),optionElements.forEach(opt=>opt.classList.remove("selected")),option.classList.add("selected"),detailsElement.removeAttribute("open")})})}function updateSavingsDisplay(){if(!activeVariant)return;const subSaveElement=section.querySelector(".productV22SellingTagDiscountSub"),oneTimeSaveElement=section.querySelector(".productV22SellingTagDiscountOne");if(!subSaveElement)return;const sellingPlanPrice=activeVariant.selling_plan_allocations?.[0]?.price;if(sellingPlanPrice===void 0)return;const subTotal=activeVariant.compare_at_price?activeVariant.compare_at_price-sellingPlanPrice:activeVariant.price-sellingPlanPrice,oneTimeTotal=activeVariant.compare_at_price-activeVariant.price;subSaveElement.innerHTML=`SAVE ${price(subTotal,!0)}`,oneTimeSaveElement&&(oneTimeTotal>0?(oneTimeSaveElement.innerHTML=`SAVE ${price(oneTimeTotal,!0)}`,oneTimeSaveElement.classList.remove("hidden")):oneTimeSaveElement.classList.add("hidden"));const basePrice=activeVariant.compare_at_price||activeVariant.price,discountPercent=Math.round((basePrice-sellingPlanPrice)/basePrice*100);let ongoingPrice=sellingPlanPrice;const ongoingPriceMetafield=variantIDtoOngoingPrice[activeVariant.id];ongoingPriceMetafield!=null&&(ongoingPrice=Math.round(parseFloat(ongoingPriceMetafield)));const ongoingPercent=Math.round((basePrice-ongoingPrice)/basePrice*100),bulletSaveElement=section.querySelector(".productV22SellingLabelBodyBottomWrapContentBulletsItemSave");bulletSaveElement&&(bulletSaveElement.innerHTML=`
2 <span class="productV22SellingLabelBodyBottomWrapContentBulletsItemSavePrice">${price(ongoingPrice,!0)}/mo after first order</span> 3 <span class="productV22SellingLabelBodyBottomWrapContentBulletsItemSaveOngoing">(${ongoingPercent}% OFF ongoing)</span> 4 `)}function checkOneTimeTextVisibility(){const textElement=section.querySelector(".productV22SellingLabelBodyBottomWrapContentTxt"),bottomContentElement=section.querySelector(".productV22SellingLabelBody.once .productV22SellingLabelBodyBottom");!textElement||!bottomContentElement||bottomContentElement.classList.toggle("hidden",textElement.textContent.trim()==="")}section.querySelectorAll("[data-dosage-click]").forEach(dosageOption=>{dosageOption.addEventListener("click",function(){const subItem=section.querySelector(".productV22SellingLabelBodyTopLeftDosageText"),oneTimeItem=section.querySelector(".productV22SellingLabelBodyTopLeftDosageText.oneTime");subItem&&(subItem.innerHTML=dosageOption.getAttribute("data-dosage-sub")),oneTimeItem&&(oneTimeItem.innerHTML=dosageOption.getAttribute("data-dosage-one-time"))})});function refreshSellingUI(){initializeCustomSelect(),updateSavingsDisplay(),checkOneTimeTextVisibility()}section.addEventListener("mainProduct:update",refreshSellingUI),refreshSellingUI();function ownsAnchors(){const owner=[...document.querySelectorAll(".productV22[data-section]")].find(productSection=>productSection.offsetParent!==null);return owner!=null&&owner.dataset.section===sectionID}document.querySelectorAll('a[href="#product"]').forEach(link=>{link.addEventListener("click",function(event){ownsAnchors()&&(event.preventDefault(),section.scrollIntoView({behavior:"smooth",block:"start"}))})})})(); 5//# sourceMappingURL=/cdn/shop/t/75/assets/main-product-v22.js.map?v=92394536361866869491789758815
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.