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

1 line
7.9 KiB
JavaScript

jQuery(function(a){function b(){e&&e.abort();var b=[];a("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(){b[a(this).data("index")]=a(this).val()});var c,d,f,g,h,i,j=a("#order_review input[name=payment_method]:checked").val(),k=a("#billing_country").val(),l=a("#billing_state").val(),m=a("input#billing_postcode").val(),n=a("#billing_city").val(),o=a("input#billing_address_1").val(),p=a("input#billing_address_2").val();a("#ship-to-different-address input").is(":checked")?(c=a("#shipping_country").val(),d=a("#shipping_state").val(),f=a("input#shipping_postcode").val(),g=a("#shipping_city").val(),h=a("input#shipping_address_1").val(),i=a("input#shipping_address_2").val()):(c=k,d=l,f=m,g=n,h=o,i=p),a(".woocommerce-checkout-payment, .woocommerce-checkout-review-order-table").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var q={action:"woocommerce_update_order_review",security:wc_checkout_params.update_order_review_nonce,shipping_method:b,payment_method:j,country:k,state:l,postcode:m,city:n,address:o,address_2:p,s_country:c,s_state:d,s_postcode:f,s_city:g,s_address:h,s_address_2:i,post_data:a("form.checkout").serialize()};e=a.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:q,success:function(b){b&&b.fragments&&(a.each(b.fragments,function(b,c){a(b).replaceWith(c),a(b).unblock()}),a(".woocommerce-checkout").find("input[name=payment_method]:checked").trigger("click"),a("body").trigger("updated_checkout"))}})}function c(){var b=!0;a(f).size()&&($required_inputs=a(f).closest("div").find(".address-field.validate-required"),$required_inputs.size()&&$required_inputs.each(function(){""===a(this).find("input.input-text").val()&&(b=!1)})),b&&(f=!1,a("body").trigger("update_checkout"))}if(a.blockUI.defaults.overlayCSS.cursor="default","undefined"==typeof wc_checkout_params)return!1;var d,e,f=!1;a("body").bind("update_checkout",function(){clearTimeout(d),b()}),a(".checkout_coupon, div.shipping_address").hide(),a("a.showlogin").click(function(){return a("form.login").slideToggle(),!1}),a("a.showcoupon").click(function(){return a(".checkout_coupon").slideToggle(400,function(){a("#coupon_code").focus()}),!1}),a("#ship-to-different-address input").change(function(){a("div.shipping_address").hide(),a(this).is(":checked")&&a("div.shipping_address").slideDown()}).change(),"yes"===wc_checkout_params.option_guest_checkout&&(a("div.create-account").hide(),a("input#createaccount").change(function(){a("div.create-account").hide(),a(this).is(":checked")&&a("div.create-account").slideDown()}).change()),a("#order_review").on("click",".payment_methods input.input-radio",function(){if(a(".payment_methods input.input-radio").length>1){var b=a("div.payment_box."+a(this).attr("ID"));a(this).is(":checked")&&!b.is(":visible")&&(a("div.payment_box").filter(":visible").slideUp(250),a(this).is(":checked")&&a("div.payment_box."+a(this).attr("ID")).slideDown(250))}else a("div.payment_box").show();a("#place_order").val(a(this).data("order_button_text")?a(this).data("order_button_text"):a("#place_order").data("value"))}).find("input[name=payment_method]:checked").click(),a("form.checkout").on("input 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]",function(){clearTimeout(d),f=!1,a("body").trigger("update_checkout")}).on("change",".address-field input.input-text, .update_totals_on_change input.input-text",function(){f&&c()}).on("input change",".address-field select",function(){f=this,c()}).on("input keydown",".address-field input.input-text, .update_totals_on_change input.input-text",function(a){var b=a.keyCode||a.which||0;return 9===b?!0:(f=this,clearTimeout(d),void(d=setTimeout(c,"1000")))}).on("blur input change",".input-text, select",function(){var b=a(this),c=b.closest(".form-row"),d=!0;if(c.is(".validate-required")&&""===b.val()&&(c.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-required-field"),d=!1),c.is(".validate-email")&&b.val()){var e=new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);e.test(b.val())||(c.removeClass("woocommerce-validated").addClass("woocommerce-invalid woocommerce-invalid-email"),d=!1)}d&&c.removeClass("woocommerce-invalid woocommerce-invalid-required-field").addClass("woocommerce-validated")}).submit(function(){clearTimeout(d);var b=a(this);if(b.is(".processing"))return!1;if(b.triggerHandler("checkout_place_order")!==!1&&b.triggerHandler("checkout_place_order_"+a("#order_review input[name=payment_method]:checked").val())!==!1){b.addClass("processing");var c=b.data();1!=c["blockUI.isBlocked"]&&b.block({message:null,overlayCSS:{background:"#fff",opacity:.6}}),a.ajax({type:"POST",url:wc_checkout_params.checkout_url,data:b.serialize(),success:function(c){var d="";try{if(c.indexOf("<!--WC_START-->")>=0&&(c=c.split("<!--WC_START-->")[1]),c.indexOf("<!--WC_END-->")>=0&&(c=c.split("<!--WC_END-->")[0]),d=a.parseJSON(c),"success"!==d.result)throw"failure"===d.result?"Result failure":"Invalid response";window.location=-1!=d.redirect.indexOf("https://")||-1!=d.redirect.indexOf("http://")?d.redirect:decodeURI(d.redirect)}catch(e){if("true"===d.reload)return void window.location.reload();a(".woocommerce-error, .woocommerce-message").remove(),b.prepend(d.messages?d.messages:c),b.removeClass("processing").unblock(),b.find(".input-text, select").blur(),a("html, body").animate({scrollTop:a("form.checkout").offset().top-100},1e3),"true"===d.refresh&&a("body").trigger("update_checkout"),a("body").trigger("checkout_error")}},dataType:"html"})}return!1}),a("form.checkout_coupon").submit(function(){var b=a(this);if(b.is(".processing"))return!1;b.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var c={action:"woocommerce_apply_coupon",security:wc_checkout_params.apply_coupon_nonce,coupon_code:b.find("input[name=coupon_code]").val()};return a.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:c,success:function(c){a(".woocommerce-error, .woocommerce-message").remove(),b.removeClass("processing").unblock(),c&&(b.before(c),b.slideUp(),a("body").trigger("update_checkout"))},dataType:"html"}),!1}),a(".woocommerce-checkout-review-order").on("click",".woocommerce-remove-coupon",function(b){b.preventDefault();var c=a(this).parents(".woocommerce-checkout-review-order"),d=a(this).data("coupon");c.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}});var e={action:"woocommerce_remove_coupon",security:wc_checkout_params.remove_coupon_nonce,coupon:d};a.ajax({type:"POST",url:wc_checkout_params.ajax_url,data:e,success:function(b){a(".woocommerce-error, .woocommerce-message").remove(),c.removeClass("processing").unblock(),b&&(c.before(b),a("body").trigger("update_checkout"),a("form.checkout_coupon").find('input[name="coupon_code"]').val(""))},dataType:"html"})}),a("body").bind("init_checkout",function(){a("#billing_country, #shipping_country, .country_to_state").change(),a("body").trigger("update_checkout")}),"1"===wc_checkout_params.is_checkout&&a("body").trigger("init_checkout")});