| @@ -157,10 +157,19 @@ | ||
| 157 | 157 | * |
| 158 | 158 | * @access private |
| 159 | 159 | */ |
| 160 | 160 | var on_change_payment_gateway = function() { |
| 161 | + var selectedGateway = $(this).val(); | |
| 162 | + | |
| 161 | 163 | self.hide_inactive_payment_methods(); |
| 162 | - self.show_active_payment_methods( $(this).val() ); | |
| 164 | + self.show_active_payment_methods( selectedGateway ); | |
| 165 | + | |
| 166 | + // Trigger resize event for Square gateway to fix iframe height issue | |
| 167 | + if ( selectedGateway === 'square' || selectedGateway === 'square_core' ) { | |
| 168 | + setTimeout(function() { | |
| 169 | + window.dispatchEvent(new Event('resize')); | |
| 170 | + }, 100); | |
| 171 | + } | |
| 163 | 172 | }; |
| 164 | 173 | |
| 165 | 174 | /** |
| 166 | 175 | * Event handler when the "Change" link is clicked for pre-filled donations. |
| @@ -239,9 +248,11 @@ | ||
| 239 | 248 | * @param object Event |
| 240 | 249 | * @param object Donation_Form |
| 241 | 250 | */ |
| 242 | 251 | var process_donation = function( event, helper ) { |
| 252 | + | |
| 243 | 253 | var data = helper.get_data(); |
| 254 | + | |
| 244 | 255 | var form = helper.form; |
| 245 | 256 | |
| 246 | 257 | /* Cancel the default Charitable action, but pass it along as the form_action variable */ |
| 247 | 258 | data.action = 'make_donation'; |
| @@ -575,15 +586,41 @@ | ||
| 575 | 586 | }).trim(); |
| 576 | 587 | }; |
| 577 | 588 | |
| 578 | 589 | /** |
| 579 | - * Select a donation amount. | |
| 590 | + * Unformat a currency string to a plain float. | |
| 580 | 591 | * |
| 581 | - * @param int price | |
| 582 | - * @return string | |
| 592 | + * Handles the case where the site uses a non-period decimal separator (e.g. comma) | |
| 593 | + * but the user types a period as the decimal point — a common mistake on non-US | |
| 594 | + * keyboards. accounting.unformat() would otherwise strip the period as if it were | |
| 595 | + * a thousands separator, turning "5.33" into 533. | |
| 596 | + * | |
| 597 | + * Heuristic: if the configured decimal is not a period, the value contains a period, | |
| 598 | + * and the value does NOT already contain the configured decimal separator: | |
| 599 | + * - One period followed by 1–2 digits at end → treat as decimal (e.g. "5.33" → "5,33") | |
| 600 | + * - One period followed by exactly 3 digits at end → treat as thousands (e.g. "1.000" → 1000) | |
| 601 | + * - Multiple periods → all thousands separators; let accounting.unformat strip them | |
| 602 | + * | |
| 603 | + * @param string|number price | |
| 604 | + * @return float | |
| 583 | 605 | */ |
| 584 | 606 | Donation_Form.prototype.unformat_amount = function( price ) { |
| 585 | - return Math.abs( parseFloat( accounting.unformat( price, CHARITABLE_VARS.currency_format_decimal_sep ) ) ); | |
| 607 | + var decimal = CHARITABLE_VARS.currency_format_decimal_sep; | |
| 608 | + | |
| 609 | + price = String( price ); | |
| 610 | + | |
| 611 | + if ( decimal !== '.' && price.indexOf( '.' ) !== -1 && price.indexOf( decimal ) === -1 ) { | |
| 612 | + var periodCount = ( price.match( /\./g ) || [] ).length; | |
| 613 | + | |
| 614 | + if ( periodCount === 1 && ! /\.\d{3}$/.test( price ) ) { | |
| 615 | + // Single period not followed by exactly 3 digits — treat as decimal separator. | |
| 616 | + price = price.replace( '.', decimal ); | |
| 617 | + } | |
| 618 | + // Single period followed by 3 digits (thousands) or multiple periods: | |
| 619 | + // fall through and let accounting.unformat strip them. | |
| 620 | + } | |
| 621 | + | |
| 622 | + return Math.abs( parseFloat( accounting.unformat( price, decimal ) ) ); | |
| 586 | 623 | }; |
| 587 | 624 | |
| 588 | 625 | /** |
| 589 | 626 | * Add an error message. |
| @@ -1005,8 +1042,32 @@ | ||
| 1005 | 1042 | |
| 1006 | 1043 | return 0; |
| 1007 | 1044 | }; |
| 1008 | 1045 | |
| 1046 | +/** | |
| 1047 | + * Set up ResetSuggestedDonations object. | |
| 1048 | + */ | |
| 1049 | +( function( exports, $ ){ | |
| 1050 | + | |
| 1051 | + CHARITABLE.ResetSuggestedDonations = function() { | |
| 1052 | + | |
| 1053 | + if ( $('.charitable-donation-options').length = 0 ) { | |
| 1054 | + // the options probably aren't on this page. | |
| 1055 | + return false; | |
| 1056 | + } | |
| 1057 | + | |
| 1058 | + $( 'ul.donation-amounts input[type="radio"]' ).each( function() { | |
| 1059 | + if ( $( this ).is(':checked') ) { | |
| 1060 | + $( this ).closest( "li" ).addClass( "selected" ); | |
| 1061 | + } else { | |
| 1062 | + $( this ).closest( "li" ).removeClass( "selected" ); | |
| 1063 | + } | |
| 1064 | + }); | |
| 1065 | + | |
| 1066 | + } | |
| 1067 | + | |
| 1068 | +})( CHARITABLE, jQuery ); | |
| 1069 | + | |
| 1009 | 1070 | /*** |
| 1010 | 1071 | * Finally queue up all the scripts. |
| 1011 | 1072 | */ |
| 1012 | 1073 | ( function( $ ) { |
| @@ -1026,7 +1087,9 @@ | ||
| 1026 | 1087 | forms.push( new CHARITABLE.Donation_Form( $( this ) ) ); |
| 1027 | 1088 | }); |
| 1028 | 1089 | |
| 1029 | 1090 | CHARITABLE.Toggle(); |
| 1091 | + | |
| 1092 | + CHARITABLE.ResetSuggestedDonations(); | |
| 1030 | 1093 | }); |
| 1031 | 1094 | |
| 1032 | 1095 | })( jQuery ); |