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