1(function(){"use strict";const ENDPOINTS={add:"/cart/add.js",update:"/cart/update.js",change:"/cart/change.js",get:"/cart.js"},JSON_HEADERS={"Content-Type":"application/json",Accept:"application/json"},MEMBERSHIP_RADIO='input[type="radio"][name="membershipOption"], input[type="radio"][name="membershipOption-mobile"]';function config(){return window.FM&&window.FM.config&&window.FM.config.membership||null}function memberOnlyHandles(){return window.FM&&window.FM.config&&window.FM.config.memberOnlyProducts||[]}function currentMembership(){return window.FM&&window.FM.state&&window.FM.state.membership||{source:"none",type:"none",active:!1}}function membershipPlanFromRadioId(id){return id?id.includes("radio-non-member-unique")?"none":id.includes("radio-quarterly-member-unique")?"quarterly":id.includes("radio-annual-member-unique")?"annual":null:null}class CartMembership{constructor(){this.busy=!1}get cartItems(){return document.querySelector("cart-items")}set(type){const cfg=config();if(!cfg||type!=="quarterly"&&type!=="annual")return console.warn("[CartMembership] set(): invali
1d type or missing FM.config",type),Promise.resolve();const target=cfg[type],other=cfg[type==="quarterly"?"annual":"quarterly"];return!target||!target.variantId?(console.warn("[CartMembership] set(): missing variantId for",type),Promise.resolve()):this._run(async()=>{const cart=await this._getCart(),needsAdd=!this._membershipLine(cart,target.variantId),updates={};other&&other.variantId&&this._membershipLine(cart,other.variantId)&&(updates[other.variantId]=0),this._variantQty(cart,target.variantId)>1&&(updates[target.variantId]=1);const hasUpdates=Object.keys(updates).length>0;if(!needsAdd&&!hasUpdates)return null;const next={source:"cart",type,active:!0};let state;if(needsAdd&&!hasUpdates)state=await this._add(target.variantId,target.sellingPlanId,!0);else{needsAdd&&await this._add(target.variantId,target.sellingPlanId,!1);const cartAfter=await this._getCart(),postUpdates={};other&&other.variantId&&this._membershipLine(cartAfter,other.variantId)&&(postUpdates[other.variantId]=0),this._variantQty(cartAfter,target.variantId)>1&&(postUpdates[target.variantId]=1),state=await this._mutate(postUpdates,cartAfter),(!state||!state.sections)&&(state=await this._refreshSections())}return this._afterTransition(next),this._renderAndSync(state),state})}remove(){const cfg=config();return this._run(async()=>{const cart=await this._getCart(),updates={};cfg&&[cfg.quarterly,cfg.annual].forEach(plan=>{if(!plan||!plan.variantId)return;const line=this._membershipLine(cart,plan.variantId);line&&(updates[line.key]=0)});const handles=memberOnlyHandles();if(handles.length&&(cart.items||[]).forEach(item=>{handles.indexOf(item.handle)!==-1&&(updates[item.key]=0)}),!Object.keys(updates).length)return null;const state=await this._mutateKeys(updates);return this._afterTransition({source:"none",type:"none",active:!1}),this._renderAndSync(state),state})}restrictDuplicates(){const cfg=config();return cfg?this._run(async()=>{const cart=await this._getCart(),qLine=cfg.quarterly&&cfg.quarterly.variantId?this._membershipLine(cart,cfg.quarterly.variantId):null,aLine=cfg.annual&&cfg.annual.variantId?this._membershipLine(cart,cfg.annual.variantId):null,updates={};if(qLine&&aLine){const items=cart.items||[],older=items.indexOf(qLine)<items.indexOf(aLine)?qLine:aLine;updates[older.key]=0}
1if([qLine,aLine].forEach(line=>{line&&line.quantity>1&&updates[line.key]!==0&&(updates[line.key]=1)}),!Object.keys(updates).length)return null;const state=await this._mutateKeys(updates);return this._renderAndSync(state),state}):Promise.resolve()}mutateLine(ref,quantity){return!ref||ref.id==null&&ref.line==null?Promise.resolve(null):this._run(async()=>{const body={quantity:Number(quantity)||0,sections_url:window.location.pathname};ref.id!=null?body.id=ref.id:body.line=ref.line;const names=this._sectionNames();names.length&&(body.sections=names);const url=window.routes&&window.routes.cart_change_url||ENDPOINTS.change;let state=await fetch(url,{method:"POST",headers:JSON_HEADERS,body:JSON.stringify(body)}).then(r=>{if(!r.ok)throw new Error("[CartMembership] mutateLine /cart/change.js failed: "+r.status);return r.json()});return(!state||!state.sections)&&(state=await this._refreshSections()),await this._resyncMembershipFromCart(),this._render(state),this._syncMembershipDom(),state})}_resyncMembershipFromCart(){const cfg=config();return this._getCart().then(cart=>{let next={source:"none",type:"none",active:!1};cfg&&(cfg.annual&&cfg.annual.variantId&&this._membershipLine(cart,cfg.annual.variantId)?next={source:"cart",type:"annual",active:!0}:cfg.quarterly&&cfg.quarterly.variantId&&this._membershipLine(cart,cfg.quarterly.variantId)&&(next={source:"cart",type:"quarterly",active:!0})),this._afterTransition(next)})}_run(task){return this.busy?Promise.resolve():(this.busy=!0,this._setLoading(!0),Promise.resolve().then(task).catch(err=>{console.error("[CartMembership] transition failed:",err)}).finally(()=>{this.busy=!1,this._setLoading(!1)}))}_setLoading(on){const ci=this.cartItems;ci&&ci.classList.toggle("cart__items--disabled",!!on)}_getCart(){return fetch(ENDPOINTS.get,{headers:{Accept:"application/json"}}).then(r=>r.json())}_add(variantId,sellingPlanId,withSections){const item={id:variantId,quantity:1};sellingPlanId&&(item.selling_plan=sellingPlanId);const body={items:[item]};if(withSections){body.sections_url=window.location.pathname;const names=this._sectionNames();names.length&&(body.sections=names)}return fetch(ENDPOINTS.add,{method:"POST",headers:JSON_HEADERS,body:JSON.stringify(body)}).then(async r=>{const state=await r.json();if(!r.ok||state.status&&Number(state.status)>=400)throw new Error(state.description||state.message||"[CartMembership] /cart/add.js failed");return withSections&&!state.sections?this._refreshSections().then(refreshed=>refreshed||state):state})}_mutate(variantKeyedUpdates,cart){return Promise.resolve(cart||this._getCart()).then(cartData=>{const keyed=this._lineKeysFromVariants(cartData,variantKeyedUpdates);return this._mutateKeys(keyed)})}_lineKeysFromVariants(cart,variantKeyedUpdates){const keyed={};return Object.entries(variantKeyedUpdates||{}).forEach(([variantId,qty])=>{const line=this._membershipLine(cart,Number(variantId))||this._line(cart,Number(variantId));line&&(keyed[line.key]=qty)}),keyed}_changeLine(lineKey,quantity,sellingPlanId,withSections){const body={id:lineKey,quantity,sections_url:window.location.pathname};if(quantity>0&&sellingPlanId&&(body.selling_plan=sellingPlanId),withSections){const names=this._sectionNames();names.length&&(body.sections=names)}const url=window.routes&&window.routes.cart_change_url||ENDPOINTS.change;return fetch(url,{method:"POST",headers:JSON_HEADERS,body:JSON.stringify(body)}).then(r=>{if(!r.ok)throw new Error("[CartMembership] /cart/change.js failed: "+r.status);return r.json()})}_mutateKeys(updates){if(!updates||!Object.keys(updates).length)return Promise.resolve(null);const entries=Object.entries(updates);let chain=Promise.resolve(null);return entries.forEach(([key,qty],index)=>{const isLast=index===entries.length-1;chain=chain.then(()=>this._changeLine(key,qty,null,isLast))}),chain}_refreshSections(){const body={updates:{},sections_url:window.location.pathname},names=this._sectionNames();return names.length?(body.sections=names,fetch(ENDPOINTS.update,{method:"POST",headers:JSON_HEADERS,body:JSON.stringify(body)}).then(r=>r.json())):Promise.resolve(null)}_render(state){state&&typeof state.item_count!="number"&&Array.isArray(state.items)&&(state.item_count=state.items.reduce(function(n,item){return n+(item.quantity||0)},0));const ci=this.cartItems;ci&&typeof ci.renderSections=="function"&&state&&state.sections&&ci.renderSections(state)}_renderAndSync(state){this._render(state),this._syncMembershipDom()}_syncMembershipDom(){const el=document.querySelector(".custom_cart_items");if(!el)return;const m=window.FM&&window.FM.state&&window.FM.state.membership;m&&m.active&&m.type==="annual"?el.setAttribute("membership-in-cart","inveterate-subscription-1"):m&&m.active&&m.type==="quarterly"?el.setAttribute("membership-in-cart","inveterate-subscription"):el.removeAttribute("membership-in-cart")}_sectionNames(){const ci=this.cartItems;return!ci||typeof ci.getSectionsToRender!="function"?[]:(ci.getSectionsToRender()||[]).map(function(s){return s.section}).filter(function(name,index,arr){return name&&arr.indexOf(name)===index})}_line(cart,variantId){return(cart.items||[]).find(i=>i.variant_id===variantId)||null}_membershipLine(cart,variantId){const cfg=config();if(!cfg)return this._line(cart,variantId);
1const plans=[cfg.quarterly,cfg.annual].filter(Boolean);for(let i=0;i<plans.length;i++){const plan=plans[i];if(plan.variantId!==variantId)continue;const withPlan=(cart.items||[]).find(item=>{if(item.variant_id!==variantId)return!1;if(!plan.sellingPlanId)return!0;const planId=item.selling_plan_allocation&&item.selling_plan_allocation.selling_plan?item.selling_plan_allocation.selling_plan.id:null;return planId&&Number(planId)===Number(plan.sellingPlanId)});if(withPlan)return withPlan}return this._line(cart,variantId)}_variantQty(cart,variantId){const line=this._membershipLine(cart,variantId);return line?line.quantity:0}_afterTransition(next){const prev=currentMembership();if(window.FM){window.FM.state=window.FM.state||{};const merged=Object.assign({},window.FM.state.membership,next);next.active||(merged.hasMemberOnlyItems=!1),window.FM.state.membership=merged}const detail=Object.assign({previous:prev},next);!prev.active&&next.active?this._emit("fm:membership-gained",detail):prev.active&&!next.active?this._emit("fm:membership-lost",detail):prev.type!==next.type&&this._emit("fm:membership-type-changed",detail),this._emit("fm:membership-changed",detail)}_emit(name,detail){document.dispatchEvent(new CustomEvent(name,{detail}))}}function injectMembershipItemStyles(){if(document.getElementById("fm-membership-item-price-fix"))return;const style=document.createElement("style");style.id="fm-membership-item-price-fix",style.textContent=".membership_item .custom_cart_item_price_member .money { text-decoration: none !important; }",document.head.appendChild(style)}function initMembershipUI(){injectMembershipItemStyles();const root=document.querySelector(".cart__footer-wrapper");if(!root||root.dataset.fmMembershipBound==="true")return;root.dataset.fmMembershipBound="true",root.addEventListener("change",onMembershipRadioChange),root.addEventListener("mousedown",onMembershipRadioMouseDown),root.addEventListener("click",onMembershipRadioClick);const cm=window.FM&&window.FM.cartMembership;cm&&cm.restrictDuplicates()}function onMembershipRadioChange(event){const target=event.target;if(!target.matches(MEMBERSHIP_RADIO))return;const cm=window.FM&&window.FM.cartMembership;if(!cm||cm.busy)return;const plan=membershipPlanFromRadioId(target.id);plan==="none"?cm.remove():plan==="quarterly"?cm.set("quarterly"):plan==="annual"&&cm.set("annual")}function onMembershipRadioMouseDown(event){const radio=event.target.closest('input[type="radio"][id*="radio-annual-member-unique"]');radio&&(radio.dataset.wasChecked=radio.checked?"1":"0")}function onMembershipRadioClick(event){const toggle=event.target.closest(".small-toggle__checkbox");if(toggle){const cm2=window.FM&&window.FM.cartMembership;if(!cm2||cm2.busy)return;toggle.checked?cm2.set("annual"):cm2.remove();return}const radio=event.target.closest('input[type="radio"][id*="radio-annual-member-unique"]');if(!radio||radio.dataset.wasChecked!=="1")return;const cm=window.FM&&window.FM.cartMembership;!cm||cm.busy||cm.remove()}window.FM=window.FM||{},window.FM.CartMembership=CartMembership,window.FM.cartMembership=window.FM.cartMembership||new CartMembership,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",initMembershipUI):initMembershipUI()})(); 2//# sourceMappingURL=/cdn/shop/t/646/assets/cart-membership.js.map?v=97521569250264532471784652333
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.