Skip to content

Commit

Permalink
update give-checkout-global to play nice with impress-org#486
Browse files Browse the repository at this point in the history
  • Loading branch information
pryley committed Feb 27, 2016
1 parent 18d643c commit 84e05b7
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 71 deletions.
12 changes: 11 additions & 1 deletion assets/css/give-admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/css/give-admin.css.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions assets/css/give-admin.min.css

Large diffs are not rendered by default.

42 changes: 38 additions & 4 deletions assets/js/frontend/give-checkout-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ jQuery( function ( $ ) {
*/
doc.on( 'blur', '.give-donation-amount .give-text-input', function ( e ) {

var parent_form = $( this ).closest( 'form' );
var minimum_amount = parent_form.find( 'input[name="give-form-minimum"]');
var value_min = give_unformat_currency( minimum_amount.val() );
var value_is_multi_level = false;

var pre_focus_amount = $( this ).data( 'amount' );
var value_now = give_unformat_currency( $( this ).val() );
var format_args = {
Expand All @@ -246,16 +251,43 @@ jQuery( function ( $ ) {
//Set the custom amount input value formatted properly
$( this ).val( formatted_total );

//Does this number have a value?
if ( !$.isNumeric( value_now ) || value_now <= 0 ) {
//Compare the multi-level price-id value to the donation value
parent_form.find( '*[data-price-id]' ).each( function() {
if ( this.value !== 'custom' && give_unformat_currency( this.value ) === value_now ) {
value_is_multi_level = true;
}
});

//Add the currency symbol to the format_args in case it is needed from here on
format_args.symbol = give_global_vars.currency_sign;

//Does this number have a valid value?
if ( !$.isNumeric( value_now ) || ( value_now < value_min || value_now <= 0 ) && ! value_is_multi_level ) {

$( this ).addClass( 'invalid-amount' );

minimum_amount_error_text = give_global_vars.bad_minimum + ' ' + give_format_currency( value_min, format_args );

var invalid_minimum = parent_form.find( '.invalid-minimum' );

if ( invalid_minimum.length === 0 ) {

var error = $( '<p class="invalid-minimum give-error">' + minimum_amount_error_text + '</p>' ).hide();

error.insertAfter( $( this ).closest( '.give-total-wrap' ) ).slideDown();
}

} else {

parent_form.find( '.invalid-minimum' ).slideUp( 400, function() {
$( this ).remove();
});
}

//If values don't match up then proceed with updating donation total value
if ( pre_focus_amount !== value_now ) {

//update donation total (include currency symbol)
format_args.symbol = give_global_vars.currency_sign;
//update donation total
$( this ).parents( 'form' ).find( '.give-final-total-amount' ).data( 'total', value_now ).text( give_format_currency( value_now, format_args ) );

//fade in/out updating text
Expand Down Expand Up @@ -334,6 +366,8 @@ jQuery( function ( $ ) {
formatted_total = this_amount + currency_symbol;
}

$( '.give-donation-amount .give-text-input' ).trigger( 'blur' );

//Update donation form bottom total data attr and text
parent_form.find( '.give-final-total-amount' ).data( 'total', this_amount ).text( formatted_total );
}
Expand Down
2 changes: 1 addition & 1 deletion assets/js/frontend/give-checkout-global.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 84e05b7

Please sign in to comment.