MediaWiki:DonationFormSandbox.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 8:
donationForm.loadedTime = Date.now();
donationForm.extraData = {};
 
donationForm.country = mw.util.getParamValue('country').toUpperCase();
donationForm.locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
try {
donationForm.currency = formdocument.forms.donateForm.currency_code.value;
} catch (error) {
donationForm.currency = 'USD';
};
 
// Don't offer recurring at all in these countries
Line 214 ⟶ 222:
'ZMK' : 5176,
'ZWD' : 373
};
 
let formatters = {
* Note this doesn't include// anyWith currency symbol
currencyFraction: new Intl.NumberFormat(
donationForm.locale, { style: 'currency', currency: donationForm.currency }
}),
currencyWhole: new Intl.NumberFormat(
donationForm.locale, { style: 'currency', currency: donationForm.currency, minimumFractionDigits: 0 }
}),
// Without currency symbol
amountFraction: new Intl.NumberFormat(
formatterOptions =donationForm.locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 };
}),
amountWhole: new Intl.NumberFormat(
donationForm.locale, {}
)
};
 
donationForm.formatAmountformatCurrency = function( amount, locale = donationForm.locale ) {
if ( amount % 1 !== 0 ) { // Not a whole number
return formatters.currencyFraction.format( amount );
} else {
return formatters.currencyWhole.format( amount );
}
};
 
donationForm.formatAmount = function( amount ) {
var formatterOptions, output;
if ( amount % 1 !== 0 ) { // Not a whole number
return formatters.amountFraction.format( amount );
} catch(e)else {
return formatters.amountWhole.format( amount );
}
};
 
Line 1,152 ⟶ 1,194:
}
return false;
};
 
/**
* Format an amount for a given locale (default to donationForm.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=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
formatterOptions = { minimumFractionDigits: 2, maximumFractionDigits: 2 };
} else {
formatterOptions = {};
}
try {
output = amount.toLocaleString( locale, formatterOptions );
} catch(e) {
output = amount.toFixed(2);
}
return output;
};
 
Line 1,360 ⟶ 1,377:
 
var form = document.forms.donateForm;
 
// These get used in quite a few places
try {
donationForm.currency = form.currency_code.value;
} catch (error) {
donationForm.currency = 'USD';
}
donationForm.country = mw.util.getParamValue('country').toUpperCase();
donationForm.locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
 
// Minimum amount is usually about 1 USD