MediaWiki:DonationFormSandbox.js: Difference between revisions

Content deleted Content added
use toLocaleString for Pay the Fee amount - phab:T336079
factor out donationForm.formatAmount method
Line 662:
if ( cardTypes[country] ) {
$('.paymentmethod-cc').addClass('cctypes-' + cardTypes[country] );
$('.cc-text-label').addClass('sr-only');
}
}
Line 753 ⟶ 754:
}
if ( params.recurring && params.variant && params.variant.match( /monthlyConvert/ ) ) {
// Post-payments monthly convert makes no sense if it's already recurring
// Avoid things like T312905
delete params.variant;
}
 
Line 990 ⟶ 991:
minAmount = donationForm.minimums[ donationForm.currency ] || 1,
maxAmount = donationForm.maxUSD * minAmount,
feeText, locale, formatterOptions, supportsIntl;
 
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
feeText = donationForm.formatAmount( feeAmount, locale );
 
if ( feeAmount % 1 !== 0 ) { // Not a whole number
formatterOptions = { minimumFractionDigits: 2 };
} else {
formatterOptions = {};
}
 
try {
feeText = feeAmount.toLocaleString( locale, formatterOptions );
} catch(e) {
feeText = feeAmount.toFixed(2);
}
 
$('.ptf label span').text( feeText );
Line 1,105 ⟶ 1,095:
* @param {string} language
* @param {string} country
* @return {string} locale identifier e.g. locale identifieren-GB
*/
donationForm.getLocale = function( language, country ) {
Line 1,139 ⟶ 1,129:
return false;
};
 
/**
* Format an amount for a given locale
*
* 2 decimal places if it has a fractional part, 0 if not
* Note this doesn't include any currency symbol
*
* @param {number} amount
* @param {string} locale To determine correct separators
* @return {string}
*/
donationForm.formatAmount = function( amount, locale ) {
var formatterOptions, output;
if ( feeAmountamount % 1 !== 0 ) { // Not a whole number
formatterOptions = { minimumFractionDigits: 2, maximumFractionDigits: 2 };
} else {
formatterOptions = {};
}
try {
feeTextoutput = feeAmountamount.toLocaleString( locale, formatterOptions );
} catch(e) {
feeTextoutput = feeAmountamount.toFixed(2);
}
return output;
}