PageSourceSearch

https://aramecare.com/cdn/shop/t/16/assets/gift-with-purchase.js?v=119387276784822753091789588711

js aramecare.com collected 2026-10-04 21:07:04 UTC 6,623 bytes, 2 lines download raw bytes

1(()=>{const configEl=document.getElementById("gwp-config");if(!configEl)return;let config;try{config=JSON.parse(configEl.textContent)}catch(err){console.warn("[GWP] Could not read config",err);return}const variantId=Number(config.variantId);if(!variantId)return;const root=window.Shopify&&window.Shopify.routes&&window.Shopify.routes.root||"/",STATE_KEY="arame_gwp_"+variantId,now=Date.now(),startsAt=config.startsAt?Date.parse(config.startsAt):NaN,endsAt=config.endsAt?Date.parse(config.endsAt):NaN,isLive=config.enabled===!0&&config.available===!0&&(isNaN(startsAt)||now>=startsAt)&&(isNaN(endsAt)||now<endsAt),rate=parseFloat(window.Shopify&&window.Shopify.currency&&window.Shopify.currency.rate)||1,thresholdCents=Math.round(Number(config.threshold)*100*rate);function loadState(){try{return Object.assign({hadGift:!1,declined:!1,unavailable:!1},JSON.parse(sessionStorage.getItem(STATE_KEY))||{})}catch{return{hadGift:!1,declined:!1,unavailable:!1}}}function saveState(state){try{sessionStorage.setItem(STATE_KEY,JSON.stringify(state))}catch{}}const isGiftLine=item=>item.variant_id===variantId;function qualifyingSubtotal(cart){const others=cart.items.filter(item=>!isGiftLine(item));if(config.basis==="after_discounts"){const lines=others.reduce((sum,item)=>sum+item.final_line_price,0),orderLevel=(cart.cart_level_discount_applications||[]).reduce((sum,d)=>sum+(d.total_allocated_amount||0),0);return Math.max(0,lines-orderLevel)}return others.reduce((sum,item)=>sum+item.original_line_price,0)}async function request(path,body){const res=await fetch(root+path,{method:body?"POST":"GET",headers:{"Content-Type":"application/json",Accept:"application/json"},body:body?JSON.stringify(body):void 0});if(!res.ok){const err=new Error(path+" failed with "+res.status);throw err.status=res.status,err}return res.json()}const getCart=()=>request("cart.js"),addGift=()=>request("cart/add.js",{items:[{id:variantId,quantity:1,properties:{_gwp:"true"}}]}),updateLines=updates=>request("cart/update.js",{updates});function refreshTheme(cart){document.dispatchEvent(new CustomEvent("theme:cart:change",{detail:{cart},bubbles:!0})),document.dispatchEvent(new CustomEvent("theme:cart:reload",{bubbles:!0}))}async function reconcile(cart){const state=loadState(),giftLines=cart.items.filter(isGiftLine),hasGift=giftLines.length>0,hasOtherItems=cart.items.some(item=>!isGiftLine(item)),qualifies=isLive&&hasOtherItems&&qualifyingSubtotal(cart)>=thresholdCents;let changed=!1,hasGiftNow=hasGift;if(qualifies&&state.hadGift&&!hasGift&&(state.declined=!0),qualifies&&hasGift&&(state.declined=!1),qualifies||(state.declined=!1),qualifies&&hasGift){const[keep,...extras]=giftLines,updates={};extras.forEach(line=>{updates[line.key]=0}),keep.quantity!==1&&(updates[keep.key]=1),Object.keys(updates).length&&(await updateLines(updates),changed=!0)}else if(qualifies&&!hasGift&&!state.declined&&!state.unavailable)try{await addGift(),changed=!0,hasGiftNow=!0}catch(err){state.unavailable=!0,console.warn("[GWP] Gift could not be added",err)}else if(!qualifies&&hasGift){const updates={};giftLines.forEach(line=>{updates[line.key]=0}),await updateLines(updates),changed=!0,hasGiftNow=!1}return state.hadGift=hasGiftNow,saveState(state),changed}let busy=!1,pending=!1;async function sync(knownCart){if(busy){pending=!0;return}busy=!0;try{let cart=knownCart||await getCart();await reconcile(cart)?(cart=await getCart(),renderMessages(cart),refreshTheme(cart)):renderMessages(cart)}catch(err){console.warn("[GWP]",err)}finally{busy=!1,pending&&(pending=!1,sync())}}const money=cents=>{const currency=window.Shopify&&window.Shopify.currency&&window.Shopify.currency.active||"USD";return new Intl.NumberFormat(document.documentElement.lang||"en-US",{style:"currency",currency,minimumFractionDigits:cents%100===0?0:2}).format(cents/100)},fill=(text,amount)=>String(text||"").replace(/\{amount\}/g,amount).replace(/\{gift\}/g,config.giftName||"gift");function renderMessages(cart){const slots=document.querySelectorAll("[data-gwp-message]");if(!slots.length)return;const state=loadState(),subtotal=qualifyingSubtotal(cart),hasGift=cart.items.some(isGiftLine),show=isLive&&!state.unavailable,remaining=Math.max(0,thresholdCents-subtotal),progress=thresholdCents>0?Math.min(1,subtotal/thresholdCents):1;let text="",button=!1;remaining>0?text=subtotal>0?fill(config.messages.progress,money(remaining)):fill(config.messages.teaser,money(thresholdCents)):hasGift?text=fill(config.messages.unlocked,""):(text=fill(config.messages.declined,""),button=!0);const C=87.96459430051421,offset=C-progress*(C/2),svgNS="http://www.w3.org/2000/svg";
1slots.forEach(slot=>{if(slot.hidden=!show,!show)return;slot.innerHTML="";const row=document.createElement("p");row.className="cart__message gwp-message__row";const graph=document.createElement("small");graph.className="cart__graph",graph.setAttribute("role","progressbar"),graph.setAttribute("aria-valuemin","0"),graph.setAttribute("aria-valuemax","100"),graph.setAttribute("aria-valuenow",String(Math.round(progress*100))),graph.setAttribute("aria-label","Progress toward your free gift");const svg=document.createElementNS(svgNS,"svg");svg.setAttribute("height","18"),svg.setAttribute("width","18"),svg.setAttribute("aria-hidden","true");const track=document.createElementNS(svgNS,"circle"),fillCircle=document.createElementNS(svgNS,"circle");[track,fillCircle].forEach(c=>{c.setAttribute("r","7"),c.setAttribute("cx","9"),c.setAttribute("cy","9")}),fillCircle.setAttribute("class","cart__graph-progress"),fillCircle.setAttribute("stroke-dasharray",C+" "+C),fillCircle.style.strokeDashoffset=String(offset),svg.appendChild(track),svg.appendChild(fillCircle),graph.appendChild(svg),row.appendChild(graph);const label=document.createElement("span");if(label.className="gwp-message__text",label.textContent=text,row.appendChild(label),slot.appendChild(row),button){const btn=document.createElement("button");btn.type="button",btn.className="gwp-message__button",btn.textContent=config.messages.addButton||"Add to cart",btn.addEventListener("click",()=>{const s=loadState();s.declined=!1,s.hadGift=!1,saveState(s),btn.disabled=!0,sync()}),label.appendChild(document.createTextNode(" ")),label.appendChild(btn)}})}document.addEventListener("theme:cart:change",event=>{const cart=event.detail&&event.detail.cart;sync(cart&&Array.isArray(cart.items)?cart:void 0)}),document.addEventListener("cart:updated",()=>sync()),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>sync()):sync()})();
2//# sourceMappingURL=/cdn/shop/t/16/assets/gift-with-purchase.js.map?v=119387276784822753091789588711

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.