PageSourceSearch

https://theearthlingco.com/cdn/shop/t/413/assets/ab-sidecart-free-gift.js?v=129941593883862563591790672145

js theearthlingco.com collected 2026-10-02 04:50:13 UTC 14,087 bytes, 2 lines download raw bytes

1(function(){"use strict";var CFG={},THRESHOLD=5500,FREE_SHIP_THRESHOLD=4500,GIFT={variantId:0,handle:"",title:"",copy:""},CELL="control",OWN_PROP="_tec_gift",OWN_VALUE="sidecart",DEBUG=!1,PREFIX="[TEC-FreeGift:"+CELL+"]";function mergeObjects(){for(var out={},i=0;i<arguments.length;i++){var src=arguments[i]||{};for(var k in src)Object.prototype.hasOwnProperty.call(src,k)&&(src[k]&&typeof src[k]=="object"&&!Array.isArray(src[k])?out[k]=mergeObjects(out[k],src[k]):out[k]=src[k])}return out}function normalizeConfig(raw){raw=raw||{};var gift=raw.gift||{},thresholds=raw.thresholds||{};return{mode:raw.mode||"legacy",cell:raw.cell||"control",debug:raw.debug===!0,threshold:thresholds.gift||raw.threshold||5500,freeShip:thresholds.freeShipping||raw.freeShip||4500,gift:{variantId:gift.variantId||raw.variantId||0,handle:gift.handle||raw.handle||"",title:gift.title||raw.title||"",copy:gift.copy||raw.copy||""}}}function resolveConfig(extra){var base=typeof window!="undefined"&&window.__TEC_FREE_GIFT||{},override=typeof window!="undefined"&&window.__TEC_FREE_GIFT_OVERRIDE||{},legacy=typeof window!="undefined"&&window.__AB_FREE_GIFT||{};return(!base||!base.gift)&&(base=legacy),normalizeConfig(mergeObjects(base,override,extra||{}))}function applyConfig(extra){CFG=resolveConfig(extra),THRESHOLD=CFG.threshold,FREE_SHIP_THRESHOLD=CFG.freeShip,GIFT=CFG.gift,CELL=CFG.cell,DEBUG=CFG.debug,PREFIX="[TEC-FreeGift:"+CELL+"]",productCache=new Map,lastCart=null,lastState=null;try{appliedOverrideSig=JSON.stringify(typeof window!="undefined"&&window.__TEC_FREE_GIFT_OVERRIDE||{})}catch(e){appliedOverrideSig=null}log("config applied",CFG)}function log(){DEBUG&&console.log.apply(console,[PREFIX].concat([].slice.call(arguments)))}var productCache=new Map,lastState=null,appliedOverrideSig=null,lastCart=null,lastCartFetch=0,sweepInFlight=!1,mutating=!1;function formatMoney(cents){if(window.Shopify&&typeof Shopify.formatMoney=="function")try{return Shopify.formatMoney(cents)}catch(e){}return"$"+(Math.round(cents)/100).toFixed(2)}function el(tag,styles,attrs){var node=document.createElement(tag);if(styles&&(node.style.cssText=styles),attrs)for(var k in attrs)node.setAttribute(k,attrs[k]);return node}function escapeHtml(s){return String(s==null?"":s).replace(/[&<>"']/g,function(c){return{"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[c]})}var DISMISS_KEY="tecFreeGiftDismissed";function isDismissed(){try{return sessionStorage.getItem(DISMISS_KEY)===String(GIFT.variantId)}catch(e){return!1}}function setDismissed(on){try{on?sessionStorage.setItem(DISMISS_KEY,String(GIFT.variantId)):sessionStorage.removeItem(DISMISS_KEY)}catch(e){}}function fetchProduct(handle){return handle?productCache.has(handle)?Promise.resolve(productCache.get(handle)):fetch("/products/"+handle+".js").then(function(r){return r.ok?r.json():null}).then(function(p){return productCache.set(handle,p),p}).catch(function(){return productCache.set(handle,null),null}):Promise.resolve(null)}function fetchCart(){var now=Date.now();return lastCart&&now-lastCartFetch<250?Promise.resolve(lastCart):fetch("/cart.js",{credentials:"same-origin"}).then(function(r){return r.json()}).then(function(cart){return lastCart=cart,lastCartFetch=Date.now(),cart})}function subtotalExcludingGift(cart){for(var sum=0,items=cart&&cart.items||[],i=0;i<items.length;i++)items[i].variant_id!==GIFT.variantId&&(sum+=items[i].final_line_price);return sum}function computeState(cart){for(var subtotal=subtotalExcludingGift(cart),giftInCart=!1,giftKey=null,items=cart&&cart.items||[],i=0;i<items.length;i++)if(items[i].variant_id===GIFT.variantId&&(giftInCart=!0,items[i].properties&&items[i].properties[OWN_PROP]===OWN_VALUE)){giftKey=items[i].key;break}return{subtotal:subtotal,unlocked:subtotal>=THRESHOLD,remainingCents:Math.max(0,THRESHOLD-subtotal),giftInCart:giftInCart,giftKey:giftKey}}var LOCK='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96.108 122.88" width="17" height="19" aria-hidden="true"><path fill-rule="evenodd" clip-rule="evenodd" d="M2.892,56.036h8.959v-1.075V37.117c0-10.205,4.177-19.484,10.898-26.207v-0.009 C29.473,4.177,38.754,0,48.966,0C59.17,0,68.449,4.177,75.173,10.901l0.01,0.009c6.721,6.723,10.898,16.002,10.898,26.207v17.844 v1.075h7.136c1.59,0,2.892,1.302,2.892,2.891v61.062c0,1.589-1.302,2.891-2.892,2.891H2.892c-1.59,0-2.892-1.302-2.892-2.891 V58.927C0,57.338,1.302,56.036,2.892,56.036L2.892,56.036z M26.271,56.036h45.387v-1.075V36.911c0-6.24-2.554-11.917-6.662-16.03 l-0.005,0.004c-4.111-4.114-9.787-6.669-16.025-6.669c-6.241,0-11.917,2.554-16.033,6.665c-4.109,4.113-6.662,9.79-6.662,16.03 v18.051V56.
1036L26.271,56.036z M49.149,89.448l4.581,21.139l-12.557,0.053l3.685-21.423c-3.431-1.1-5.918-4.315-5.918-8.111 c0-4.701,3.81-8.511,8.513-8.511c4.698,0,8.511,3.81,8.511,8.511C55.964,85.226,53.036,88.663,49.149,89.448L49.149,89.448z"/></svg>',CHECK='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 96 96" width="17" height="19" aria-hidden="true"><path fill-rule="evenodd" clip-rule="evenodd" fill="#6BBE66" d="M48,0c26.51,0,48,21.49,48,48S74.51,96,48,96S0,74.51,0,48 S21.49,0,48,0L48,0z M26.764,49.277c0.644-3.734,4.906-5.813,8.269-3.79c0.305,0.182,0.596,0.398,0.867,0.646l0.026,0.025 c1.509,1.446,3.2,2.951,4.876,4.443l1.438,1.291l17.063-17.898c1.019-1.067,1.764-1.757,3.293-2.101 c5.235-1.155,8.916,5.244,5.206,9.155L46.536,63.366c-2.003,2.137-5.583,2.332-7.736,0.291c-1.234-1.146-2.576-2.312-3.933-3.489 c-2.35-2.042-4.747-4.125-6.701-6.187C26.993,52.809,26.487,50.89,26.764,49.277L26.764,49.277z"/></svg>';function renderChip(state){var header=document.querySelector("#CartDrawer .drawer__header");if(header){var chip=header.querySelector(".ab-free-gift-chip");chip||(chip=el("div",null,{class:"drawer__header__item font-nitti uppercase ab-free-gift-chip"}),header.appendChild(chip));var shippingChip=header.querySelector(".drawer__header__item--free-shipping");if(shippingChip&&shippingChip.parentNode){var giftFirst=THRESHOLD<FREE_SHIP_THRESHOLD;giftFirst&&chip.nextSibling!==shippingChip?shippingChip.parentNode.insertBefore(chip,shippingChip):!giftFirst&&shippingChip.nextSibling!==chip&&shippingChip.parentNode.insertBefore(chip,shippingChip.nextSibling)}chip.innerHTML=(state.unlocked?CHECK:LOCK)+"<span>Free <br>Gift</span>"}}function renderBanner(state){var banner=document.querySelector("#CartDrawer .drawer__message");if(banner){var subtotal=state.subtotal,msg;THRESHOLD===FREE_SHIP_THRESHOLD?msg=state.unlocked?"Free shipping + free gift unlocked \uD83C\uDF89":"Add "+formatMoney(THRESHOLD-subtotal)+" for free shipping + a free gift":THRESHOLD<FREE_SHIP_THRESHOLD?state.unlocked?subtotal<FREE_SHIP_THRESHOLD?msg="Add "+formatMoney(FREE_SHIP_THRESHOLD-subtotal)+" for free shipping":msg="Free gift + free shipping unlocked \uD83C\uDF89":msg="Add "+formatMoney(state.remainingCents)+" for your free gift":subtotal<FREE_SHIP_THRESHOLD?msg="Add "+formatMoney(FREE_SHIP_THRESHOLD-subtotal)+" for Free Shipping!":state.unlocked?msg="Free gift unlocked \uD83C\uDF89":msg="Add "+formatMoney(state.remainingCents)+" for your free gift",msg.indexOf("\n")!==-1?banner.innerHTML=msg.split("\n").map(escapeHtml).join("<br>"):banner.textContent=msg,banner.setAttribute("data-ab-free-gift","1")}}function findInsertionTarget(){var drawerContent=document.querySelector("#CartDrawer .drawer__content");if(!drawerContent)return null;var items=drawerContent.querySelector("cart-drawer-items");return{parent:drawerContent,before:items||drawerContent.firstChild}}function removeGiftCard(){var existing=document.querySelector(".ab-free-gift-card");existing&&existing.parentNode.removeChild(existing)}function renderGiftCard(product){var target=findInsertionTarget();if(target){if(!product||product.available===!1){removeGiftCard();return}var img=product.featured_image?product.featured_image+"&width=160":"",title=GIFT.title||product.title||"Free gift",card=el("cart-free-gift",null,{class:"cart__free-gift ab-free-gift-card","data-variant-id":GIFT.variantId});card.innerHTML='<div class="cart__free-gift__image">'+(img?'<img class="cart__free-gift__image-element" src="'+img+'" alt="" loading="lazy" width="80">':"")+'</div><div class="cart__free-gift__title">'+escapeHtml(title)+(GIFT.copy?"<br><small>"+escapeHtml(GIFT.copy)+"</small>":"")+'</div><button type="button" class="cart__free-gift__submit font-nitti uppercase"><span>Add Free Gift</span></button>';var submit=card.querySelector(".cart__free-gift__submit");submit&&submit.addEventListener("click",function(e){e.preventDefault(),addGift(submit)});var existing=document.querySelector(".ab-free-gift-card");return existing?existing.replaceWith(card):target.before?target.parent.insertBefore(card,target.before):target.parent.appendChild(card),card}}function addGift(button){if(mutating)return;mutating=!0,button&&button.classList.add("loading");function done(){mutating=!1,button&&button.classList.remove("loading")}fetchCart().then(function(cart){if(computeState(cart).giftInCart)return log("gift already in cart \u2014 skip add"),setTimeout(sweep,0),null;var props={};return props[OWN_PROP]=OWN_VALUE,fetch("/cart/add.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({items:[{id:GIFT.variantId,quantity:1,properties:props}]})}).then(function(r){if(!r.ok)throw new Error("cart/add "+r.status);return r.json()}).then(function(){lastCart=null;try{typeof publish=="function"&&typeof PUB_SUB_EVENTS!="undefined"&&publish(PUB_SUB_EVENTS.cartUpdate,{source:"ab-free-gift"})}catch(e){}setTimeout(sweep,200)})}).catch(function(e){console.error(PREFIX,"addGift error",e)}).then(done)}function removeGift(giftKey){return mutating||!giftKey?Promise.resolve():(mutating=!0,log("guard: removing gift line",giftKey,"(subtotal under threshold)"),fetch("/cart/change.js",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({id:giftKey,quantity:0})}).then(function(r){if(!r.ok)throw new Error("cart/change "+r.status);return r.json()}).then(function(){lastCart=null;try{typeof publish=="function"&&typeof PUB_SUB_EVENTS!="undefined"&&publish(PUB_SUB_EVENTS.cartUpdate,{source:"ab-free-gift"})}catch(e){}}).catch(function(e){console.error(PREFIX,"removeGift error",e)}).then(function(){mutating=!1}))}function sweep(){if(!sweepInFlight){try{var liveSig=JSON.stringify(window.__TEC_FREE_GIFT_OVERRIDE||{});liveSig!==appliedOverrideSig&&applyConfig()}catch(e){}if(!GIFT.variantId||!GIFT.handle){log("no gift configured \u2014 control behavior");return}sweepInFlight=!0,fetchCart().then(function(cart){var state=computeState(cart),prev=lastState;if(lastState=state,log("state",state),prev&&prev.giftInCart&&!state.giftInCart&&state.unlocked&&!mutating&&setDismissed(!0),state.unlocked||setDismissed(!1),state.giftKey&&!state.unlocked)return removeGift(state.giftKey).then(function(){setTimeout(sweep,200)});if(renderChip(state),renderBanner(state),state.unlocked&&!state.giftInCart&&!isDismissed())return fetchProduct(GIFT.handle).then(function(product){renderGiftCard(product)});removeGiftCard()}).catch(function(err){console.error(PREFIX,"sweep error",err)}).then(function(){sweepInFlight=!1,watchDrawer()})}}var CART_WRITE_RE=/\/cart\/(change|add|update|clear)(\.js)?(\?|$)/;function patchAjax(){var origFetch=window.fetch;origFetch&&!origFetch.__abFreeGiftPatched&&(window.fetch=function(){var args=arguments,url=typeof args[0]=="string"?args[0]:args[0]&&args[0].url||"";return CART_WRITE_RE.test(url)?origFetch.apply(this,args).then(function(res){return lastCart=null,setTimeout(sweep,60),setTimeout(sweep,350),res}):origFetch.apply(this,args)},window.fetch.__abFreeGiftPatched=!0)}function reapplyFromCache(){if(lastState){var header=document.querySelector("#CartDrawer .drawer__header");header&&!header.querySelector(".ab-free-gift-chip")&&renderChip(lastState);var banner=document.querySelector("#CartDrawer .drawer__message");if(banner&&banner.getAttribute("data-ab-free-gift")!=="1"&&renderBanner(lastState),lastState.unlocked&&!lastState.giftInCart&&!isDismissed()&&!document.querySelector(".ab-free-gift-card")){var product=productCache.get(GIFT.handle);product&&renderGiftCard(product)}}}function watchDrawer(){var target=document.getElementById("CartDrawer");!target||target.__abFreeGiftWatched||(target.__abFreeGiftWatched=!0,new MutationObserver(reapplyFromCache).observe(target,{childList:!0,subtree:!0}))}function injectStyles(){if(!document.getElementById("ab-free-gift-styles")){var s=document.createElement("style");s.id="ab-free-gift-styles",s.textContent=".ab-free-gift-card{grid-template-columns:90px 1fr minmax(150px,40%) !important;padding-left:14px !important;padding-right:14px !important;}.ab-free-gift-card .cart__free-gift__submit{padding-inline:8px !important;white-space:nowrap !important;}.drawer__message[data-ab-free-gift]{padding:8px 20px !important;height:auto !important;min-height:55px;box-sizing:border-box;text-align:center;line-height:1.25;}
1@media (width < 400px){.drawer__message[data-ab-free-gift]{min-height:44px;}}",document.head.appendChild(s)}}function exposeApi(){window.TECFreeGift=window.TECFreeGift||{},window.TECFreeGift.configure=function(config){window.__TEC_FREE_GIFT_OVERRIDE=mergeObjects(window.__TEC_FREE_GIFT_OVERRIDE||{},config||{}),applyConfig(),sweep()},window.TECFreeGift.sweep=sweep}function init(){applyConfig(),exposeApi(),injectStyles(),sweep(),patchAjax(),watchDrawer();try{typeof subscribe=="function"&&typeof PUB_SUB_EVENTS!="undefined"&&subscribe(PUB_SUB_EVENTS.cartUpdate,function(){lastCart=null,watchDrawer(),sweep()})}catch(e){}log("init complete")}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",init):init(),window.addEventListener("load",function(){setTimeout(function(){sweep(),watchDrawer()},300),setTimeout(function(){sweep(),watchDrawer()},1500)}),[600,1200,2500].forEach(function(ms){setTimeout(function(){sweep(),watchDrawer()},ms)})})();
2//# sourceMappingURL=/cdn/shop/t/413/assets/ab-sidecart-free-gift.js.map?v=129941593883862563591790672145

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.