1 line
2.1 KiB
JavaScript
1 line
2.1 KiB
JavaScript
jQuery(function(a){if("undefined"==typeof wc_add_to_cart_params)return!1;var b=function(){a(document).on("click",".add_to_cart_button",this.onAddToCart).on("added_to_cart",this.updateButton).on("added_to_cart",this.updateCartPage).on("added_to_cart",this.updateFragments)};b.prototype.onAddToCart=function(b){var c=a(this);if(c.is(".ajax_add_to_cart")){if(!c.attr("data-product_id"))return!0;b.preventDefault(),c.removeClass("added"),c.addClass("loading");var d={};a.each(c.data(),function(a,b){d[a]=b}),a(document.body).trigger("adding_to_cart",[c,d]),a.post(wc_add_to_cart_params.wc_ajax_url.toString().replace("%%endpoint%%","add_to_cart"),d,function(b){if(b)return b.error&&b.product_url?void(window.location=b.product_url):"yes"===wc_add_to_cart_params.cart_redirect_after_add?void(window.location=wc_add_to_cart_params.cart_url):void a(document.body).trigger("added_to_cart",[b.fragments,b.cart_hash,c])})}},b.prototype.updateButton=function(b,c,d,e){e="undefined"!=typeof e&&e,e&&(e.removeClass("loading"),e.addClass("added"),wc_add_to_cart_params.is_cart||0!==e.parent().find(".added_to_cart").length||e.after(' <a href="'+wc_add_to_cart_params.cart_url+'" class="added_to_cart wc-forward" title="'+wc_add_to_cart_params.i18n_view_cart+'">'+wc_add_to_cart_params.i18n_view_cart+"</a>"),a(document.body).trigger("wc_cart_button_updated",[e]))},b.prototype.updateCartPage=function(){var b=window.location.toString().replace("add-to-cart","added-to-cart");a(".shop_table.cart").load(b+" .shop_table.cart:eq(0) > *",function(){a(".shop_table.cart").stop(!0).css("opacity","1").unblock(),a(document.body).trigger("cart_page_refreshed")}),a(".cart_totals").load(b+" .cart_totals:eq(0) > *",function(){a(".cart_totals").stop(!0).css("opacity","1").unblock(),a(document.body).trigger("cart_totals_refreshed")})},b.prototype.updateFragments=function(b,c){c&&(a.each(c,function(b){a(b).addClass("updating").fadeTo("400","0.6").block({message:null,overlayCSS:{opacity:.6}})}),a.each(c,function(b,c){a(b).replaceWith(c),a(b).stop(!0).css("opacity","1").unblock()}),a(document.body).trigger("wc_fragments_loaded"))},new b}); |