MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
update minimums to match payments
Adding directmail250 hpcSet for US
 
(20 intermediate revisions by 2 users not shown)
Line 8:
donationForm.loadedTime = Date.now();
donationForm.extraData = {};
 
donationForm.country = mw.util.getParamValue('country').toUpperCase();
try {
donationForm.currency = document.forms.donateForm.currency_code.value;
} catch (error) {
donationForm.currency = 'USD';
}
 
/**
* Make language and country into a standard javascript Intl locale identifier
*
* @param {string} language
* @param {string} country
* @return {string} locale identifier e.g. en-GB
*/
donationForm.getLocale = function( language, country ) {
// Sometimes in email testing links the uselang is a variable contiaining %
// In that case fall back to English so locale code doesn't break form
if ( language.match('%') ) {
language = 'en';
}
if ( language === 'en-gb' ) {
language = 'en';
}
if ( language === 'es-419' ) {
language = 'es';
}
if ( language === 'pt-br' ) {
language = 'pt';
}
return language + '-' + country;
};
 
donationForm.locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
 
 
// Don't offer recurring at all in these countries
donationForm.noRecurringCountries = [ 'AR', 'IN' ]; // is this still needed?
 
donationForm.noRecurringPaypalCountries = [ 'CL', 'CO', 'PE', 'UY', 'BR' ];
 
donationForm.maxUSDcurrencyRates = 25000;{
 
donationForm.minimums = {
// From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php
// Updated 2024-07-31
Line 97 ⟶ 130:
'IEP' : 0.72460490043714,
'ILS' : 3.69,
'INR' : 1083,
'IQD' : 1290,
'IRR' : 42009,
Line 216 ⟶ 249:
'ZMK' : 5176,
'ZWD' : 373
};
 
/* Amount and currency formatting */
let formatters = {
// Amounts without currency symbol
amountFraction: new Intl.NumberFormat( donationForm.locale,
{ minimumFractionDigits: 2, maximumFractionDigits: 2 }
),
amountWhole: new Intl.NumberFormat( donationForm.locale,
{}
)
}
 
// currencyDisplay: 'narrowSymbol' fixes some issues like en-CO showing the ISO code
// but browser support is lacking, so wrap in a try/catch
try {
formatters.currencyFraction = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency, currencyDisplay: 'narrowSymbol' }
);
formatters.currencyWhole = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency, currencyDisplay: 'narrowSymbol', minimumFractionDigits: 0 }
);
} catch(e) {
formatters.currencyFraction = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency }
);
formatters.currencyWhole = new Intl.NumberFormat( donationForm.locale,
{ style: 'currency', currency: donationForm.currency, minimumFractionDigits: 0 }
);
}
 
donationForm.formatCurrency = function( amount ) {
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 );
} else {
return formatters.amountWhole.format( amount );
}
};
 
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
var currency = donationForm.currency,;
minAmount = donationForm.minimums[ currency ],
locale = donationForm.getLocale( mw.config.get('wgPageContentLanguage'), donationForm.country );
 
// Round up
minAmount = Math.ceil( minAmount * 100 ) / 100;
 
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount( minAmount, localedonationForm.minLocal ) + '\xa0' + currency );
});
 
Line 240 ⟶ 314:
 
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', donationForm.formatAmount( donationForm.maxUSD * minAmount, localemaxLocal ) )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD, locale ) );
});
};
Line 253 ⟶ 327:
TODO: split data out? */
 
var hpcSet = mw.util.getParamValue('hpcSet');
// Look for 'hpc' parameter, then 'mrc'. If neither, then bail out.
 
// Look for 'hpc' parameter, then 'mrc'
var hpc = parseFloat( mw.util.getParamValue('hpc') );
if( isNaN(hpc) ) {
hpc = parseFloat( mw.util.getParamValue('mrc') );
if( isNaN(hpc) ) {
return;if ( hpcSet ) {
// Allow using hpcSet even without hpc, for MG appeals
hpc = 0;
} else {
return;
}
}
}
 
var hpcSet = mw.util.getParamValue('hpcSet');
 
var currency = donationForm.currency;
var language = mw.config.get('wgPageContentLanguage');
 
// If changing, please update https://docs.google.com/spreadsheets/d/1e02TsZ_bKDAS1BMVBCdyo9D7RGln_wCGnkg7IF5kU5s/edit
Line 287 ⟶ 365:
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T11FY2425_E1_T11_USD" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 3.75, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
Line 304 ⟶ 382:
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T14_USFY2425_E1_T14_USD" : [ // Upgrade recurring amount dynamically
[ 0, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 2.75, 10, 15, 20, 25, 35, 50 ] ],
[ 15, [ 2 3.7550, 10, 20, 30, 50, 75, 100 ] ],
[ 20, [ 3.75, 10, 25, 35, 50, 75, 100 ] ],
[ 25, [ 4.50, 10, 25, 35, 50, 75, 100 ] ],
[ 35, [ 6.75, 15, 30, 50, 75, 100, 150 ] ],
[ 75, [ 15.75, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 24.75, 50, 75, 100, 200, 300, 500 ] ],
[ 150, [ 44.75, 100, 150, 250, 500, 750, 1000 ] ],
[ 200, [ 50, 100, 150, 250, 500, 750, 1000 ] ],
[ 500, [ 150, 250, 300, 500, 750, 1000, 2000 ] ],
[ 1000, [ 250, 500, 750, 1000, 2500, 5000, 10000 ] ],
[ 3000, [ 500, 1000, 2000, 3500, 5000, 7500, 10000 ] ]
],
"FY2425_E1_T21_USFY2425_E1_T21_USD" : [ // Give less reactivation amount
[ 0, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.75, 5, 10, 20, 25, 35, 50 ] ],
Line 328 ⟶ 406:
[ 25, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 35, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 5075, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 75, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 100, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 150, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
Line 337 ⟶ 414:
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
],
"midtier2018"// :Direct [Mail - fixed amounts
"directmail" : [
[ 0, [ 3, 5, 10, 20, 30, 50, 100 ] ],
[ 50, [ 525, 1035, 2050, 35100, 50150, 100250, 150300 ] ],
],
[ 10, [ 10, 15, 20, 35, 50, 100, 150 ] ],
"directmail250" : [
[ 15, [ 15, 20, 25, 35, 50, 100, 150 ] ],
[ 20 0, [ 20250, 25300, 35500, 50750, 751000, 1002500, 1505000 ] ],
[ 25, [ 35, 50, 75, 100, 150, 250, 500 ] ],
[ 35, [ 50, 75, 100, 150, 250, 350, 500 ] ],
[ 50, [ 75, 100, 150, 200, 250, 350, 500 ] ],
[ 75, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 100, [ 150, 200, 250, 300, 400, 500, 1000 ] ],
[ 150, [ 200, 250, 300, 400, 500, 1000, 2500 ] ],
[ 200, [ 500, 750, 1000, 2000, 3500, 5000, 7500 ] ],
[ 500, [ 750, 1000, 1500, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
"EUR" : {
"default" : [ // also used for GBP
[ 0, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 35, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 50, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 100, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 200, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T14_GBFY2425_E1_T11_EUR" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 20, [ 3.50, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 25, [ 5, 10, 2015, 2520, 35, 50, 100 ] ],
[ 10, [ 210, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 15, [ 215, 1020, 2025, 3035, 50, 75, 100 ] ],
[ 20, [ 320, [ 1020, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 425, [ 1025, 2530, 3540, 50, 75, 100, 150 ] ],
[ 35, [ 635, 1550, 3075, 50100, 75200, 100300, 150500 ] ],
[ 75, [ 1550, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 100, [ 2575, [ 5075, 75100, 100150, 200250, 300500, 500750, 1000 ] ],
[ 150, [ [ 45100, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 200, [ [ 50150, [ 100150, 150200, 250300, 500, 750, 1000, 2000 ] ],
[ 500, [ 150200, [ 250200, 300, 500, 750, 1000, 20002500, 5000 ] ],
[ 1000, [ 250500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 3000, [ 500[ 1000, [ 1000, 2000, 35003000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T21_GBFY2425_E1_T14_EUR" : [ // Upgrade recurring amount dynamically
[ 0, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 10, 5[ 2.50, 10, 15, 20, 3525, 5035, 100 50 ] ],
[ 15, [ 102.50, 1510, 20, 2530, 3550, 5075, 100 ] ],
[ 20, [ 153.50, 2010, 25, 35, 50, 75, 100 ] ],
[ 25, [ 4.25, 20 10, 25, 35, 50, 75, 100, 150 ] ],
[ 35, [ 6.25, 3015, 4030, 50, 75, 100, 150 ] ],
[ 5075, [ 3515, 50, 75, 100, 200, 300, 500 ] ],
[ 75 [ 100, [ 25, 50, 75, 100, 200, 300, 500, 750 ] ],
[ 100150, [ 7545, 100, 150, 250, 500, 750, 1000 ] ],
[ 150200, [ 50, 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 200500, [ 150, 200250, 300, 500, 750, 1000, 2000 ] ],
[ 500, [ [ 2001000, [ 300250, 500, 750, 1000, 2500, 5000, 10000 ] ],
[ 10003000, [ 500, 7501000, 10002000, 25003500, 5000, 7500, 10000 ] ],
],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
"FY2425_E1_T21_EUR" : [ // Give less reactivation amount
[ 0, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2.50, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 15, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 20, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 25, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 35, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 75, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 150, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 200, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 500, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 1000, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
"GBP" : {
"default" : [
[ 0, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 35, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 50, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 100, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 200, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T11_GBP" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 3, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 10, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 15, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 35, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 50, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 100, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 150, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 200, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ]
],
"FY2425_E1_T14_GBP" : [ // Upgrade recurring amount dynamically
[ 0, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 2, 10, 15, 20, 25, 35, 50 ] ],
[ 15, [ 2, 10, 20, 30, 50, 75, 100 ] ],
[ 20, [ 3, 10, 25, 35, 50, 75, 100 ] ],
[ 25, [ 4, 10, 25, 35, 50, 75, 100 ] ],
[ 35, [ 6, 15, 30, 50, 75, 100, 150 ] ],
[ 75, [ 15, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 20, 50, 75, 100, 200, 300, 500 ] ],
[ 150, [ 40, 100, 150, 250, 500, 750, 1000 ] ],
[ 200, [ 45, 100, 150, 250, 500, 750, 1000 ] ],
[ 500, [ 125, 250, 300, 500, 750, 1000, 2000 ] ],
[ 1000, [ 200, 500, 750, 1000, 2500, 5000, 10000 ] ],
[ 3000, [ 400, 1000, 2000, 3500, 5000, 7500, 10000 ] ]
],
"FY2425_E1_T21_GBP" : [ // Give less reactivation amount
[ 0, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 5, [ 2, 5, 10, 20, 25, 35, 50 ] ],
[ 10, [ 5, 10, 15, 20, 35, 50, 100 ] ],
[ 15, [ 10, 15, 20, 25, 35, 50, 100 ] ],
[ 20, [ 15, 20, 25, 35, 50, 75, 100 ] ],
[ 25, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 35, [ 25, 30, 40, 50, 75, 100, 150 ] ],
[ 75, [ 35, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
[ 150, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 200, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
[ 500, [ 200, 300, 500, 750, 1000, 2500, 5000 ] ],
[ 1000, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 3000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ]
]
},
"JPY" : [
[ 0, [ 500, 1000, 2000, 2500, 4000, 5000, 10000 ] ],
Line 428 ⟶ 580:
radioAmountsData.NZD = radioAmountsData.USD;
 
// Major gifts appeals, hacky but this is easier than adding a load of new forms to maintain
radioAmountsData.GBP = radioAmountsData.EUR;
var currencyList = [ 'USD', 'CAD', 'AUD', 'NZD', 'GBP', 'EUR' ]; // close enough
for ( let i = 0; i < currencyList.length; i++ ) {
radioAmountsData[ currencyList[i] ].MG_2024_500 = [ [ 0, [ 500, 750, 1000, 1250, 1500, 1750, 2000 ] ] ];
radioAmountsData[ currencyList[i] ].MG_2024_650 = [ [ 0, [ 650, 750, 1000, 1250, 1500, 1750, 2000 ] ] ];
}
 
var appealAmountsData = {
Line 467 ⟶ 624:
appealAmountsData.NZD = appealAmountsData.USD;
appealAmountsData.EUR = appealAmountsData.USD;
 
var formats = {
"USD" : "$\t",
"EUR" : {
"en" : "€\t",
"cy" : "€\t",
"ga" : "€\t",
"mt" : "€\t",
"nl" : "€ \t",
"lv" : "€ \t",
"tr" : "€ \t",
"default" : "\t €"
},
"AUD" : "$\t",
"CAD" : {
"fr" : "\t $",
"default" : "$\t"
},
"GBP" : "£\t",
"NZD" : "$\t",
"JPY" : "¥\t",
"SEK" : "\t kr",
"BRL" : "R$\t"
};
 
var format;
if ( formats[currency] ) {
format = formats[currency][language] || formats[currency]['default'] || formats[currency];
} else {
format = '\t';
}
 
// Radio button amounts
Line 507 ⟶ 633:
var $label = $("label[for='input_amount_" + j + "']");
$radio.val( radioAmounts[j] );
$label.text( formatdonationForm.replaceformatCurrency('\t', radioAmounts[j] ) );
}
}
Line 514 ⟶ 640:
var appealAmounts = pickAmountArray( appealAmountsData, currency, hpc, hpcSet );
if ( appealAmounts.length ) {
var appealAmountString = appealAmounts.map( donationForm.formatCurrency ).join( ', ');
// Build string
var appealAmountString = '';
for( var k = 0; k < appealAmounts.length; k++ ) {
appealAmountString += format.replace('\t', appealAmounts[k]) + ', ';
}
appealAmountString = appealAmountString.trim();
 
$('.consider-amounts').html(appealAmountString);
}
Line 929 ⟶ 1,049:
 
var amount = donationForm.getAmount();
var minAmount = donationForm.minimums[ donationForm.currency ] || 1;
 
if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmountdonationForm.minLocal ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').hide();
$('.lp-error-smallamount').show();
return false;
} else if ( amount > donationForm.maxUSD * minAmountmaxLocal ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').show();
Line 959 ⟶ 1,078:
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText;
minAmount = donationForm.minimums[ donationForm.currency ] || 1,
maxAmount = donationForm.maxUSD * minAmount,
feeText, locale;
 
localefeeText = donationForm.getLocaleformatCurrency( mw.config.get('wgPageContentLanguage'), donationForm.countryfeeAmount );
feeText = donationForm.formatAmount( feeAmount, locale );
 
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <= maxAmountdonationForm.maxLocal ) {
$('.ptf').slideDown();
}
Line 995 ⟶ 1,111:
'UAH' : 10,
'ZAR' : 5,
// Latin America // Updated 20232024-0108-1722 to approx 0.35 USD equivalent
'BRL' : 1.75,
'ARS' : 32300,
'CLP' : 322300,
'COP' : 13851400,
'MXN' : 6,
'PEN' : 1.32,
'UYU' : 13.714
};
 
Line 1,058 ⟶ 1,174:
};
}
};
 
/**
* Make language and country into a standard javascript Intl locale identifier
*
* @param {string} language
* @param {string} country
* @return {string} locale identifier e.g. en-GB
*/
donationForm.getLocale = function( language, country ) {
if ( language === 'en-gb' ) {
language = 'en';
}
if ( language === 'es-419' ) {
language = 'es';
}
if ( language === 'pt-br' ) {
language = 'pt';
}
return language + '-' + country;
};
 
Line 1,098 ⟶ 1,194:
}
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 ( 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,307 ⟶ 1,378:
var form = document.forms.donateForm;
 
// TheseMinimum getamount usedis inusually quiteabout a1 few placesUSD
donationForm.minLocal = donationForm.currencyRates[ donationForm.currency ];
try {
donationForm.currencyminLocal = formMath.currency_codeceil( donationForm.valueminLocal * 100 ) / 100; // Round it up
}donationForm.maxUSD catch (error) {= 25000;
donationForm.maxLocal = Math.floor( donationForm.currencyRates[ donationForm.currency =] * donationForm.maxUSD 'USD');
 
// Overrides for India
if ( donationForm.currency === 'INR' ) {
donationForm.minLocal = 10;
// Until https://phabricator.wikimedia.org/T370583 fixed?
donationForm.maxUSD = 3000;
donationForm.maxLocal = 250000;
}
donationForm.country = mw.util.getParamValue('country').toUpperCase();
 
// Block typing symbols in Other field
Line 1,350 ⟶ 1,427:
$( '.paymentmethod-pp, .paymentmethod-pp-usd' ).addClass( 'not-monthly-capable' );
}
// Format amounts on buttons
$( '.amount-options li' ).each( function( index ) {
let amount = this.querySelector( 'input' ).value;
if ( amount !== 'Other' ) {
this.querySelector( 'label' ).innerText = donationForm.formatCurrency( amount );
}
});
 
addCardTypesClass( donationForm.country );
 
// Only show Amazon for links from Ways to give
// TODO: remove utm_source when Ways to give has been updated
if (
mw.util.getParamValue( 'wmf_source' ) === 'Waystogive' ||
Line 1,395 ⟶ 1,479:
&& mw.util.getParamValue('monthly') !== '0'
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1
&& mw.util.getParamValue('utm_medium') !== 'endowment'
&& mw.util.getParamValue('wmf_medium') !== 'endowment'
) {
$('#frequency_monthly').click();