Last active
April 30, 2021 00:04
-
-
Save ericnicolaas/ee6621a6fe80973f7266770f9b9cca84 to your computer and use it in GitHub Desktop.
Extend Charitable using jQuery Events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CHARITABLE = window.CHARITABLE || {}; | |
( function( $ ) { | |
var $body = $( 'body' ); | |
/** | |
* Do something when a donation form loads. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:loaded', function( event, helper ) { | |
} ); | |
/** | |
* Do something after the first donation form on the page is initialized. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:initialize', function( event, helper ) { | |
} ); | |
/** | |
* Do something when calculating the donation amount. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:get_amount', function( event, helper ) { | |
} ); | |
/** | |
* Do something when the donation amount, excluding fees, is changed. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:amount:changed', function( event, helper ) { | |
} ); | |
/** | |
* Do something when the total donation amount, including any fees, is changed. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:total:changed', function( event, helper ) { | |
} ); | |
/** | |
* Do something when donation form processing is cancelled, for example | |
* because of an error. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:cancelled', function( event, helper ) { | |
} ); | |
/** | |
* Do something when the donation is being validated. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:validate', function( event, helper ) { | |
// To add an error, use helper.add_error. This will prevent | |
// the form from submitting. | |
// | |
// helper.add_error( 'This is my custom error' ); | |
} ); | |
/** | |
* Do something when the donation is being processed, after validation. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:process', function( event, helper ) { | |
} ); | |
/** | |
* Do something after the donation has been processed and | |
* created in the admin. | |
* | |
* @since 1.0.0 | |
* | |
* @param object Event | |
* @param object response | |
* @param object CHARITABLE.Donation_Form | |
* @return void | |
*/ | |
$body.on( 'charitable:form:processed', function( event, response, helper ) { | |
if ( response.success ) { | |
// Do something for donations created successfully. | |
} else { | |
// Donation failed to be created successfully. | |
} | |
} ); | |
} )( jQuery ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment