PageSourceSearch

https://www.heifer.org/build/js/chunks/ResourcesCart.D1PXXsMW.js

js heifer.org collected 2026-09-24 08:28:23 UTC 6,433 bytes, 1 lines download raw bytes

1import{p as m,a as g,c as d}from"../app.CK3LBLtN.js";function y(){return{step:"cart",errorText:"",successText:"",isSubmitting:!1,productsJSON:"",totalText:null,get isCartStep(){return this.step==="cart"},get isShippingStep(){return this.step==="shipping"},get isSuccessStep(){return this.step==="success"},get showFooter(){return this.cartHasItems||this.isSuccessStep},get showCloseIcon(){return this.isCartStep},get showStepBullets(){return this.isShippingStep||this.isSuccessStep},get cartTotalAmount(){var s,t;return((t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.totalAmount)??0},get resourcesCartItems(){var s,t;return((t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.items)??[]},get cartItemElems(){return Array.from(document.querySelectorAll('[x-data="CartItem"]'))},get cartIsEmpty(){var s,t;return(((t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.items)??[]).length===0},get cartHasItems(){var s,t;return(((t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.items)??[]).length>0},justAddedClass:"just-added",get justAddedItem(){var s,t;return((t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.justAddedItem)??null},get isCartOpen(){var s,t;return((t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.isCartOpen)??!1},get hasOrderedResources(){return Array.isArray(this.orderedResources)&&this.orderedResources.length>0},get orderedResourcesForDisplay(){return(Array.isArray(this.orderedResources)?this.orderedResources:[]).map(function(t,e){const r=t&&(t.name||t.title||t.label||t.resourceName)||"Resource",i=t&&t.quantity?Number(t.quantity):1;return{key:t&&t.id?t.id:e,name:String(r),quantityText:"× "+i,imageUrl:t&&t.image?String(t.image):""}})},get increaseBtnDisabled(){return this.isAtMaxQuantity},get increaseBtnClass(){return this.isAtMaxQuantity?"tw-opacity-40 tw-cursor-not-allowed":""},get shippingSummaryItems(){return(Array.isArray(this.resourcesCartItems)?this.resourcesCartItems:[]).map(function(t,e){const r=t&&(t.name||t.title||t.label||t.resourceName)||"Resource",i=t&&t.quantity?Number(t.quantity):1;return{key:t&&(t.id||t.resourceId||t.sku)?t.id||t.resourceId||t.sku:e,titleText:String(r),qtyText:"Qty: "+i+" / Free",showEdit:e===0}})},updateStepBullets(){var e,r;const s=(e=this.$refs)==null?void 0:e.stepBulletOne,t=(r=this.$refs)==null?void 0:r.stepBulletTwo;!s||!t||(s.classList.toggle("active",this.isShippingStep),t.classList.toggle("active",this.isSuccessStep))},init(){const s=this.resourcesCartItems;s&&s.length&&this.buildProductsJSON(s),this.totalText="Free",this.step="cart",this.errorText="",this.successText="",this.isSubmitting=!1,this.$el.addEventListener("focus",t=>{const e=t.target,r=["INPUT","SELECT","TEXTAREA"],i=this.$el.querySelector(".cart__footer");i!=null&&i.contains(e)||r.includes(e.tagName)&&e.scrollIntoView({behavior:"smooth",block:"center"})},!0),queueMicrotask(()=>{var t;(t=this.$store)!=null&&t.resourcesCart&&(this.$watch("step",()=>{queueMicrotask(()=>this.updateStepBullets())}),this.$watch("$store.resourcesCart.isCartOpen",e=>{e&&(this.step="cart",this.errorText="",this.successText="",this.isSubmitting=!1,this.orderedResources=[],this.totalText=d(this.cartTotalAmount),queueMicrotask(()=>this.updateStepBullets()))}),this.$watch("$store.resourcesCart.items",e=>{var i;const r=Array.isArray(e)?e:[];this.buildProductsJSON(r),this.totalText=d(this.cartTotalAmount),this.handleCartItemClasses(r,(i=this.justAddedItem)==null?void 0:i.sku)}))}),document.addEventListener("submit-free-checkout",t=>{this.handleFreeCheckout(t.detail.form,t.detail.id??null)})},beginCheckout(){g("begin_checkout",this.resourcesCartItems),!this.cartIsEmpty&&(this.step="shipping",queueMicrotask(()=>this.updateStepBullets()))},backToCart(){this.step="cart",this.errorText="",this.successText="",queueMicrotask(()=>this.updateStepBullets())},submitShippingFromButton(){const s=this.$el.querySelector("form");s&&this.submitShipping({target:s})},async submitShipping(s){var t,e,r,i;if(!this.isSubmitting){this.errorText="",this.successText="",this.isSubmitting=!0;try{const a=s&&s.target&&s.target.tagName==="FORM"?s.target:this.$el.querySelector("form");if(!a)throw new Error("Missing form element");const c=new FormData(a),n=(this.resourcesCartItems||[]).map(o=>({id:String((o==null?void 0:o.resourceId)??""),quantity:Number((o==null?void 0:o.quantity)||1)}
1)).filter(o=>o.id),h={};for(let[o,p]of c.entries())h[o]=p;h.ids=n;const u=await(await fetch("/jobs/resource/ship",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(h)})).json();if(!(u!=null&&u.body.success))throw new Error("Submission failed");this.orderedResources=Array.isArray((t=u==null?void 0:u.body)==null?void 0:t.resources)?u.body.resources:[],this.successText="Success! Your free resource will be shipped to you at the address provided.",this.step="success",queueMicrotask(()=>this.updateStepBullets());const l=(e=this.$store)==null?void 0:e.resourcesCart;(i=(r=Alpine.store("resourcesCart"))==null?void 0:r.clearItems)==null||i.call(r),l&&"isCartSaved"in l&&(l.isCartSaved=!1)}catch(a){console.error("Error:",a),this.errorText="There was an error submitting your shipping information. Please try again later."}finally{this.isSubmitting=!1}}},handleCartItemClasses(s,t){!s||!t||this.cartItemElems.forEach(e=>{e.dataset.productSku&&e.dataset.productSku===t?e.classList.add(this.justAddedClass):e.classList.remove(this.justAddedClass)})},buildProductsJSON(s){let t=[];s.forEach(e=>{t=[{resourceId:(e==null?void 0:e.resourceId)||(e==null?void 0:e.id)||(e==null?void 0:e.sku),quantity:(e==null?void 0:e.quantity)??1},...t]}),this.productsJSON=JSON.stringify(t)},closeCart(){var s,t,e;this.step="cart",this.errorText="",this.successText="",this.isSubmitting=!1,(e=(t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.closeCart)==null||e.call(t),queueMicrotask(()=>this.updateStepBullets())},openCart(){var s,t,e;(e=(t=(s=this.$store)==null?void 0:s.resourcesCart)==null?void 0:t.openCart)==null||e.call(t)},removeItem(){var i,a,c,n;const s=this.$el.closest("[data-product-id]"),t=(i=s==null?void 0:s.dataset)==null?void 0:i.productId;if(!t)return;const e=(a=this.$store)==null?void 0:a.resourcesCart,r=(c=e==null?void 0:e.findItemWithMatchingId)==null?void 0:c.call(e,(e==null?void 0:e.items)??[],t);r&&m("remove_from_cart",r),(n=e==null?void 0:e.removeItem)==null||n.call(e,t)}}}export{y as default};

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.