woocommerce/assets/js/frontend/cart.min.js

1 line
6.0 KiB
JavaScript
Raw Normal View History

jQuery(function(a){if("undefined"==typeof wc_cart_params)return!1;var b=function(a){return wc_cart_params.wc_ajax_url.toString().replace("%%endpoint%%",a)},c=function(a){return a.is(".processing")},d=function(a){a.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},e=function(a){a.removeClass("processing").unblock()},f=function(b){var c=a.parseHTML(b),d=a("table.shop_table.cart",c).closest("form"),e=a(".cart_totals",c),f=a(".woocommerce-error",c),i=a(".woocommerce-message",c);if(a(".woocommerce-error, .woocommerce-message").remove(),0===d.length){var j=a(".cart-empty",c).closest(".woocommerce");a("table.shop_table.cart").closest(".woocommerce").replaceWith(j),f.length>0?h(f,a(".cart-empty").closest(".woocommerce")):i.length>0&&h(i,a(".cart-empty").closest(".woocommerce"))}else a("table.shop_table.cart").closest("form").replaceWith(d),a("table.shop_table.cart").closest("form").find('input[name="update_cart"]').prop("disabled",!0),f.length>0?h(f):i.length>0&&h(i),g(e);a(document.body).trigger("updated_wc_div")},g=function(b){a(".cart_totals").replaceWith(b),a(document.body).trigger("updated_cart_totals")},h=function(b,c){c||(c=a("table.shop_table.cart").closest("form")),a(".woocommerce-error, .woocommerce-message").remove(),c.before(b)},i={init:function(b){this.cart=b,this.toggle_shipping=this.toggle_shipping.bind(this),this.shipping_method_selected=this.shipping_method_selected.bind(this),this.shipping_calculator_submit=this.shipping_calculator_submit.bind(this),a(document).on("click",".shipping-calculator-button",this.toggle_shipping),a(document).on("change","select.shipping_method, input[name^=shipping_method]",this.shipping_method_selected),a(document).on("submit","form.woocommerce-shipping-calculator",this.shipping_calculator_submit),a(".shipping-calculator-form").hide()},toggle_shipping:function(){return a(".shipping-calculator-form").slideToggle("slow"),!1},shipping_method_selected:function(c){var f=c.currentTarget,h={};a("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(){h[a(f).data("index")]=a(f).val()}),d(a("div.cart_totals"));var i={security:wc_cart_params.update_shipping_method_nonce,shipping_method:h};a.ajax({type:"post",url:b("update_shipping_method"),data:i,dataType:"html",success:function(a){g(a)},complete:function(){e(a("div.cart_totals")),a(document.body).trigger("updated_shipping_method")}})},shipping_calculator_submit:function(b){b.preventDefault();var c=a(b.currentTarget);d(c),d(a("div.cart_totals")),a("<input />").attr("type","hidden").attr("name","calc_shipping").attr("value","x").appendTo(c),a.ajax({type:c.attr("method"),url:c.attr("action"),data:c.serialize(),dataType:"html",success:function(a){f(a)},complete:function(){e(c),e(a("div.cart_totals"))}})}},j={init:function(){this.update_cart_totals=this.update_cart_totals.bind(this),this.cart_submit=this.cart_submit.bind(this),this.submit_click=this.submit_click.bind(this),this.apply_coupon=this.apply_coupon.bind(this),this.remove_coupon_clicked=this.remove_coupon_clicked.bind(this),this.quantity_update=this.quantity_update.bind(this),this.item_remove_clicked=this.item_remove_clicked.bind(this),this.update_cart=this.update_cart.bind(this),a(document).on("wc_update_cart",this.update_cart),a(document).on("click","div.woocommerce > form input[type=submit]",this.submit_click),a(document).on("submit","div.woocommerce > form",this.cart_submit),a(document).on("click","a.woocommerce-remove-coupon",this.remove_coupon_clicked),a(document).on("click","td.product-remove > a",this.item_remove_clicked),a(document).on("change input","div.woocommerce > form .cart_item :input",this.input_changed),a('div.woocommerce > form input[name="update_cart"]').prop("disabled",!0)},input_changed:function(){a('div.woocommerce > form input[name="update_cart"]').prop("disabled",!1)},update_cart:function(){var b=a("table.shop_table.cart").closest("form");d(b),d(a("div.cart_totals")),a.ajax({type:b.attr("method"),url:b.attr("action"),data:b.serialize(),dataType:"htm