| 1 |
"use strict";var merchant=merchant||{};merchant.customAddToCartButton={domReady:function(t){if("function"==typeof t)return"interactive"===document.readyState||"complete"===document.readyState?t():void document.addEventListener("DOMContentLoaded",t,!1)},init:function(){var t=document.querySelectorAll(".merchant-custom-addtocart");if(!t.length)return!1;for(var e=0;e<t.length;e++)t[e].addEventListener("click",function(t){t.preventDefault();var e=this,t=this.getAttribute("data-product-id"),n=this.innerHTML,d=this.getAttribute("data-loading-text"),r=this.getAttribute("data-added-text"),a=this.getAttribute("data-nonce"),o=new XMLHttpRequest;o.open("POST",merchant.setting.ajax_url,!0),o.setRequestHeader("Content-type","application/x-www-form-urlencoded"),e.innerHTML=d,o.onload=function(){200<=this.status&&this.status<400&&(e.innerHTML=r,setTimeout(function(){e.innerHTML=n},1500),jQuery(document.body).trigger("wc_fragment_refresh"),jQuery(document.body).trigger("added_to_cart"),document.body.dispatchEvent(new Event("merchant.custom_added_to_cart")))},o.send("action=merchant_custom_addtocart&product_id="+t+"&nonce="+a)})}},merchant.customAddToCartButton.domReady(function(){merchant.customAddToCartButton.init()}); |