1 line
2.3 KiB
JavaScript
1 line
2.3 KiB
JavaScript
jQuery.fn.serializeArrayAll=function(){var e=/\r?\n/g;return this.map((function(){return this.elements?jQuery.makeArray(this.elements):this})).map((function(t,r){var n=jQuery(this).val();return null===n?null===n:"checkbox"===this.type&&!1===this.checked?{name:this.name,value:this.checked?this.value:""}:"radio"!==this.type?jQuery.isArray(n)?jQuery.map(n,(function(t,n){return{name:r.name,value:t.replace(e,"\r\n")}})):{name:r.name,value:n.replace(e,"\r\n")}:this.checked?{name:this.name,value:this.checked?this.value:""}:void 0})).get()},jQuery(document).ready((function(){jQuery(document.body).on("click",".single_add_to_cart_button:not(.disabled)",(function(e){var t=jQuery(this),r=t.closest("form.cart"),n=r.find('input:not([name="product_id"]), select, button, textarea').serializeArrayAll()||0,a=-1!==r.attr("action").indexOf("?")?r.attr("action")+"&wc-ajax=get_refreshed_fragments":r.attr("action")+"?wc-ajax=get_refreshed_fragments";e.preventDefault(),t.find("span").length||t.wrapInner("<span></span>"),jQuery(document.body).trigger("adding_to_cart",[t,n]),jQuery.ajax({type:"POST",url:a,data:n,beforeSend:function(){t.removeClass("added").addClass("loading")},complete:function(){t.addClass("added").removeClass("loading")},success:function(e){e.error&&e.product_url?window.location=e.product_url:(void 0!==e.fragments.awb_woo_notices&&jQuery(e.fragments.awb_woo_notices).hasClass("woocommerce-notices-wrapper")&&jQuery(".woocommerce-notices-wrapper").each((function(t){jQuery(this).replaceWith(jQuery(e.fragments.awb_woo_notices).eq(t))})),jQuery(document.body).trigger("added_to_cart",[e.fragments,e.cart_hash,t]))}})})).on("added_to_cart",(function(e,t,r,n){const a=n.parent().parent().parent();if(a.hasClass("fusion-wqv-content-inner"))return void setTimeout((function(){a.closest(".fusion-woocommerce-quick-view-container").find(".fusion-wqv-close button").trigger("click")}),200);if(!jQuery(".woocommerce-notices-wrapper").length||!n.hasClass("single_add_to_cart_button"))return;const o=fusion.getAdminbarHeight();jQuery(".fusion-header-wrapper").find("div").each((function(){"fixed"===jQuery(this).css("position")&&($stickyHeaderHeight=jQuery(this).height())})),jQuery("html, body").stop(),jQuery("html, body").animate({scrollTop:jQuery(".woocommerce-notices-wrapper").offset().top-o-0-10},500)}))})); |