MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
add donationForm.currencyRates; define donationForm.minLocal and maxLocal at load and allow overriding (currently only for India)
simplify locale code: just define donationForm.locale on load and use that as default for formatAmount
Line 218:
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
var currency = donationForm.currency,;
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
 
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount( donationForm.minLocal, locale ) + '\xa0' + currency );
});
 
Line 234 ⟶ 233:
 
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount( donationForm.maxLocal, locale ) )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD, locale ) );
});
};
Line 952 ⟶ 951:
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText, locale;
 
localefeeText = donationForm.getLocaleformatAmount( mw.config.get('wgPageContentLanguage'), donationForm.countryfeeAmount );
feeText = donationForm.formatAmount( feeAmount, locale );
 
$('.ptf label span').text( feeText );
Line 1,092 ⟶ 1,090:
 
/**
* Format an amount for a given locale (default to donationForm.locale)
*
* 2 decimal places if it has a fractional part, 0 if not
Line 1,098 ⟶ 1,096:
*
* @param {number} amount
* @param {string} [locale=donationForm.locale] To determine correct separators
* @return {string}
*/
donationForm.formatAmount = function( amount, locale = donationForm.locale ) {
var formatterOptions, output;
if ( amount % 1 !== 0 ) { // Not a whole number
Line 1,305 ⟶ 1,303:
}
donationForm.country = mw.util.getParamValue('country').toUpperCase();
donationForm.locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
 
// Minimum amount is usually about 1 USD