woocommerce/assets/js/frontend/checkout.min.js

1 line
13 KiB
JavaScript
Raw Normal View History

jQuery(function(e){if("undefined"==typeof wc_checkout_params)return!1;e.blockUI.defaults.overlayCSS.cursor="default";var t={updateTimer:!1,dirtyInput:!1,selectedPaymentMethod:!1,xhr:!1,$order_review:e("#order_review"),$checkout_form:e("form.checkout"),init:function(){e(document.body).bind("update_checkout",this.update_checkout),e(document.body).bind("init_checkout",this.init_checkout),this.$checkout_form.on("click",'input[name="payment_method"]',this.payment_method_selected),e(document.body).hasClass("woocommerce-order-pay")&&this.$order_review.on("click",'input[name="payment_method"]',this.payment_method_selected),this.$checkout_form.attr("novalidate","novalidate"),this.$checkout_form.on("submit",this.submit),this.$checkout_form.on("input validate change",".input-text, select, input:checkbox",this.validate_field),this.$checkout_form.on("update",this.trigger_update_checkout),this.$checkout_form.on("change",'select.shipping_method, input[name^="shipping_method"], #ship-to-different-address input, .update_totals_on_change select, .update_totals_on_change input[type="radio"], .update_totals_on_change input[type="checkbox"]',this.trigger_update_checkout),this.$checkout_form.on("change",".address-field select",this.input_changed),this.$checkout_form.on("change",".address-field input.input-text, .update_totals_on_change input.input-text",this.maybe_input_changed),this.$checkout_form.on("keydown",".address-field input.input-text, .update_totals_on_change input.input-text",this.queue_update_checkout),this.$checkout_form.on("change","#ship-to-different-address input",this.ship_to_different_address),this.$checkout_form.find("#ship-to-different-address input").change(),this.init_payment_methods(),"1"===wc_checkout_params.is_checkout&&e(document.body).trigger("init_checkout"),"yes"===wc_checkout_params.option_guest_checkout&&e("input#createaccount").change(this.toggle_create_account).change()},init_payment_methods:function(){var o=e(".woocommerce-checkout").find('input[name="payment_method"]');1===o.length&&o.eq(0).hide(),t.selectedPaymentMethod&&e("#"+t.selectedPaymentMethod).prop("checked",!0),0===o.filter(":checked").length&&o.eq(0).prop("checked",!0),o.filter(":checked").eq(0).trigger("click")},get_payment_method:function(){return t.$checkout_form.find('input[name="payment_method"]:checked').val()},payment_method_selected:function(){if(e(".payment_methods input.input-radio").length>1){var o=e("div.payment_box."+e(this).attr("ID"));e(this).is(":checked")&&!o.is(":visible")&&(e("div.payment_box").filter(":visible").slideUp(250),e(this).is(":checked")&&e("div.payment_box."+e(this).attr("ID")).slideDown(250))}else e("div.payment_box").show();e(this).data("order_button_text")?e("#place_order").text(e(this).data("order_button_text")):e("#place_order").text(e("#place_order").data("value"));var c=e('.woocommerce-checkout input[name="payment_method"]:checked').attr("id");c!==t.selectedPaymentMethod&&e(document.body).trigger("payment_method_selected"),t.selectedPaymentMethod=c},toggle_create_account:function(){e("div.create-account").hide(),e(this).is(":checked")&&(e("#account_password").val("").change(),e("div.create-account").slideDown())},init_checkout:function(){e("#billing_country, #shipping_country, .country_to_state").change(),e(document.body).trigger("update_checkout")},maybe_input_changed:function(e){t.dirtyInput&&t.input_changed(e)},input_changed:function(e){t.dirtyInput=e.target,t.maybe_update_checkout()},queue_update_checkout:function(e){if(9===(e.keyCode||e.which||0))return!0;t.dirtyInput=this,t.reset_update_checkout_timer(),t.updateTimer=setTimeout(t.maybe_update_checkout,"1000")},trigger_update_checkout:function(){t.reset_update_checkout_timer(),t.dirtyInput=!1,e(document.body).trigger("update_checkout")},maybe_update_checkout:function(){var o=!0;if(e(t.dirtyInput).length){var c=e(t.dirtyInput).closest("div").find(".address-field.validate-required");c.length&&c.each(function(){""===e(this).find("input.input-text").val()&&(o=!1)})}o&&t.trigger_update_checkout()},ship_to_different_address:function(){e("div.shipping_address")