MediaWiki:DonationFormSandbox.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
factor out donationForm.formatAmount method
use new method when localizing errors
Line 225: Line 225:
/* Localize the amount errors. Call when initialising form. */
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
donationForm.localizeErrors = function() {
var currency = donationForm.currency;
var currency = donationForm.currency,
var minAmount = donationForm.minimums[ currency ];
minAmount = donationForm.minimums[ currency ],
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
/* T287706 - round to 2 decimal places (rounding up) */
var numFormat = function( amount ) {
return Math.ceil( amount * 100 ) / 100;
};


$('.lp-error-smallamount').text( function( index, oldText ) {
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', numFormat( minAmount ) + ' ' + currency );
return oldText.replace( '$1', donationForm.formatAmount( minAmount, locale ) + ' ' + currency );
});
});


Line 245: Line 242:


$('.lp-error-bigamount').text( function( index, oldText ) {
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', numFormat( donationForm.maxUSD * minAmount ) )
return oldText.replace( '$1', donationForm.formatAmount( donationForm.maxUSD * minAmount, locale ) )
.replace( '$2', currency )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.maxUSD );
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD, locale ) );
});
});
};
};