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

1 line
3.2 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("div.woocommerce",c);a("div.woocommerce").replaceWith(d)},g=function(){return a(".shipping-calculator-form").slideToggle("slow"),!1},h=function(c){var e=c.target,f=[];a("select.shipping_method, input[name^=shipping_method][type=radio]:checked, input[name^=shipping_method][type=hidden]").each(function(){f[a(e).data("index")]=a(e).val()}),d(a("div.cart_totals"));var g={security:wc_cart_params.update_shipping_method_nonce,shipping_method:f};a.post(b("update_shipping_method"),g,function(b){a("div.cart_totals").replaceWith(b),a(document.body).trigger("updated_shipping_method")})},i=function(b){b.preventDefault();var c=a(b.target);d(c),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)}})};a(document).on("click",".shipping-calculator-button",g),a(document).on("change","select.shipping_method, input[name^=shipping_method]",h),a(document).on("submit","form.woocommerce-shipping-calculator",i),a(".shipping-calculator-form").hide();var j=function(){d(a("div.cart_totals")),a.ajax({url:b("get_cart_totals"),dataType:"html",success:function(b){a("div.cart_totals").replaceWith(b)}})},k=function(b){var c=a("div.woocommerce > form");a(".woocommerce-error, .woocommerce-message").remove(),c.before(b)},l=function(b){b.preventDefault();var d=a(b.target),e=a(document.activeElement);return window.console.log(e),c(d)?!1:void(e.is('[name="update_cart"]')||e.is("input.qty")?(window.console.log("update cart"),o(d)):(e.is('[name="apply_coupon"]')||e.is("#coupon_code"))&&(window.console.log("apply coupon"),m(d)))},m=function(c){d(c);var f=a("#coupon_code"),g=f.val(),h={security:wc_cart_params.apply_coupon_nonce,coupon_code:g};a.ajax({type:"POST",url:b("apply_coupon"),data:h,dataType:"html",success:function(a){k(a)},complete:function(){e(c),f.val(""),j()}})},n=function(c){c.preventDefault();var f=a(this).parents("tr"),g=a(this).attr("data-coupon");d(f.parents("table"));var h={security:wc_cart_params.remove_coupon_nonce,coupon:g};a.ajax({type:"POST",url:b("remove_coupon"),data:h,dataType:"html",success:function(a){k(a),e(f.parents("table"))},complete:function(){j()}})},o=function(b){a("<input />").attr("type","hidden").attr("name","update_cart").attr("value","Update Cart").appendTo(b),d(b),a.ajax({type:b.attr("method"),url:b.attr("action"),data:b.serialize(),dataType:"html",success:f,complete:function(){e(b)}})},p=function(b){b.preventDefault();var c=a(b.target),g=c.parents("form");d(g),a.ajax({type:"GET",url:c.attr("href"),dataType:"html",success:f,complete:function(){e(g)}})};a(document).on("submit","div.woocommerce > form",l),a(document).on("click","a.woocommerce-remove-coupon",n),a(document).on("click","td.product-remove > a",p)});