MediaWiki:DonationForm.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
hide card text when showing logos |
new donationForm.formatAmount method, and use it for both fee and error amounts |
||
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, |
||
minAmount = donationForm.minimums[ currency ], |
|||
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country ); |
|||
/* T287706 - round to 2 decimal places (rounding up) */ |
|||
⚫ | |||
return Math.ceil( amount * 100 ) / 100; |
|||
⚫ | |||
$('.lp-error-smallamount').text( function( index, oldText ) { |
$('.lp-error-smallamount').text( function( index, oldText ) { |
||
return oldText.replace( '$1', |
return oldText.replace( '$1', donationForm.formatAmount( minAmount, locale ) + '\xa0' + currency ); |
||
}); |
}); |
||
Line 245: | Line 242: | ||
$('.lp-error-bigamount').text( function( index, oldText ) { |
$('.lp-error-bigamount').text( function( index, oldText ) { |
||
return oldText.replace( '$1', |
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 ) ); |
||
}); |
}); |
||
}; |
}; |
||
Line 754: | Line 751: | ||
} |
} |
||
if ( params.recurring && params.variant && params.variant.match( /monthlyConvert/ ) ) { |
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 991: | Line 988: | ||
minAmount = donationForm.minimums[ donationForm.currency ] || 1, |
minAmount = donationForm.minimums[ donationForm.currency ] || 1, |
||
maxAmount = donationForm.maxUSD * minAmount, |
maxAmount = donationForm.maxUSD * minAmount, |
||
feeText, locale |
feeText, locale; |
||
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country ); |
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country ); |
||
feeText = donationForm.formatAmount( feeAmount, locale ); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
$('.ptf label span').text( feeText ); |
$('.ptf label span').text( feeText ); |
||
Line 1,106: | Line 1,092: | ||
* @param {string} language |
* @param {string} language |
||
* @param {string} country |
* @param {string} country |
||
* @return {string} |
* @return {string} locale identifier e.g. en-GB |
||
*/ |
*/ |
||
donationForm.getLocale = function( language, country ) { |
donationForm.getLocale = function( language, country ) { |
||
Line 1,140: | Line 1,126: | ||
return false; |
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} |
|||
*/ |
|||
⚫ | |||
var formatterOptions, output; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return output; |
|||
} |
|||