laipower/wp-content/plugins/easy-digital-downloads/assets/js/edd-checkout-global.js

1 line
8.7 KiB
JavaScript

!function(e){var t={};function d(a){if(t[a])return t[a].exports;var n=t[a]={i:a,l:!1,exports:{}};return e[a].call(n.exports,n,n.exports,d),n.l=!0,n.exports}d.m=e,d.c=t,d.d=function(e,t,a){d.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},d.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},d.t=function(e,t){if(1&t&&(e=d(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(d.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)d.d(a,n,function(t){return e[t]}.bind(null,n));return a},d.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return d.d(t,"a",t),t},d.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},d.p="",d(d.s=231)}({1:function(e,t){e.exports=jQuery},13:function(e,t,d){"use strict";(function(e){d.d(t,"a",(function(){return a})),d.d(t,"b",(function(){return o}));var a=function(e){var t,d=e;switch(e){case"amex":d="americanexpress",t=32;break;default:t=50}return"\n <svg\n width=".concat(t,"\n height=",32,'\n class="payment-icon icon-').concat(d,'"\n role="img"\n >\n <use\n href="#icon-').concat(d,'"\n xlink:href="#icon-').concat(d,'">\n </use>\n </svg>')},n=0;function o(t){if("1"==edd_global_vars.taxes_enabled){var d=document.getElementsByClassName("edd_cart_tax");if(d.length>0&&!d[0].querySelector(".edd-recalculate-taxes-loading")){d=d[0];var a=document.createElement("span"),o=document.getElementsByClassName("edd_cart_tax_amount");o.length>0&&d.removeChild(o[0]),a.classList.add("edd-loading-ajax","edd-recalculate-taxes-loading","edd-loading"),d.appendChild(a)}var r=e("#edd_cc_address"),c=r.find("#billing_country").val(),i=r.find("#card_address").val(),l=r.find("#card_address_2").val(),s=r.find("#card_city").val(),u=r.find("#card_state").val();t||(t=u);var _={action:"edd_recalculate_taxes",card_address:i,card_address_2:l,card_city:s,card_zip:r.find("#card_zip").val(),state:t,billing_country:c,nonce:e("#edd-checkout-address-fields-nonce").val(),current_page:edd_global_vars.current_page},f=++n;return e.ajax({type:"POST",data:_,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(t){if(f===n){t.html&&e("#edd_checkout_cart_form").replaceWith(t.html),e(".edd_cart_amount").html(t.total);var d=new Object;d.postdata=_,d.response=t,e("body").trigger("edd_taxes_recalculated",[d])}e(".edd-recalculate-taxes-loading").remove()}}).fail((function(t){window.console&&window.console.log&&(console.log(t),f===n&&e("body").trigger("edd_taxes_recalculated",[tax_data]))}))}}}).call(this,d(1))},231:function(e,t,d){"use strict";d.r(t),d(232);var a=d(13);window.recalculate_taxes=a.b,window.EDD_Checkout=function(e){var t,d,n;function o(d){d.preventDefault();var o=e("#edd-discount").val(),r=e("#edd-discount-loader"),c=e("#edd_cc_address .edd-input, #edd_cc_address .edd-select").filter("[required]");if(""==o||o==edd_global_vars.enter_discount)return!1;var i={action:"edd_apply_discount",code:o,form:e("#edd_purchase_form").serialize(),current_page:edd_global_vars.current_page};return e("#edd-discount-error-wrap").html("").hide(),r.show(),e.ajax({type:"POST",data:i,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(d){d?"valid"==d.msg?(e(".edd_cart_discount").html(d.html),e(".edd_cart_discount_row").show(),e(".edd_cart_amount").each((function(){e(this).text(d.total),e(this).data("total",d.total_plain)})),e("#edd-discount",n).val(""),Object(a.b)(),"0.00"==d.total_plain?(e("#edd_cc_fields,#edd_cc_address,#edd_payment_mode_select").slideUp(),c.prop("required",!1),e('input[name="edd-gateway"]').val("manual")):(c.prop("required",!0),e("#edd_cc_fields,#edd_cc_address").slideDown()),t.trigger("edd_discount_applied",[d])):(e("#edd-discount-error-wrap").html('<span class="edd_error">'+d.msg+"</span>"),e("#edd-discount-error-wrap").show(),t.trigger("edd_discount_invalid",[d])):(window.console&&window.console.log&&console.log(d),t.trigger("edd_discount_failed",[d])),r.hide()}}).fail((function(e){window.console&&window.console.log&&console.log(e)})),!1}function r(d){var n={action:"edd_remove_discount",code:e(this).data("code"),current_page:edd_global_vars.current_page};return e.ajax({type:"POST",data:n,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(d){var n="0"+edd_global_vars.decimal_separator+"00";e(".edd_cart_amount").each((function(){edd_global_vars.currency_sign+n!=e(this).text()&&n+edd_global_vars.currency_sign!=e(this).text()||window.location.reload(),e(this).text(d.total),e(this).data("total",d.total_plain)})),e(".edd_cart_discount").html(d.html),d.discounts&&0===d.discounts.length&&e(".edd_cart_discount_row").hide(),Object(a.b)(),e("#edd_cc_fields,#edd_cc_address").slideDown(),t.trigger("edd_discount_removed",[d])}}).fail((function(e){window.console&&window.console.log&&console.log(e)})),!1}function c(d){var a=e(this),n=a.val(),o=a.data("key"),r=a.closest(".edd_cart_item").data("download-id"),c=a.parent().find('input[name="edd-cart-download-'+o+'-options"]').val(),i=e("#edd_cc_address"),l={action:"edd_update_quantity",quantity:n,download_id:r,options:c,billing_country:i.find("#billing_country").val(),card_state:i.find("#card_state").val(),current_page:edd_global_vars.current_page};return e.ajax({type:"POST",data:l,dataType:"json",url:edd_global_vars.ajaxurl,xhrFields:{withCredentials:!0},success:function(d){e(".edd_cart_subtotal_amount").each((function(){e(this).text(d.subtotal)})),e(".edd_cart_tax_amount").each((function(){e(this).text(d.taxes).data("tax",d.taxes_raw).attr("data-tax",d.taxes_raw)})),e(".edd_cart_discount").html(d.discounts),e(".edd_cart_amount").each((function(){e(this).text(d.total).data("subtotal",d.subtotal_raw).attr("data-subtotal",d.subtotal_raw).data("total",d.total_raw).attr("data-total",d.total_raw),t.trigger("edd_quantity_updated",[d])}))}}).fail((function(e){window.console&&window.console.log&&console.log(e)})),!1}return{init:function(){t=e(document.body),d=e("#edd_purchase_form"),e(".edd_cart_amount").text(),n=e("#edd_checkout_form_wrap"),t.on("edd_gateway_loaded",(function(e){var t,a,n,o;a=(t=d).find(".card-number"),n=t.find(".card-cvc"),o=t.find(".card-expiry"),a.length&&"function"==typeof a.payment&&(a.payment("formatCardNumber"),n.payment("formatCardCVC"),o.payment("formatCardExpiry"))})),t.on("keyup change",".edd-do-validate .card-number",(function(){var t,d;t=e(this),(d=t).validateCreditCard((function(t){var n=e(".card-type");null==t.card_type?(n.removeClass().addClass("off card-type"),d.removeClass("valid"),d.addClass("error")):(n.removeClass("off"),n.html(Object(a.a)(t.card_type.name)),n.addClass(t.card_type.name),t.length_valid&&t.luhn_valid?(d.addClass("valid"),d.removeClass("error")):(d.removeClass("valid"),d.addClass("error")))}))})),t.on("blur change",".card-name",(function(){var t=e(this);t.validateCreditCard((function(d){null!=d.card_type?(t.removeClass("valid").addClass("error"),e("#edd-purchase-button").attr("disabled","disabled")):(t.removeClass("error").addClass("valid"),e("#edd-purchase-button").removeAttr("disabled"))}))})),t.on("submit","#edd_payment_mode",(function(){if(0==e("#edd-gateway option:selected").val())return alert(edd_global_vars.no_gateway),!1})),t.on("click","#edd_payment_mode_select input",(function(){e("#edd_payment_mode_select label.edd-gateway-option-selected").removeClass("edd-gateway-option-selected"),e("#edd_payment_mode_select input:checked").parent().addClass("edd-gateway-option-selected")})),n.on("click",".edd-apply-discount",o),n.on("keypress","#edd-discount",(function(e){if("13"==e.keyCode)return!1})),n.on("keyup","#edd-discount",(function(e){"13"==e.keyCode&&n.find(".edd-apply-discount").trigger("click")})),t.on("click",".edd_discount_remove",r),t.on("click",".edd_discount_link",(function(t){t.preventDefault(),e(".edd_discount_link").parent().hide(),e("#edd-discount-code-wrap").show().find("#edd-discount").focus()})),t.find("#edd-discount-code-wrap").hide(),t.find("#edd_show_discount").show(),t.on("change",".edd-item-quantity",c),t.on("click",".edd-amazon-logout #Logout",(function(e){e.preventDefault(),amazon.Login.logout(),window.location=edd_amazon.checkoutUri}))},recalculate_taxes:a.b}}(window.jQuery),window.jQuery(document).ready(EDD_Checkout.init)},232:function(e,t,d){"use strict";(function(e){var t=d(4);Object(t.a)((function(){e(document.body).on("click",".edd_terms_links",(function(t){t.preventDefault();var d=e(this).parent();d.prev(".edd-terms").slideToggle(),d.find(".edd_terms_links").toggle()}))}))}).call(this,d(1))},4:function(e,t,d){"use strict";(function(e){d.d(t,"a",(function(){return a}));var a=function(t){e(t)}}).call(this,d(1))}});