| 2 |
CHARITABLE=window.CHARITABLE||{},function(a,b){var c=function(a){this.errors=[],this.form=a,this.pause_processing=!1,this.submit_processing=!1;var c=this,d=b("body"),e=function(){return c.form.find(".charitable-terms-text").addClass("active"),!1},f=function(){b(this).closest("li").trigger("click").find("input[name=donation_amount]").prop("checked",!0).trigger("change"),c.form.off("focus","input.custom-donation-input",f),b(this).focus(),c.form.on("focus","input.custom-donation-input",f)},g=function(){var a=c.unformat_amount(b(this).val());b.trim(a)>0&&b(this).val(c.format_amount(a))},h=function(){var a=b(this).closest("li");a.hasClass("selected")||(a.parents(".charitable-donation-form").find(".donation-amount.selected").removeClass("selected"),a.addClass("selected"),a.hasClass("custom-donation-amount")&&a.find("input.custom-donation-input").focus())},i=function(){c.hide_inactive_payment_methods(),c.show_active_payment_methods(b(this).val())},j=function(a){var b=a.data.helper;return!b.submit_processing&&(b.submit_processing=!0,b.show_processing(),!1===b.validate()?(b.hide_processing(),b.print_errors(),b.scroll_to_top(),!1):!1===b.pause_processing&&(1!==b.form.data("use-ajax")||(d.trigger("charitable:form:process",b),!1)))},k=function(a,c){var d=c.get_data();c.form;return d.action="make_donation",d.form_action=d.charitable_action,delete d.charitable_action,b.ajax({type:"POST",data:d,dataType:"json",url:CHARITABLE_VARS.ajaxurl,timeout:0,xhrFields:{withCredentials:!0},success:function(a){a.success?window.location.href=a.redirect_to:(c.hide_processing(),c.print_errors(a.errors),c.scroll_to_top(),a.donation_id&&c.set_donation_id(a.donation_id))}}).fail(function(a,b,d){window.console&&window.console.log&&console.log(a),c.hide_processing(),c.print_errors([CHARITABLE_VARS.error_unknown]),c.scroll_to_top()}),!1},l=function(){c.form.on("click",".donation-amount",h),c.form.on("focus","input.custom-donation-input",f),c.form.on("click",".charitable-terms-link",e),c.form.on("blur",".custom-donation-input",g),c.form.find(".donation-amount input:checked").each(function(){b(this).closest("li").addClass("selected")}),c.get_all_payment_methods().length&&(c.hide_inactive_payment_methods(),c.form.on("change","#charitable-gateway-selector input[name=gateway]",i)),c.form.on("submit",{helper:c},j),!1===CHARITABLE.forms_initialized&&(d.on("charitable:form:process",k),d.trigger("charitable:form:initialize",c),CHARITABLE.forms_initialized=!0),d.trigger("charitable:form:loaded",c)};l()};c.prototype.get_input=function(a){return this.form.find("[name="+a+"]")},c.prototype.get_email=function(){return this.form.find("[name=email]").val()},c.prototype.get_suggested_amount=function(){return accounting.unformat(this.form.find("[name=donation_amount]:checked, input[type=hidden][name=donation_amount]").val(),CHARITABLE_VARS.currency_format_decimal_sep)},c.prototype.get_custom_amount=function(){var a=this.form.find(".charitable-donation-options.active .custom-donation-input");return 0===a.length&&(a=this.form.find(".custom-donation-input")),accounting.unformat(a.val(),CHARITABLE_VARS.currency_format_decimal_sep)},c.prototype.get_amount=function(){return this.get_suggested_amount()||this.get_custom_amount()},c.prototype.get_description=function(){return this.form.find("[name=description]").val()||""},c.prototype.get_cc_number=function(){return this.form.find("#charitable_field_cc_number input").val()||""},c.prototype.get_cc_cvc=function(){return this.form.find("#charitable_field_cc_cvc input").val()||""},c.prototype.get_cc_expiry_month=function(){return this.form.find("#charitable_field_cc_expiration select.month").val()||""},c.prototype.get_cc_expiry_year=function(){return this.form.find("#charitable_field_cc_expiration select.year").val()||""},c.prototype.clear_cc_fields=function(){this.form.find("#charitable_field_cc_number input, #charitable_field_cc_name input, #charitable_field_cc_cvc input, #charitable_field_cc_expiration select").removeAttr("name")},c.prototype.get_payment_method=function(){return this.form.find("[type=hidden][name=gateway], [name=gateway]:checked").val()||""},c.prototype.get_all_payment_methods=function(){return this.form.find("#charitable-gateway-selector input[name=gateway]")},c.prototype.hide_inactive_payment_methods=function(){var a=this.get_payment_method(),b=this.form.find(".charitable-gateway-fields[data-gateway!="+a+"]");b.hide(),b.find("input[required],select[required],textarea[required]").attr("data-required",1).attr("required",!1)},c.prototype.show_active_payment_methods=function(a){var a=a||this.get_payment_method(),b=this.form.find(".charitable-gateway-fields[data-gateway="+a+"]");b.show(),b.find("[data-required]").attr("required",!0)},c.prototype.format_amount=function(a,b){return"undefined"==typeof b&&(b=""),accounting.formatMoney(a,{symbol:b,decimal:CHARITABLE_VARS.currency_format_decimal_sep,thousand:CHARITABLE_VARS.currency_format_thousand_sep,precision:CHARITABLE_VARS.currency_format_num_decimals,format:CHARITABLE_VARS.currency_format}).trim()},c.prototype.unformat_amount=function(a){return Math.abs(parseFloat(accounting.unformat(a,CHARITABLE_VARS.currency_format_decimal_sep)))},c.prototype.add_error=function(a){this.errors.push(a)},c.prototype.get_errors=function(){return this.errors},c.prototype.get_error_message=function(){return this.errors.join(" ")},c.prototype.print_errors=function(a){var b=a||this.errors,c=b.length,d="";0!==c&&(this.form.find(".charitable-form-errors").length&&this.form.find(".charitable-form-errors").remove(),d+='<div class="charitable-form-errors charitable-notice"><ul class="errors"><li>',d+=b.join("</li><li>"),d+="</li></ul></div>",this.form.prepend(d))},c.prototype.clear_errors=function(){this.errors=[],this.form.find(".charitable-form-errors").length&&this.form.find(".charitable-form-errors").remove()},c.prototype.show_processing=function(){this.form.find(".charitable-form-processing").show(),this.form.find('button[name="donate"]').hide()},c.prototype.hide_processing=function(){this.form.find(".charitable-form-processing").hide(),this.form.find('button[name="donate"]').show(),this.submit_processing=!1,this.pause_processing=!1},c.prototype.scroll_to_top=function(){var a=this.form.parents(".charitable-modal");a.length?a.scrollTop(0):window.scrollTo(this.form.position().left,this.form.position().top)},c.prototype.set_donation_id=function(a){this.form.find("[name=ID]").val(a)},c.prototype.get_data=function(){return this.form.serializeArray().reduce(function(a,b){return a[b.name]=b.value,a},{})},c.prototype.get_required_fields=function(){var a=this.form.find(".charitable-fieldset .required-field").not("#charitable-gateway-fields .required-field"),c=this.get_payment_method();if(""!==c){var d=this.form.find("[data-gateway="+c+"] .required-field");d.length&&(a=b.merge(a,d))}return a},c.prototype.is_valid_amount=function(){var a=parseFloat(CHARITABLE_VARS.minimum_donation);return a>0?this.get_amount()>=a:this.get_amount()>=a},c.prototype.validate_amount=function(){return!1!==this.is_valid_amount()||(this.add_error(CHARITABLE_VARS.error_invalid_amount),!1)},c.prototype.validate_required_fields=function(){var a=!0;this.get_required_fields();return this.get_required_fields().each(function(){""===b(this).find("input, select, textarea").val()&&(a=!1)}),a||this.add_error(CHARITABLE_VARS.error_required_fields),a},c.prototype.validate=function(){return this.clear_errors(),this.validate_amount(),this.validate_required_fields(),this.form.trigger("charitable:form:validate",this),0===this.errors.length},a.Donation_Form=c}(CHARITABLE,jQuery),function(a,b){var c=function(){var c=function(){d(b(this)).addClass("charitable-hidden")},d=function(a){var c=a.data("charitable-toggle");return"."!==c[0]&&"#"!==c[0]&&(c="#"+c),b(c)},e=function(){var a=b(this),c=d(a);return c.toggleClass("charitable-hidden",function(){return a.is(":checkbox")?!a.is(":checked"):!1===c.hasClass("charitable-hidden")}()),!1},f=function(){b("[data-charitable-toggle]").each(c)};if(b("body").on("click","[data-charitable-toggle]",e),a.content_loading)var g=setInterval(function(){!1===a.content_loading&&(f(),clearInterval(g))},500);return f};a.Toggle=c()}(CHARITABLE,jQuery),function(a,b){}(CHARITABLE,jQuery),CHARITABLE.SanitizeURL=function(a){CHARITABLE.Helpers.sanitize_url(a)},function(a){CHARITABLE.forms_initialized=!1,a(document).ready(function(){a("html").addClass("js"),a(".charitable-donation-form").each(function(){new CHARITABLE.Donation_Form(a(this))}),CHARITABLE.Toggle()})}(jQuery); |