PageSourceSearch

https://onewheel.com/cdn/shop/t/416/assets/cart-insurance-ajax.js?v=27593450865445382551788874451

js onewheel.com collected 2026-10-03 21:37:47 UTC 6,586 bytes, 2 lines download raw bytes

1const insuranceProductID=String(window.OWShipPlus?.variantId||"");let insuranceCheckChain=Promise.resolve(),insuranceBusy=!0,cachedInsuranceItem=null;function rememberInsuranceFromCart(cart){cachedInsuranceItem=cart?getInsuranceItem(cart):null}async function getCart(){return(await fetch(window.Shopify.routes.root+"cart.js")).json()}function getInsuranceItem(cart){return cart.items.find(i=>Number(i.id)===Number(insuranceProductID))}function getRealCartItemCount(cart){return cart.items.reduce((count,item)=>Number(item.id)===Number(insuranceProductID)?count:count+item.quantity,0)}function getShipPlusProperties(){return window.__shipPlusScpProps||scpProps}function hasInsurancePropertyChanges(item){const shipPlusProperties=getShipPlusProperties();return Object.keys(shipPlusProperties).some(key=>String(item.properties?.[key])!==String(shipPlusProperties[key]))}async function insuranceInCart(cart){try{const data=cart||await getCart();rememberInsuranceFromCart(data);const item=getInsuranceItem(data),realItemCount=getRealCartItemCount(data);return item?{inCart:!0,hasChanges:hasInsurancePropertyChanges(item),item,realItemCount}:{inCart:!1,hasChanges:!1,item:null,realItemCount}}catch{return{inCart:!1,hasChanges:!1,item:null,realItemCount:0}}}function setShipPlusLoading(loading){window.OWCartPageAjax?.setSubtotalLoadingState?.(loading)}function setInsuranceToggleEnabled(enabled,options={}){const allowInteraction=options.force===!0||enabled&&!insuranceBusy;document.querySelectorAll("#insurance-toggle").forEach(toggle=>{toggle.disabled=!allowInteraction,toggle.setAttribute("aria-disabled",String(!allowInteraction))})}function setToggleChecked(checked){document.querySelectorAll("#insurance-toggle").forEach(toggle=>{toggle.checked=checked})}function getInsuranceIntent(cart){const item=getInsuranceItem(cart),realItemCount=getRealCartItemCount(cart),inCart=!!item,hasChanges=item?hasInsurancePropertyChanges(item):!1,shipPlusDenied=sessionStorage.getItem("shipPlusDenied");return inCart&&realItemCount===0?{willChange:!0,targetChecked:!1}:(!inCart||hasChanges)&&(!shipPlusDenied||shipPlusDenied==="false")&&realItemCount>0?{willChange:!0,targetChecked:!0}:{willChange:!1,targetChecked:inCart}}async function syncToggleToCart(cart){const{inCart}=await insuranceInCart(cart);document.querySelectorAll("#insurance-toggle").forEach(toggle=>{toggle.checked=inCart})}async function checkInsurance(options={}){const suppressUi=options.suppressUi===!0,{inCart,hasChanges,item,realItemCount}=await insuranceInCart(options.cart),shipPlusDenied=sessionStorage.getItem("shipPlusDenied");return inCart&&realItemCount===0?updateItemInCart(item.key,0,!0,{suppressUi}):(!inCart||hasChanges)&&(!shipPlusDenied||shipPlusDenied==="false")&&realItemCount>0?updateItemInCart(inCart?item.key:insuranceProductID,1,inCart,{suppressUi}):!1}function runInsuranceCheck(options={}){const run=()=>checkInsurance(options);return insuranceCheckChain=insuranceCheckChain.then(run),insuranceCheckChain}function refreshCartAfterInsuranceChange(changed,cart,options={}){if(!changed)return Promise.resolve();const refresh=cartPayload=>{if(window.OWCartPageAjax?.afterCartChange)return window.OWCartPageAjax.afterCartChange(cartPayload,options);window.location.reload()};return cart?refresh(cart):getCart().then(refresh)}async function initInsuranceCheck(){if(!insuranceProductID){insuranceBusy=!1,setInsuranceToggleEnabled(!0);return}insuranceBusy=!0,setInsuranceToggleEnabled(!1);try{let cart=await getCart();rememberInsuranceFromCart(cart);const intent=getInsuranceIntent(cart);setToggleChecked(intent.targetChecked),intent.willChange&&setShipPlusLoading(!0),await checkInsurance({suppressUi:!0,cart})&&(cart=await getCart(),await refreshCartAfterInsuranceChange(!0,cart,{insuranceOnly:!0})),await syncToggleToCart(cart)}catch(error){console.error("Ship+ check failed:",error),await syncToggleToCart()}finally{insuranceBusy=!1,setShipPlusLoading(!1),setInsuranceToggleEnabled(!0,{force:!0})}}function bootInsurance(){insuranceCheckChain=insuranceCheckChain.then(()=>initInsuranceCheck())}document.addEventListener("DOMContentLoaded",bootInsurance);async function handleInsurance(){if(await insuranceCheckChain,insuranceBusy||window.OWCartPageAjax?.isCartUpdating?.()){await syncToggleToCart();return}
1const toggle=document.querySelector("#insurance-toggle");if(!toggle||toggle.disabled)return;const wantsInsurance=toggle.checked;let inCart=!!cachedInsuranceItem,item=cachedInsuranceItem;insuranceBusy=!0,setInsuranceToggleEnabled(!1),setShipPlusLoading(!0);try{if(!wantsInsurance&&inCart&&!item?.key){const state=await insuranceInCart();item=state.item,inCart=state.inCart}if(wantsInsurance===inCart){toggle.checked=inCart;return}wantsInsurance?(sessionStorage.setItem("shipPlusDenied","false"),await updateItemInCart(insuranceProductID,1)):item?.key?(sessionStorage.setItem("shipPlusDenied","true"),await updateItemInCart(item.key,0,!0)):toggle.checked=!1}catch(error){console.error("Ship+ toggle failed:",error),await syncToggleToCart()}finally{insuranceBusy=!1,setInsuranceToggleEnabled(!0),window.OWCartPageAjax?.isCartUpdating?.()||setShipPlusLoading(!1)}}async function updateItemInCart(productID,quantity,inCart,options={}){if(options.suppressUi===!0)return await postCartItemUpdate(productID,quantity,inCart),!0;const doUpdate=async()=>{await postCartItemUpdate(productID,quantity,inCart);const cart2=await getCart();return rememberInsuranceFromCart(cart2),cart2};if(window.OWCartPageAjax?.runCartUpdate)return await window.OWCartPageAjax.runCartUpdate(doUpdate,{insuranceOnly:!0}),!0;const cart=await doUpdate();return await refreshCartAfterInsuranceChange(!0),!0}async function postCartItemUpdate(productID,quantity,inCart){let urlEndpoint="cart/add.js";(quantity===0||inCart)&&(urlEndpoint="cart/change.js");const requestBody={id:productID,quantity};return quantity>0&&(requestBody.properties=getShipPlusProperties()),(await fetch(window.Shopify.routes.root+urlEndpoint,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(requestBody)})).json()}window.OWShipPlus=window.OWShipPlus||{},window.OWShipPlus.getRealCartItemCount=getRealCartItemCount,window.OWShipPlus.getInsuranceItem=getInsuranceItem,window.OWShipPlus.runInsuranceCheck=runInsuranceCheck,window.OWShipPlus.setToggleEnabled=function(enabled,options){setInsuranceToggleEnabled(enabled,options)},window.OWShipPlus.isInsuranceBusy=()=>insuranceBusy,window.OWShipPlus.rememberCart=rememberInsuranceFromCart;
2//# sourceMappingURL=/cdn/shop/t/416/assets/cart-insurance-ajax.js.map?v=27593450865445382551788874451

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.