PageSourceSearch

https://cdn.assets.rapidlms.com/assets/controllers/checkout_contro…89d9b26f7b4e7ee7f620530fba4135bc46cf2d5a.js

js rapidlms.com collected 2026-09-26 07:17:53 UTC 4,265 bytes, 1 lines download raw bytes

1import{Controller}from"@hotwired/stimulus";import{post}from"@rails/request.js";import{debounce}from"underscore";export default class extends Controller{static values={events:Array,stripeKey:{type:String},stripeImage:{type:String},checkoutDisabled:{type:Boolean,default:!0},requiresShipping:{type:Boolean,default:!1},copyShippingAddyFromBilling:{type:Boolean,default:!0}};static targets=["checkoutForm","stripeBtn","shippingAddyContainer","intent","amount","stripeToken","dropShippingCharges","taxExempt","withoutPayment"];connect(){document.addEventListener("cart:update",this.updateTaxes.bind(this)),this.stripeHandler=window.StripeCheckout.configure({key:this.stripeKeyValue,image:this.stripeImageValue,locale:I18n.locale,token:e=>{this.amountTarget.value=this.amount,this.stripeTokenTarget.value=e.id,this.checkoutFormTarget.submit()}}),this.enableStripeBtn=debounce(this.enableStripeBtn,500).bind(this),Array.from(this.checkoutFormTarget.querySelectorAll("input[required],select[required]")).forEach(e=>{let t=" change->checkout#enableStripeBtn";e.name&&(e.name.includes("billing_address")||e.name.includes("shipping_address"))&&(t+=" change->checkout#updateTaxes",e.name.includes("billing_address")&&(t+=" change->checkout#updateShippingAddress")),e.setAttribute("data-action",(e.getAttribute("data-action")||"")+t)}),this.requiresShippingValue&&(this.copyShippingAddyFromBilling=!this.copyShippingAddyFromBillingValue,this.toggleCopyShippingAddyFromBilling()),this.updateTaxes()}validateForm(){this.checkoutFormTarget.reportValidity()}enableStripeBtn(){const e=Array.from(document.getElementsByClassName("stripe-button"));!this.checkoutDisabledValue&&this.checkoutFormTarget.checkValidity()?e.forEach(e=>{e.disabled=!1}):e.forEach(e=>{e.disabled=!0})}toggleCopyShippingAddyFromBilling(){this.copyShippingAddyFromBilling=!this.copyShippingAddyFromBilling,this.hasShippingAddyContainerTarget&&(this.copyShippingAddyFromBilling?(this.shippingAddyContainerTarget.classList.add("same-as-billing","disabled"),Array.from(this.shippingAddyContainerTarget.querySelectorAll("input,select")).forEac
1h(e=>{e.disabled=!0}),this.updateShippingAddress()):(this.shippingAddyContainerTarget.classList.remove("same-as-billing","disabled"),Array.from(this.shippingAddyContainerTarget.querySelectorAll("input,select")).forEach(e=>{e.disabled=!1})),this.updateTaxes())}updateShippingAddress=debounce(()=>{if(!this.copyShippingAddyFromBilling)return;const e=new FormData(this.checkoutFormTarget);Array.from(e.keys()).forEach(t=>{if(t.includes("billing_address_attributes")){const i=t.replace("billing","shipping");Array.from(this.checkoutFormTarget.querySelectorAll(`input[name="${i}"],select[name="${i}"]`)).forEach(i=>{i.value!=e.get(t)&&(i.value=e.get(t),i.dispatchEvent(new Event("change")))})}})},500);updateTaxes=debounce(()=>{let e=!0;if(Array.from(document.querySelectorAll('[id^="order_form_billing_address_attributes_"]')).forEach(t=>{e&&(e=t.checkValidity())}),!e)return;const t=new FormData(this.checkoutFormTarget),i=this.hasDropShippingChargesTarget&&this.dropShippingChargesTarget.checked,r=this.hasTaxExemptTarget&&this.taxExemptTarget.checked,a={};let s={};Array.from(t.keys()).forEach(e=>{let i=e.match(/\[billing_address_attributes\]\[(.*)\]/i);i?a[i[1]]=t.get(e):this.copyShippingAddyFromBilling||(i=e.match(/\[shipping_address_attributes\]\[(.*)\]/i),i&&(s[i[1]]=t.get(e)))}),0==Object.keys(s).length&&(s=null),post("/orders/tax",{responseKind:"turbo-stream",body:{drop_shipping_charges:i,tax_exempt:r,shipping_address_attributes:s,billing_address_attributes:a,offline_order:"offline_order_form_intent"===this.intentTarget.id}})},1e3);payLater(e){const{amount:t}=e.params;this.withoutPaymentTarget.value="true",this.amountTarget.value=t}openStripePayment(e){if(e.preventDefault(),!this.checkoutDisabledValue&&this.checkoutFormTarget.checkValidity()){const{name:t,email:i,description:r,amount:a,currency:s,intent:n}=e.params;this.intentTarget.value=n,this.amount=a,this.stripeHandler.open({name:t,email:i,description:r,amount:a,currency:s})}}freeCheckout(e){if(e.preventDefault(),!this.checkoutDisabledValue&&this.checkoutFormTarget.checkValidity()){const{intent:t}=e.params;this.amountTarget.value=0,this.intentTarget.value=t,this.checkoutFormTarget.submit()}}}

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.