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

1 line
7.1 KiB
JavaScript
Raw Normal View History

jQuery(function(t){if("undefined"==typeof wc_cart_params)return!1;var e=function(t){return wc_cart_params.wc_ajax_url.toString().replace("%%endpoint%%",t)},o=function(t){return t.is(".processing")||t.parents(".processing").length},c=function(t){o(t)||t.addClass("processing").block({message:null,overlayCSS:{background:"#fff",opacity:.6}})},i=function(t){t.removeClass("processing").unblock()},r=function(e,o){var c=t.parseHTML(e),i=t(".woocommerce-cart-form",c),r=t(".cart_totals",c),s=t(".woocommerce-error, .woocommerce-message, .woocommerce-info",c);if(0!==t(".woocommerce-cart-form").length){if(o||t(".woocommerce-error, .woocommerce-message, .woocommerce-info").remove(),0===i.length){if(t(".woocommerce-checkout").length)return void(window.location.href=window.location.href);var p=t(".cart-empty",c).closest(".woocommerce");t(".woocommerce-cart-form__contents").closest(".woocommerce").replaceWith(p),s.length>0&&n(s,t(".cart-empty").closest(".woocommerce"))}else t(".woocommerce-checkout").length&&t(document.body).trigger("update_checkout"),t(".woocommerce-cart-form").replaceWith(i),t(".woocommerce-cart-form").find('input[name="update_cart"]').prop("disabled",!0),s.length>0&&n(s),a(r);t(document.body).trigger("updated_wc_div")}else window.location.href=window.location.href},a=function(e){t(".cart_totals").replaceWith(e),t(document.body).trigger("updated_cart_totals")},n=function(e,o){o||(o=t(".woocommerce-cart-form")),o.before(e)},s={init:function(e){this.cart=e,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),t(document).on("click",".shipping-calculator-button",this.toggle_shipping),t(document).on("change","select.shipping_method, input[name^=shipping_method]",this.shipping_method_selected),t(document).on("submit","form.woocommerce-shipping-calculator",this.shipping_calculator_submit),t(".shipping-calculator-form").hide()},toggle_shipping:function(){return t(".shipping-calculator-form").slideToggle("slow"),!1},shipping_method_selected:function(o){var r=o.currentTarget,n={};t("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(){n[t(r).data("index")]=t(r).val()}),c(t("div.cart_totals"));var s={security:wc_cart_params.update_shipping_method_nonce,shipping_method:n};t.ajax({type:"post",url:e("update_shipping_method"),data:s,dataType:"html",success:function(t){a(t)},complete:function(){i(t("div.cart_totals")),t(document.body).trigger("updated_shipping_method")}})},shipping_calculator_submit:function(e){e.preventDefault();var o=t(e.currentTarget);c(t("div.cart_totals")),c(o),t("<input />").attr("type","hidden").attr("name","calc_shipping").attr("value","x").appendTo(o),t.ajax({type:o.attr("method"),url:o.attr("action"),data:o.serialize(),dataType:"html",success:function(t){r(t)},complete:function(){i(o),i(t("div.cart_totals"))}})}},p={init:function(){this.update_cart_totals=this.update_cart_totals.bind(this),this.input_keypress=this.input_keypress.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.item_restore_clicked=this.item_restore_clicked.bind(this),this.update_cart=this.update_cart.bind(this),t(document).on("wc_update_cart",this.update_cart),t(document).on("click",".woocommerce-cart-form input[type=submit]",this.submit_click),t(document).on("keypress",".woocommerce-cart-form input[type=number]",this.input_keypress),t(document).on("submit",".woocommerce-cart-form",this.cart_submit),t(document).on("click","a.woocommerce-remove-coupon",this.remove_coupon_clicked),t(document).on("click",".woocommerce-cart-form .product-remove > a",this.item_remove_clicked),t(document).on("click",".woocommerce-cart .restore-item",this.item_r