| 2 |
!function(t,_){function e(t){this.errors=[],this.pending_processes=[],this.form=t,this.pause_processing=!1,this.submit_processing=!1,this.total=0,this.prevent_scroll_to_top=!1;var e=this,o=_("body"),t=function(){return e.form.find(".charitable-terms-text").addClass("active"),!1},n=function(){_(this).closest("li").trigger("click").find("input[name=donation_amount]").prop("checked",!0).trigger("change"),e.form.off("focus","input.custom-donation-input",n),_(this).focus(),e.form.on("focus","input.custom-donation-input",n)},r=function(){o.trigger("charitable:form:amount:changed",e),o.trigger("charitable:form:total:changed",e)},i=function(){var t=e.unformat_amount(_(this).val());0<_.trim(t)&&_(this).val(e.format_amount(t)),r()},a=function(){var t=_(this).closest("li");t.hasClass("selected")||(t.parents(".charitable-donation-form").find(".donation-amount.selected").removeClass("selected"),t.addClass("selected").find("[name=donation_amount]").prop("checked",!0),t.hasClass("custom-donation-amount")&&t.find("input.custom-donation-input").focus(),r())},s=function(){e.hide_inactive_payment_methods(),e.show_active_payment_methods(_(this).val())},c=function(){_(this).parent().addClass("charitable-hidden")},u=function(t){var e=t.data.helper;return!e.submit_processing&&(e.submit_processing=!0,e.show_processing(),!1===e.validate()?(e.cancel_processing(),!1):!1===e.pause_processing&&(1!==e.form.data("use-ajax")||(d(e,function(){o.trigger("charitable:form:process",e)}),!1)))},d=function(t,e){t.waiting()?setTimeout(d,500,t,e):0<t.get_errors().length?t.cancel_processing():e()},l=function(t,n){var e=n.get_data();n.form;return e.action="make_donation",e.form_action=e.charitable_action,delete e.charitable_action,_.ajax({type:"POST",data:e,dataType:"json",url:CHARITABLE_VARS.ajaxurl,timeout:0,xhrFields:{withCredentials:!0},success:function(t){o.trigger("charitable:form:processed",[t,n]),t.success?d(n,function(){window.location.href=t.redirect_to}):(n.cancel_processing(t.errors),t.donation_id&&n.set_donation_id(t.donation_id))}}).fail(function(t,e,o){window.console&&window.console.log&&console.log(t),n.cancel_processing([CHARITABLE_VARS.error_unknown])}),!1};e.form.on("click",".donation-amount",a),e.form.on("focus","input.custom-donation-input",n),e.form.on("click",".charitable-terms-link",t),e.form.on("blur",".custom-donation-input",i),e.form.find(".donation-amount input:checked").each(function(){_(this).closest("li").addClass("selected")}),e.get_all_payment_methods().length&&(e.hide_inactive_payment_methods(),e.form.on("change","#charitable-gateway-selector input[name=gateway]",s)),e.form.on("click",".change-donation",c),e.form.on("submit",{helper:e},u),!1===CHARITABLE.forms_initialized&&(o.on("charitable:form:process",l),o.trigger("charitable:form:initialize",e),CHARITABLE.forms_initialized=!0),o.trigger("charitable:form:loaded",e)}e.prototype.get_input=function(t){return this.form.find("[name="+t+"]")},e.prototype.get_email=function(){return this.form.find("[name=email]").val()},e.prototype.is_recurring_donation=function(){var t=this.form.find("[name=recurring_donation]:checked, [name=recurring_donation][type=hidden]");return t.length&&"once"!==t.val()},e.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)},e.prototype.get_custom_amount=function(){var t=this.form.find(".charitable-donation-options.active input.custom-donation-input,.charitable-donation-options.active input.custom-donation-amount");return 0===t.length&&(t=this.form.find("input.custom-donation-input")),accounting.unformat(t.val(),CHARITABLE_VARS.currency_format_decimal_sep)},e.prototype.get_subtotal=function(){return this.get_suggested_amount()||this.get_custom_amount()},e.prototype.get_amount=function(){return this.total=this.get_subtotal(),this.form.trigger("charitable:form:get_amount",this),this.total},e.prototype.add_amount=function(t){this.total+=t},e.prototype.remove_amount=function(t){this.total-=t},e.prototype.get_description=function(){return this.form.find("[name=description]").val()||""},e.prototype.get_cc_number=function(){return this.form.find("#charitable_field_cc_number input").val()||""},e.prototype.get_cc_cvc=function(){return this.form.find("#charitable_field_cc_cvc input").val()||""},e.prototype.get_cc_expiry_month=function(){return this.form.find("#charitable_field_cc_expiration select.month").val()||""},e.prototype.get_cc_expiry_year=function(){return this.form.find("#charitable_field_cc_expiration select.year").val()||""},e.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")},e.prototype.get_payment_method=function(){return this.form.find("[type=hidden][name=gateway], [name=gateway]:checked").val()||""},e.prototype.get_all_payment_methods=function(){return this.form.find("#charitable-gateway-selector input[name=gateway]")},e.prototype.hide_inactive_payment_methods=function(){var t=this.get_payment_method(),t=this.form.find(".charitable-gateway-fields[data-gateway!="+t+"]");t.hide(),t.find("input[required],select[required],textarea[required]").attr("data-required",1).attr("required",!1)},e.prototype.show_active_payment_methods=function(t){t=t||this.get_payment_method(),t=this.form.find(".charitable-gateway-fields[data-gateway="+t+"]");t.show(),t.find("[data-required]").attr("required",!0)},e.prototype.format_amount=function(t,e){return void 0===e&&(e=""),accounting.formatMoney(t,{symbol:e,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()},e.prototype.unformat_amount=function(t){return Math.abs(parseFloat(accounting.unformat(t,CHARITABLE_VARS.currency_format_decimal_sep)))},e.prototype.add_error=function(t){this.errors.push(t)},e.prototype.get_errors=function(){return this.errors},e.prototype.get_error_message=function(){return this.errors.join(" ")},e.prototype.print_errors=function(t){var t=t||this.errors,e="";0!==t.length&&(this.form.find(".charitable-form-errors").length&&this.form.find(".charitable-form-errors").remove(),e=(e+='<div class="charitable-form-errors charitable-notice"><ul class="errors"><li>')+t.join("</li><li>"),this.form.prepend(e+="</li></ul></div>"))},e.prototype.clear_errors=function(){this.errors=[],this.form.find(".charitable-form-errors").length&&this.form.find(".charitable-form-errors").remove()},e.prototype.waiting=function(){return 0<this.pending_processes.length},e.prototype.add_pending_process=function(t){var e=this.pending_processes.indexOf(t);return-1===e?this.pending_processes.push(t)-1:e},e.prototype.remove_pending_process=function(t){this.pending_processes.splice(t,1)},e.prototype.remove_pending_process_by_name=function(t){t=this.pending_processes.indexOf(t);return-1!==t&&this.remove_pending_process(t)},e.prototype.show_processing=function(){this.form.find(".charitable-form-processing").show(),this.form.find('button[name="donate"]').hide()},e.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},e.prototype.scroll_to_top=function(){var t;this.prevent_scroll_to_top?this.prevent_scroll_to_top=!1:(t=this.form.parents(".charitable-modal")).length?t.scrollTop(0):window.scrollTo(this.form.offset().left,this.form.offset().top)},e.prototype.cancel_processing=function(t){this.hide_processing(),this.print_errors(t),this.scroll_to_top(),this.form.trigger("charitable:form:cancelled",this)},e.prototype.set_donation_id=function(t){this.form.find("[name=ID]").val(t)},e.prototype.get_data=function(){return this.form.serializeArray().reduce(function(t,e){var o;return"[]"===e.name.slice(-2)?(o=e.name.slice(0,-2),t.hasOwnProperty(o)||(t[o]=[]),t[o].push(e.value)):t[e.name]=e.value,t},{})},e.prototype.get_required_fields=function(){var t=this.form.find(".charitable-fieldset .required-field").not("#charitable-gateway-fields .required-field"),e=this.get_payment_method();return t=""!==e&&(e=this.form.find("[data-gateway="+e+"] .required-field")).length?_.merge(t,e):t},e.prototype.subtotal_exceeds_maximum=function(){return""!==CHARITABLE_VARS.maximum_donation&&this.get_subtotal()>parseFloat(CHARITABLE_VARS.maximum_donation)},e.prototype.is_valid_amount=function(){var t=parseFloat(CHARITABLE_VARS.minimum_donation);return!this.subtotal_exceeds_maximum()&&(0<t||CHARITABLE_VARS.permit_0_donation?this.get_subtotal()>=t:this.get_subtotal()>t)},e.prototype.validate_amount=function(){return!1!==this.is_valid_amount()||(0<this.get_subtotal()&&this.subtotal_exceeds_maximum()?this.add_error(CHARITABLE_VARS.error_max_exceeded):this.add_error(CHARITABLE_VARS.error_invalid_amount),!1)},e.prototype.validate_required_fields=function(){var t=!0;return this.get_required_fields().each(function(){""===_(this).find("input, select, textarea").val()&&(t=!1)}),t||this.add_error(CHARITABLE_VARS.error_required_fields),t},e.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},t.Donation_Form=e}(CHARITABLE=window.CHARITABLE||{},jQuery),function(t,o){var e,n;function r(){n(o(this)).addClass("charitable-hidden")}function i(){o("[data-charitable-toggle]").each(r)}t.Toggle=(n=function(t){t=t.data("charitable-toggle");return"."!==t[0]&&"#"!==t[0]&&(t="#"+t),o(t)},o("body").on("click","[data-charitable-toggle]",function(){var t=o(this),e=n(t);return e.toggleClass("charitable-hidden",t.is(":checkbox")?!t.is(":checked"):!1===e.hasClass("charitable-hidden")),!1}),t.content_loading&&(e=setInterval(function(){!1===t.content_loading&&(i(),clearInterval(e))},500)),i)}(CHARITABLE,jQuery),CHARITABLE.VersionCompare=function(t,e){if(typeof t+typeof(e=e||CHARITABLE_VARS.version)!="stringstring")return!1;for(var o=t.split("."),n=e.split("."),r=0,i=Math.max(o.length,n.length);r<i;r++){if(o[r]&&!n[r]&&0<parseInt(o[r])||parseInt(o[r])>parseInt(n[r]))return 1;if(n[r]&&!o[r]&&0<parseInt(n[r])||parseInt(o[r])<parseInt(n[r]))return-1}return 0},function(e){CHARITABLE.forms_initialized=!1,e(document).ready(function(){e("html").addClass("js");var t=[];e(".charitable-donation-form").each(function(){t.push(new CHARITABLE.Donation_Form(e(this)))}),CHARITABLE.Toggle()})}(jQuery); |