MediaWiki:DonationFormSandbox.js: Difference between revisions

Content deleted Content added
Created page with "jshint strict:false: * MediaWiki:DonationForm.js - loaded on all donation forms * TODO: lots of cleanup: var donationForm = {}; donationForm.loadedTime = Date.now(); donationForm.extraData = { 'vw' : window.innerWidth, 'vh' : window.innerHeight }; if ( navigator.brave !== undefined ) { // T283367 donationForm.extraData.brave = '1'; } // Don't offer recurring at all in these countries donationForm.noRecurringCountries = [ 'AR', 'CL', 'CO', 'MX',..."
 
base64 decode recipient_id if needed
 
(48 intermediate revisions by 2 users not shown)
Line 7:
 
donationForm.loadedTime = Date.now();
donationForm.extraData = {};
'vw' : window.innerWidth,
'vh' : window.innerHeight
};
 
donationForm.country = mw.util.getParamValue('country').toUpperCase();
if ( navigator.brave !== undefined ) { // T283367
try {
donationForm.extraData.brave = '1';
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';
}
// MediaWiki allows some language codes like en-gb, en-ca, pt-br
// We don't want these for a javascript locale, so drop anything after '-'
language = language.split('-')[0];
 
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', 'CL', 'CO', 'MX', 'PE', 'UY', 'BR', 'IN' ];
 
donationForm.noRecurringPaypalCountries = [ 'CL', 'CO', 'PE', 'UY', 'BR' ];
 
donationForm.currencyRates = {
// From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php
// Updated 2024-07-31
'ADF' : 6.04,
'ADP' : 153,
'AED' : 3.67,
'AFA' : 70,
'AFN' : 70,
'ALL' : 90,
'AMD' : 368,
'ANG' : 1.79,
'AOA' : 844,
'AON' : 844,
'ARS' : 887,
'ATS' : 13,
'AUD' : 1.5,
'AWG' : 1.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.8,
'BBD' : 2,
'BDT' : 116,
'BEF' : 37,
'BGL' : 1.8,
'BGN' : 1.8,
'BHD' : 0.37355757356689,
'BIF' : 2842,
'BMD' : 1,
'BND' : 1.35,
'BOB' : 6.71,
'BRL' : 5.1,
'BSD' : 1,
'BTN' : 83,
'BWP' : 13,
'BYR' : 32642,
'BZD' : 1.98,
'CAD' : 1.36,
'CDF' : 2786,
'CHF' : 0.9094629289448,
'CLP' : 890,
'CNY' : 7.23,
'COP' : 3803,
'CRC' : 498,
'CUC' : 1,
'CUP' : 25,
'CVE' : 101,
'CYP' : 0.53848627984321,
'CZK' : 23,
'DEM' : 1.8,
'DJF' : 178,
'DKK' : 6.86,
'DOP' : 58,
'DZD' : 133,
'ECS' : 24094,
'EEK' : 14,
'EGP' : 47,
'ESP' : 153,
'ETB' : 57,
'EUR' : 0.92005843390143,
'FIM' : 5.47,
'FJD' : 2.23,
'FKP' : 0.78703952551207,
'FRF' : 6.04,
'GBP' : 0.78703952551207,
'GEL' : 2.71,
'GHC' : 143125,
'GHS' : 14,
'GIP' : 0.78703952551207,
'GMD' : 68,
'GNF' : 8493,
'GRD' : 314,
'GTQ' : 7.57,
'GYD' : 200,
'HKD' : 7.8,
'HNL' : 24,
'HRK' : 6.93,
'HTG' : 132,
'HUF' : 355,
'IDR' : 15986,
'IEP' : 0.72460490043714,
'ILS' : 3.69,
'INR' : 83,
'IQD' : 1290,
'IRR' : 42009,
'ISK' : 138,
'ITL' : 1781,
'JMD' : 154,
'JOD' : 0.70900000000001,
'JPY' : 156,
'KES' : 130,
'KGS' : 88,
'KHR' : 3993,
'KMF' : 453,
'KPW' : 135,
'KRW' : 1358,
'KWD' : 0.30629670764681,
'KYD' : 0.83333299999999,
'KZT' : 442,
'LAK' : 21103,
'LBP' : 89393,
'LKR' : 298,
'LRD' : 193,
'LSL' : 18,
'LTL' : 3.18,
'LUF' : 37,
'LVL' : 0.64662074757963,
'LYD' : 4.8,
'MAD' : 9.79,
'MDL' : 17,
'MGA' : 4379,
'MGF' : 9150,
'MKD' : 56,
'MMK' : 2075,
'MNT' : 2620,
'MOP' : 8.03,
'MRO' : 391,
'MTL' : 0.39498108567387,
'MUR' : 45,
'MVR' : 15,
'MWK' : 1720,
'MXN' : 17,
'MYR' : 4.68,
'MZM' : 63200,
'MZN' : 63,
'NAD' : 18,
'NGN' : 1505,
'NIO' : 36,
'NLG' : 2.03,
'NOK' : 11,
'NPR' : 131,
'NZD' : 1.63,
'OMR' : 0.38377594841305,
'PAB' : 1,
'PEN' : 3.67,
'PGK' : 3.76,
'PHP' : 58,
'PKR' : 277,
'PLN' : 3.91,
'PTE' : 184,
'PYG' : 7355,
'QAR' : 3.56,
'ROL' : 45713,
'RON' : 4.57,
'RSD' : 108,
'RUB' : 91,
'RWF' : 1277,
'SAR' : 3.75,
'SBD' : 8.37,
'SCR' : 13,
'SDD' : 59800,
'SDG' : 598,
'SDP' : 2261,
'SEK' : 11,
'SGD' : 1.35,
'SHP' : 0.78703952551207,
'SIT' : 220,
'SKK' : 28,
'SLL' : 19750,
'SOS' : 549,
'SRD' : 33,
'SRG' : 33320,
'STD' : 22477,
'SVC' : 8.75,
'SYP' : 513,
'SZL' : 18,
'THB' : 36,
'TJS' : 11,
'TMM' : 16750,
'TMT' : 3.35,
'TND' : 3.11,
'TOP' : 2.32,
'TRL' : 32168418,
'TRY' : 32,
'TTD' : 6.64,
'TWD' : 32,
'TZS' : 2587,
'UAH' : 39,
'UGX' : 3760,
'USD' : 1,
'UYU' : 38,
'UZS' : 12662,
'VEB' : 3651907631,
'VEF' : 3651908,
'VND' : 25451,
'VUV' : 112,
'WST' : 2.67,
'XAF' : 604,
'XAG' : 0.031347411860134,
'XAU' : 0.00041128929241299,
'XCD' : 2.7,
'XEU' : 0.92005843390143,
'XOF' : 604,
'XPD' : 0.00098009826645798,
'XPF' : 110,
'XPT' : 0.00093444018680404,
'YER' : 249,
'YUN' : 108,
'ZAR' : 18,
'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.maxUSDformatAmount = 12000;function( amount ) {
var formatterOptions, output;
donationForm.minimums = {
if ( amount % 1 !== 0 ) { // Not a whole number
/* From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php */
return formatters.amountFraction.format( amount );
'ADF' : 5.45,
} else {
'ADP' : 138,
return formatters.amountWhole.format( amount );
'AED' : 3.67,
}
'AFA' : 77,
'AFN' : 77,
'ALL' : 102,
'AMD' : 522,
'ANG' : 1.79,
'AOA' : 622,
'AON' : 622,
'ARS' : 90,
'ATS' : 11,
'AUD' : 1.29,
'AWG' : 1.79,
'AZM' : 8500,
'AZN' : 1.7,
'BAM' : 1.63,
'BBD' : 2,
'BDT' : 83,
'BEF' : 34,
'BGL' : 1.63,
'BGN' : 1.63,
'BHD' : 0.37503712235129,
'BIF' : 1927,
'BMD' : 1,
'BND' : 1.33,
'BOB' : 6.74,
'BRL' : 5.62,
'BSD' : 1,
'BTN' : 73,
'BWP' : 11,
'BYR' : 26065,
'BZD' : 1.97,
'CAD' : 1.26,
'CDF' : 1975,
'CHF' : 0.92373627643191,
'CLP' : 729,
'CNY' : 6.47,
'COP' : 3660,
'CRC' : 601,
'CUC' : 1,
'CUP' : 25,
'CVE' : 92,
'CYP' : 0.4866220993031,
'CZK' : 22,
'DEM' : 1.63,
'DJF' : 178,
'DKK' : 6.18,
'DOP' : 57,
'DZD' : 133,
'ECS' : 24094,
'EEK' : 13,
'EGP' : 16,
'ESP' : 138,
'ETB' : 40,
'EUR' : 0.83144322027478,
'FIM' : 4.94,
'FJD' : 2.02,
'FKP' : 0.71743442231745,
'FRF' : 5.45,
'GBP' : 0.71743442231745,
'GEL' : 3.3,
'GHC' : 57159,
'GHS' : 5.72,
'GIP' : 0.71743442231745,
'GMD' : 51,
'GNF' : 10041,
'GRD' : 283,
'GTQ' : 7.53,
'GYD' : 201,
'HKD' : 7.76,
'HNL' : 24,
'HRK' : 6.3,
'HTG' : 76,
'HUF' : 303,
'IDR' : 14279,
'IEP' : 0.65481474833248,
'ILS' : 3.3,
'INR' : 73,
'IQD' : 1442,
'IRR' : 42010,
'ISK' : 127,
'ITL' : 1610,
'JMD' : 149,
'JOD' : 0.70900000000001,
'JPY' : 107,
'KES' : 109,
'KGS' : 85,
'KHR' : 4019,
'KMF' : 409,
'KPW' : 135,
'KRW' : 1126,
'KWD' : 0.30191153907257,
'KYD' : 0.83333299999999,
'KZT' : 418,
'LAK' : 9170,
'LBP' : 1508,
'LKR' : 194,
'LRD' : 173,
'LSL' : 15,
'LTL' : 2.87,
'LUF' : 34,
'LVL' : 0.58434162098198,
'LYD' : 4.42,
'MAD' : 8.82,
'MDL' : 17,
'MGA' : 3716,
'MGF' : 9150,
'MKD' : 51,
'MMK' : 1392,
'MNT' : 2620,
'MOP' : 7.99,
'MRO' : 357,
'MTL' : 0.35693857446396,
'MUR' : 39,
'MVR' : 15,
'MWK' : 770,
'MXN' : 21,
'MYR' : 4.05,
'MZM' : 73880,
'MZN' : 74,
'NAD' : 15,
'NGN' : 380,
'NIO' : 35,
'NLG' : 1.83,
'NOK' : 8.52,
'NPR' : 115,
'NZD' : 1.38,
'OMR' : 0.38383957365098,
'PAB' : 1,
'PEN' : 3.63,
'PGK' : 3.43,
'PHP' : 49,
'PKR' : 157,
'PLN' : 3.78,
'PTE' : 167,
'PYG' : 6541,
'QAR' : 3.61,
'ROL' : 40517,
'RON' : 4.05,
'RSD' : 97,
'RUB' : 74,
'RWF' : 973,
'SAR' : 3.75,
'SBD' : 7.89,
'SCR' : 20,
'SDD' : 34467,
'SDG' : 345,
'SDP' : 2261,
'SEK' : 8.45,
'SGD' : 1.33,
'SHP' : 0.71743442231745,
'SIT' : 199,
'SKK' : 25,
'SLL' : 10105,
'SOS' : 558,
'SRD' : 14,
'SRG' : 14018,
'STD' : 20304,
'SVC' : 8.75,
'SYP' : 513,
'SZL' : 15,
'THB' : 30,
'TJS' : 11,
'TMM' : 16770,
'TMT' : 3.35,
'TND' : 2.69,
'TOP' : 2.22,
'TRL' : 7456951,
'TRY' : 7.46,
'TTD' : 6.66,
'TWD' : 28,
'TZS' : 2309,
'UAH' : 28,
'UGX' : 3641,
'USD' : 1,
'UYU' : 43,
'UZS' : 10427,
'VEB' : 1.86275657102E+14,
'VEF' : 186275657102,
'VND' : 22940,
'VUV' : 112,
'WST' : 2.43,
'XAF' : 545,
'XAG' : 0.038609238198237,
'XAU' : 0.000584537038152,
'XCD' : 2.7,
'XEU' : 0.83144322027478,
'XOF' : 545,
'XPD' : 0.000423507866364,
'XPF' : 99,
'XPT' : 0.00085367167460603,
'YER' : 250,
'YUN' : 97,
'ZAR' : 15,
'ZMK' : 5176,
'ZWD' : 373
};
 
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
var currency = donationForm.currency;
var minAmount = donationForm.minimums[ currency ];
/* T287706 - round to 2 decimal places (rounding up) */
var numFormat = function( amount ) {
return Math.ceil( amount * 100 ) / 100;
};
 
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', numFormatdonationForm.formatAmount( minAmountdonationForm.minLocal ) + ' \xa0' + currency );
});
 
if ( currency === 'USD' ) {
// we don't need to include the conversion
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '($1 $2) ', '' )
.replace( '($1 $2) ', '' );
});
}
}
 
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', numFormatdonationForm.formatAmount( donationForm.maxUSD * minAmountmaxLocal ) )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' )
.replace( '$4', donationForm.formatAmount( donationForm.maxUSD ) );
});
};
 
 
function adjustHPC() {
/* Adjust amounts based on highest previous contribution (hpc)
or most recent contribution (mrc) parameter. Used for emails.
TODO: split data out? */
 
var hpcSet = mw.util.getParamValue('hpcSet');
// Look for 'hpc' parameter, then 'mrc'. If neither, then bail out.
var hpc = parseFloat( mw.util.getParamValue('hpc') );
if( isNaN(hpc) ) {
hpc = parseFloat( mw.util.getParamValue('mrc') );
if( isNaN(hpc) ) {
return;
}
}
 
// Look for 'hpc' parameter, then 'mrc'
var hpcSet = mw.util.getParamValue('hpcSet');
var hpc = parseFloat( mw.util.getParamValue('hpc') );
if( isNaN(hpc) ) {
hpc = parseFloat( mw.util.getParamValue('mrc') );
if( isNaN(hpc) ) {
if ( hpcSet ) {
// Allow using hpcSet even without hpc, for MG appeals
hpc = 0;
} else {
return;
}
}
}
 
var currency = donationForm.currency;
var language = mw.config.get('wgPageContentLanguage');
 
// If changing, please update https://docs.google.com/spreadsheets/d/1e02TsZ_bKDAS1BMVBCdyo9D7RGln_wCGnkg7IF5kU5s/edit
var radioAmountsData = {
"USD" : { // also used for CAD, 'USD'AUD, : {NZD
' "default'" : [
[ 0, [ 2.75, 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, [ 7550, [ 75, 100, 150 200, 250 300, 500, 750, 1000 ] ],
[ 75, [ 75, [ 100, [ 100150, 150, 250, 500, 750, 1000, 2500 ] ],
[ 100, [ 150100, [ 150, 200 250, 300, 500, 750, 1000, 20002500 ] ],
[ 150, [ 200150, [ 200, 300, 500, 750, 1000, 2500, 50002000 ] ],
[ 200, [ 200, 300, [ 500, [ 500750, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 500, [ 500, [ 1000750, [ 1000, 2000, 30002500, 4000, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, [ 3000, [ 3000, 4000, 5000, 6000, 7500, 10000, 12000 ] ],
[ 3000, [ 3000, 4000, 5000, 6000, 7500, ]10000, 12000 ] ]
],
'2incvar' : [
"FY2425_E1_T11_USD" : [ // Upgrade recurring +1 for lowest ask
[ 0, [ 1, 5, 10, 15, 20, 30, 50 ] ],
[ 30, [ 3.75, 5, 10, 20, 35 25, 50 35, 75 50 ] ],
[ 5, [ 5, [ 610, [ 615, 10, 20, 35, 50, 75, 100 ] ],
[ 10, [ 10, 15, 20, [ 1025, [ 1035, 15, 25, 50, 75, 100, 125 ] ],
[ 15, [ 15, [ 1320, [ 1325, 20, 35, 50, 75, 100, 125 ] ],
[ 20, [ 20, [ 1625, [ 1635, 25, 50, 75, 100, 150, 200 ] ],
[ 25, [ 25, 30, [ 2040, [ 2050, 35, 5075, 75100, 125, 150, 200 ] ],
[ 35, [ 35, [ 2350, [ 2375, 35100, 50200, 75300, 125, 175, 250500 ] ],
[ 50, [ 2650, [ 2675, 35100, 50200, 75300, 125 500, 175, 250750 ] ],
[ 75, [ 3075, [ 30100, 40150, 50250, 75500, 125, 175750, 2501000 ] ],
[ 100, [ 35100, [ 35150, 45250, 50500, 100, 125750, 1751000, 2502500 ] ],
[ 150, [ 40150, [ 40200, 50300, 75500, 100, 150750, 2501000, 3002000 ] ],
[ 45200, [ 45200, 50300, 75500, 100 750, 1501000, 2502500, 5005000 ] ],
[ 50500, [ 50500, 60750, 1001000, 1252500, 1755000, 2507500, 50010000 ] ],
[ 601000, [ 601000, 752000, 1003000, 1254000, 1755000, 2507500, 50010000 ] ],
[ 703000, [ 703000, 854000, 1005000, 1256000, 1757500, 25010000, 50012000 ] ],
],
[ 80, [ 80, 100, 125, 150, 200, 300, 500 ] ],
"FY2425_E1_T14_USD" : [ // Upgrade recurring amount dynamically
[ 90, [ 90, 100, 125, 150, 200, 300, 500 ] ],
[ 0, [ 2.75, 5, 10, [ 100, [ 10020, 125, 17525, 250, 35035, 500, 75050 ] ],
[ 5, [ 2.75, 5, 10, [ 12520, [ 125, 15025, 200, 30035, 500, 750, 100050 ] ],
[ 10, [ 2.75, 10, 15, [ 15020, [ 150, 17525, 250, 40035, 500, 750, 100050 ] ],
[ 15, [ 3.50, 10, 20, [ 17530, [ 175, 20050, 300, 40075, 500, 750, 1000100 ] ],
[ 20, [ 3.75, 10, 25, [ 20035, [ 200, 25050, 300, 40075, 500, 750, 1000100 ] ],
[ 25, [ 4.50, 10, 25, 35, 50, 75, 100 ] ],
[ 35, [ 6.75, 15, 30, 50, 75, 100, 150 ] ],
'3incvarsv' : [
[ 075, [ 15.75, 150, 5, 7.5075, 10100, 15200, 20300, 30500 ] ],
[ 3100, [ 24.75, 350, 5, 1075, 15100, 20200, 25300, 40500 ] ],
[ 6150, [ 644.75, 10100, 15150, 20250, 30500, 40750, 501000 ] ],
[ 10200, [ 10 50, 15100, 20150, 25250, 30500, 40750, 501000 ] ],
[ 13500, [ 13150, 20250, 25300, 35500, 45750, 551000, 752000 ] ],
[ 161000, [ 16250, 20500, 25750, 351000, 452500, 555000, 7510000 ] ],
[ 203000, [ 20500, 251000, 352000, 453500, 555000, 757500, 10010000 ] ],
],
[ 23, [ 23, 30, 37, 45, 55, 75, 100 ] ],
"FY2425_E1_T21_USD" : [ // Give less reactivation amount
[ 26, [ 26, 30, 37, 45, 55, 75, 100 ] ],
[ 0, [ 2.75, 5, [ 3010, [ 3020, 35, 4025, 45, 5535, 75, 10050 ] ],
[ 5, [ 2.75, 5, [ 3510, [ 3520, 40, 4525, 50, 6535, 75, 10050 ] ],
[ 10, [ 5, 10, [15, 4020, [ 4035, 45, 50, 65, 75, 100, 125 ] ],
[ 15, [ 10, 15, 20, [ 4525, [ 4535, 50, 55, 65, 75, 100, 125 ] ],
[ 20, [ 15, 20, 25, [ 5035, [ 50, 60, 75, 100, 125, 150, 200 ] ],
[ 25, [ 20, 25, [ 6035, [ 6050, 70, 8075, 100, 125, 150, 200 ] ],
[ 35, [ 25, 30, 40, [ 7050, [ 70, 8075, 100, 125, 150, 200, 250 ] ],
[ 75, [ 35, 50, [ 8075, [ 80100, 90200, 100, 125300, 150, 200, 250500 ] ],
[ 90100, [ 9075, 100, 125 150, 150 250, 200 500, 250 750, 3001000 ] ],
[ 150, [ 100, [ 100150, 110 250, 150 500, 200, 250750, 3001000, 3502500 ] ],
[ 200, [ 150, [ 125200, [ 125300, 150, 200500, 250, 300750, 4001000, 5002000 ] ],
[ 500, [ 150200, [ 150300, 175 500, 200, 250750, 3001000, 4002500, 5005000 ] ],
[ 1751000, [ 175500, 200 750, 2501000, 3002500, 4005000, 5007500, 75010000 ] ],
[ 2003000, [ 2001000, 2502000, 3003000, 3504000, 4005000, 5007500, 75010000 ] ],
],
],
// Direct Mail - fixed amounts
'4HA7' : [
"directmail" : [
[ 0, [ 2.75, 5, 10, 20, 25, 35, 100 ] ],
[ 0, [ 25, 35, [ 550, [ 5, 10100, 15150, 20250, 35, 50, 200300 ] ],
],
[ 10, [ 10, 15, 20, 25, 35, 50, 250 ] ],
"directmail250" : [
[ 15, [ 15, 20, 25, 35, 50, 75, 300 ] ],
[ 0, [ 20250, [ 20300, 25500, 35, 50750, 751000, 1002500, 5005000 ] ],
]
[ 25, [ 25, 30, 40, 50, 75, 100, 500 ] ],
},
[ 35, [ 35, 50, 75, 100, 200, 300, 1000 ] ],
"EUR" : {
[ 75, [ 75, 100, 150, 250, 500, 750, 2000 ] ],
"default" : [
[ 100, [ 100, 150, 250, 500, 750, 1000, 5000 ] ],
[ 0, [ 2.50, 5, 10, [ 15020, [ 150, 20025, 300, 50035, 750, 1000, 750050 ] ],
[ 5, [ 5, 10, [ 20015, [ 200, 30020, 500, 75035, 1000, 250050, 10000 100 ] ],
[ 10, [ 10, 15, 20, [ 500 25, [ 500, 75035, 1000, 250050, 5000, 7500, 12000100 ] ],
[ 15, [ 15, 20, 25, [ 1000, [ 100035, 2000, 3000, 4000, 500050, 7500 75, 12000 100 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 25, [ 25, 30, 40, 50, 75, 100, 150 ] ],
'5LA1' : [
[ 035, [ 135, 550, 10 75, 15100, 20200, 30300, 50500 ] ],
[ 350, [ 350, 575, 10100, 20200, 35300, 50500, 75750 ] ],
[ 675, [ 575, 10100, 20150, 35250, 50500, 75750, 1001000 ] ],
[ 10100, [ 10100, 15150, 25250, 50500, 75750, 1001000, 1252500 ] ],
[ 13150, [ 10150, 20200, 35300, 50500, 75750, 1001000, 1252000 ] ],
[ 16200, [ 15200, 25300, 50500, 75750, 1001000, 1502500, 2005000 ] ],
[ 20500, [ 20500, 35750, 501000, 752500, 1255000, 1507500, 20010000 ] ],
[ 231000, [ 201000, 352000, 503000, 754000, 1255000, 1757500, 25010000 ] ],
[ 263000, [ 253000, 354000, 505000, 756000, 1257500, 17510000, 25012000 ] ],
],
[ 30, [ 30, 40, 50, 75, 125, 175, 250 ] ],
"FY2425_E1_T11_EUR" : [ // Upgrade recurring +1 for lowest ask
[ 35, [ 35, 45, 50, 100, 125, 175, 300 ] ],
[ 0, [ 3.50, 5, [ 4010, [ 4020, 50, 7525, 100, 15035, 200, 30050 ] ],
[ 5, [ 5, 10, [ 4515, [ 4520, 50, 7535, 100, 15050, 250, 500100 ] ],
[ 10, [ 10, 15, [ 5020, [ 5025, 75, 10035, 125, 17550, 250, 500100 ] ],
[ 15, [ 15, 20, [ 6025, [ 6035, 75, 10050, 125, 17575, 250, 500100 ] ],
[ 20, [ 20, 25, 35, [ 7050, [ 7075, 85, 100, 125, 175, 250, 500150 ] ],
[ 25, [ 25, 30, 40, [ 8050, [ 8075, 100, 125, 150, 200, 300, 500 ] ],
[ 35, [ 35, 50, [ 9075, [ 90, 100, 125, 150200, 200, 300, 500 ] ],
[ 50, [ 50, 75, [ 100, [ 100200, 125, 175300, 250, 350500, 500, 750 ] ],
[ 75, [ 75, [ 125100, [ 125150, 150, 200250, 300, 500, 750, 1000 ] ],
[ 100, [ 150100, [ 150, 200, 300250, 400, 500, 750, 1000, 2500 ] ],
[ 175150, [ 175150, 200, 300, 400, 500, 750, 1000, 2000 ] ],
[ 200, [ 200, 225 300, 300 500, 400 750, 5001000, 7502500, 1000 5000 ] ],
[ 500, [ 500, 750, 1000, 2500, 5000, 7500, 10000 ] ],
[ 1000, [ 1000, 2000, 3000, 4000, 5000, 7500, 10000 ] ],
'2018control' : [
[ 03000, [ 53000, 104000, 205000, 256000, 357500, 5010000, 10012000 ] ],
],
[ 5, [ 10, 15, 20, 35, 50, 100, 150 ] ],
"FY2425_E1_T14_EUR" : [ // Upgrade recurring amount dynamically
[ 10, [ 15, 20, 25, 35, 50, 100, 150 ] ],
[ 0, [ 2.50, 5, 10, [ 1520, [ 20, 25, 35, 50, 75, 100, 250 ] ],
[ 5, [ 2.50, 5, 10, [ 20, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 10, [ 2.50, 10, 15, [ 2520, [ 30, 4025, 50, 7535, 100, 150, 25050 ] ],
[ 15, [ 2.50, 10, 20, [ 3530, [ 25, 50, 75, 100, 200, 250, 300 ] ],
[ 20, [ 3.50, 10, 25, [ 7535, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 25, [ 4.25, 10, 25, [ 10035, [ 25, 50, 100, 15075, 250, 500, 1000100 ] ],
[ 35, [ 6.25, 15, 30, [ 150, [ 50, 100, 15075, 200, 350100, 500, 1000150 ] ],
[ 75, [ 15, 50, 75, [ 200, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 100, [ 25, 50, 75, [ 500, [ 100, 250, 500200, 750, 1000300, 1500, 2000 500 ] ],
[ 150, [ 45, 100, 150, 250, [ 1000, [ 500, 1000, 2000, 2500750, 3000, 4000, 50001000 ] ],
[ 200, [ 50, 100, 150, 250, 500, 750, 1000 ] ],
[ 500, [ 150, 250, 300, 500, 750, 1000, 2000 ] ],
'LTLA' : [
[ 01000, [ 3250, 10500, 15750, 201000, 352500, 505000, 10010000 ] ],
[ 53000, [ 5500, 101000, 202000, 353500, 505000, 1007500, 15010000 ] ],
],
[ 10, [ 10, 20, 35, 50, 75, 100, 150 ] ],
"FY2425_E1_T21_EUR" : [ // Give less reactivation amount
[ 15, [ 15, 25, 35, 50, 75, 100, 250 ] ],
[ 0, [ 2.50, 5, 10, [ 20, [ 20, 3025, 50, 7535, 100, 150, 25050 ] ],
[ 5, [ 2.50, 5, 10, [ 2520, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 10, [ 5, 10, [15, 35, [ 2520, 50, 7535, 100, 20050, 250, 300100 ] ],
[ 15, [ 10, 15, 20, [ 75, [ 25, 50, 7535, 100, 20050, 300, 500100 ] ],
[ 20, [ 15, 20, 25, [ 100 35, [ 25, 50, 100, 15075, 250, 500, 1000100 ] ],
[ 25, [ 20, 25, 35, [ 150, [ 50, 100, 15075, 200, 350100, 500, 1000150 ] ],
[ 35, [ 25, 30, 40, [ 200, [ 10050, 150, 20075, 300, 400100, 500, 1000150 ] ],
[ 75, [ 35, 50, 75, [ 500, [ 100, 250, 500200, 750, 1000300, 1500, 2000 500 ] ],
[ 100, [ 75, 100, 150, 250, [ 1000, [ 500, 1000, 2000, 2500750, 3000, 4000, 50001000 ] ],
[ 150, [ 100, 150, 250, 500, 750, 1000, 2500 ] ],
[ 200, [ 150, 200, 300, 500, 750, 1000, 2000 ] ],
'midtier2018' : [
[ 0500, [ 3200, 5300, 10500, 20750, 301000, 502500, 1005000 ] ],
[ 51000, [ 5500, 10750, 201000, 352500, 505000, 1007500, 15010000 ] ],
[ 103000, [ 101000, 152000, 203000, 354000, 505000, 1007500, 15010000 ] ],
]
[ 15, [ 15, 20, 25, 35, 50, 100, 150 ] ],
},
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
"GBP" : {
[ 25, [ 35, 50, 75, 100, 150, 250, 500 ] ],
"default" : [
[ 35, [ 50, 75, 100, 150, 250, 350, 500 ] ],
[ 0, [ 2, 5, [ 5010, [ 7520, 100, 15025, 200, 25035, 350, 50050 ] ],
[ 5, [ 5, 10, [ 15, 75, [ 10020, 150, 20035, 300, 40050, 500, 1000100 ] ],
[ 10, [ 10, 15, 20, [ 100, [ 15025, 200, 25035, 300, 40050, 500, 1000100 ] ],
[ 15, [ 15, 20, 25, [ 150, [ 20035, 250, 30050, 400, 50075, 1000, 2500100 ] ],
[ 20, [ 20, 25, 35, [ 200 50, [ 500, 75075, 1000, 2000, 3500100, 5000, 7500150 ] ],
[ 25, [ 25, 30, 40, [ 500 50, [ 750, 100075, 1500, 2500, 5000100, 7500, 10000 150 ] ],
[ 35, [ 35, 50, 75, [ 1000100, [ 1000, 2000200, 3000, 4000, 5000300, 7500, 10000 500 ] ],
[ 50, [ 50, 75, 100, 200, 300, 500, 750 ] ],
[ 75, [ 75, 100, 150, 250, 500, 750, 1000 ] ],
'LT2018' : [
[ 0100, [ 5100, 10150, 20.18250, 25500, 35750, 501000, 1002500 ] ],
[ 5150, [ 10150, 15200, 20.18300, 35500, 50750, 1001000, 1502000 ] ],
[ 10200, [ 15200, 20.18300, 25500, 35750, 501000, 1002500, 1505000 ] ],
[ 15500, [ 20.18500, 25750, 351000, 502500, 755000, 1007500, 25010000 ] ],
[ 201000, [ 251000, 352000, 503000, 754000, 1005000, 1507500, 25010000 ] ],
[ 253000, [ 303000, 404000, 505000, 756000, 1007500, 15010000, 25012000 ] ],
],
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ],
"FY2425_E1_T11_GBP" : [ // Upgrade recurring +1 for lowest ask
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 0, [ 3, 5, [ 10010, [ 25 20, 50, 10025, 150, 25035, 500, 1000 50 ] ],
[ 5, [ 5, 10, [ 15015, [ 50 20, 100, 15035, 200, 35050, 500, 1000100 ] ],
[ 10, [ 10, 15, 20, [ 200, [ 10025, 150, 20035, 300, 40050, 500, 1000100 ] ],
[ 15, [ 15, 20, 25, [ 50035, [ 100, 25050, 500, 75075, 1000, 1500, 2018100 ] ],
[ 20, [ 20, 25, 35, [ 1000, [ 50050, 1000, 2018, 2500, 300075, 4000 100, 5000 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 ] ],
'JPY' : [
[ 75, [ 075, [ 100, 500, 1000150, 2000, 2500250, 4000500, 5000750, 100001000 ] ],
[ 100, [ 1000100, [ 1000150, 1500 250, 2500, 4000500, 5000750, 100001000, 150002500 ] ],
[ 150, [ 1500150, [ 1500200, 2000 300, 3000, 4000500, 5000750, 100001000, 150002000 ] ],
[ 200, [ 2000200, [ 2000300, 2500 500, 3500, 5000750, 75001000, 100002500, 250005000 ] ],
[ 500, [ 500, 750, [ 25001000, [ 2500, 3500, 5000, 7500, 10000, 15000, 25000 ] ],
[ 1000, [ 1000, [ 30002000, [ 3000, 4000, 5000, 7500, 10000, 15000, 25000 ] ],
[ 3000, [ 25003000, [ 25004000, 5000, 75006000, 10000, 200007500, 3000010000, 5000012000 ] ],
],
[ 2500, [ 2500, 5000, 7500, 10000, 20000, 50000, 100000 ] ],
"FY2425_E1_T14_GBP" : [ // Upgrade recurring amount dynamically
[ 5000, [ 5000, 10000, 15000, 20000, 35000, 50000, 100000 ] ],
[ 0, [ 2, [ 10000 5, [ 10000, 25000, 5000010, 75000 20, 100000 25, 150000 35, 200000 50 ] ],
[ 5, [ 2, 5, 10, 20, 25, 35, 50 ] ],
],
[ 10, [ 2, 10, 15, 20, 25, 35, 50 ] ],
'SEK' : [
[ 15, [ 2, [10, 0 20, [ 20 30, 50, 100, 200, 300, 50075, 1000 100 ] ],
[ 20, [ 3, [10, 3025, [ 30 35, 50, 100, 200, 300, 50075, 1000 100 ] ],
[ 25, [ 4, [10, 50, [ 5025, 100, 150, 200 35, 300 50, 500 75, 1000 100 ] ],
[ 35, [ 6, [15, 200 30, [ 50, 100, 200, 300, 50075, 750 100, 1000 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 ] ],
radioAmountsData.AUD = radioAmountsData.USD;
[ 200, [ 45, 100, 150, 250, 500, 750, 1000 ] ],
radioAmountsData.CAD = radioAmountsData.USD;
[ 500, [ 125, 250, 300, 500, 750, 1000, 2000 ] ],
radioAmountsData.GBP = radioAmountsData.USD;
[ 1000, [ 200, 500, 750, 1000, 2500, 5000, 10000 ] ],
radioAmountsData.NZD = radioAmountsData.USD;
[ 3000, [ 400, 1000, 2000, 3500, 5000, 7500, 10000 ] ]
radioAmountsData.EUR = radioAmountsData.USD;
],
"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 ] ],
[ 1000, [ 1000, 1500, 2500, 4000, 5000, 10000, 15000 ] ],
[ 1500, [ 1500, 2000, 3000, 4000, 5000, 10000, 15000 ] ],
[ 2000, [ 2000, 2500, 3500, 5000, 7500, 10000, 25000 ] ],
[ 2500, [ 2500, 3500, 5000, 7500, 10000, 15000, 25000 ] ],
[ 3000, [ 3000, 4000, 5000, 7500, 10000, 15000, 25000 ] ],
[ 2500, [ 2500, 5000, 7500, 10000, 20000, 30000, 50000 ] ],
[ 2500, [ 2500, 5000, 7500, 10000, 20000, 50000, 100000 ] ],
[ 5000, [ 5000, 10000, 15000, 20000, 35000, 50000, 100000 ] ],
[ 10000, [ 10000, 25000, 50000, 75000, 100000, 150000, 200000 ] ]
],
"SEK" : [
[ 0, [ 30, 100, 150, 200, 500, 750, 1000 ] ],
[ 50, [ 50, 100, 150, 200, 300, 750, 1000 ] ],
[ 200, [ 50, 100, 200, 300, 500, 750, 1000 ] ]
]
};
radioAmountsData.AUD = radioAmountsData.USD;
radioAmountsData.CAD = radioAmountsData.USD;
radioAmountsData.NZD = radioAmountsData.USD;
 
// Major gifts appeals, hacky but this is easier than adding a load of new forms to maintain
var appealAmountsData = {
var currencyList = [ 'USD', 'CAD', 'AUD', 'NZD', 'GBP', 'EUR' ]; // close enough
'USD' : [
for ( let i = 0; i < currencyList.length; i++ ) {
[ 0, [ 5, 10, 20 ] ],
radioAmountsData[ currencyList[i] ].MG_2024_500 = [ [ 0, [ 500, 10750, [1000, 1250, 101500, 201750, 2000 50] ] ],;
radioAmountsData[ currencyList[i] ].MG_2024_650 = [ [ 0, [ 650, 20750, [1000, 1250, 201500, 301750, 2000 50] ] ],;
}
[ 35, [ 20, 30, 50 ] ],
[ 50, [ 20, 50, 100 ] ],
[ 75, [ 50, 75, 100 ] ],
[ 100, [ 75, 100, 150 ] ],
[ 150, [ 75, 100, 200 ] ],
[ 200, [ 100, 200, 300 ] ]
],
'JPY' : [
[ 0, [ 300, 500, 1000 ] ],
[ 3, [ 500, 1000, 1500 ] ],
[ 5, [ 1000, 1500, 2000 ] ],
[ 10, [ 1500, 2000, 5000 ] ],
[ 20, [ 2000, 3000, 5000 ] ],
[ 50, [ 2000, 5000, 10000 ] ],
[ 100, [ 5000, 10000, 15000 ] ]
],
'SEK' : [
[ 0, [ 20, 50, 100 ] ],
[ 3, [ 30, 50, 100 ] ],
[ 5, [ 50, 100, 150 ] ],
[ 15, [ 100, 150, 200 ] ],
[ 23, [ 100, 200, 300 ] ],
[ 38, [ 100, 200, 500 ] ],
[ 75, [ 100, 500, 750 ] ],
[ 112, [ 100, 500, 1000 ] ]
]
};
appealAmountsData.AUD = appealAmountsData.USD;
appealAmountsData.CAD = appealAmountsData.USD;
appealAmountsData.GBP = appealAmountsData.USD;
appealAmountsData.NZD = appealAmountsData.USD;
appealAmountsData.EUR = appealAmountsData.USD;
 
var formatsappealAmountsData = {
"USD" : [ // also used for CAD, AUD, NZD, GBP, EUR
"USD" : "$\t",
[ 0, [ 5, "EUR" :10, { 20 ] ],
[ 10, [ 10, 20, 50 ] "en" : "€\t"],
[ 20, [ 20, 30, 50 ] "cy" : "€\t"],
[ 35, [ 20, 30, 50 ] "ga" : "€\t"],
[ 50, [ 20, 50, 100 ] "mt" : "€\t"],
[ 75, [ 50, 75, 100 ] "nl" : "€ \t"],
[ 100, [ 75, 100, 150 ] ],
"lv" : "€ \t",
[ 150, [ 75, 100, 200 ] ],
"tr" : "€ \t",
[ 200, [ 100, 200, 300 ] ]
"default" : "\t €"
],
},
"AUDJPY" : "$\t",[
[ 0, [ 300, "CAD" :500, { 1000 ] ],
[ 3, [ 500, 1000, 1500 ] "fr" : "\t $"],
[ 5, [ 1000, 1500, 2000 ] "default" : "$\t"],
[ 10, [ 1500, 2000, }5000 ] ],
[ 20, [ 2000, 3000, "GBP"5000 :] "£\t"],
[ 50, [ 2000, 5000, 10000 "NZD"] : "$\t"],
[ 100, [ 5000, 10000, 15000 ] ]
"JPY" : "¥\t",
],
"SEK" : "\t kr",
"BRLSEK" : "R$\t"[
[ 0, [ 20, 50, 100 ] ],
};
[ 3, [ 30, 50, 100 ] ],
[ 5, [ 50, 100, 150 ] ],
[ 15, [ 100, 150, 200 ] ],
[ 23, [ 100, 200, 300 ] ],
[ 38, [ 100, 200, 500 ] ],
[ 75, [ 100, 500, 750 ] ],
[ 112, [ 100, 500, 1000 ] ]
]
};
appealAmountsData.AUD = appealAmountsData.USD;
appealAmountsData.CAD = appealAmountsData.USD;
appealAmountsData.GBP = appealAmountsData.USD;
appealAmountsData.NZD = appealAmountsData.USD;
appealAmountsData.EUR = appealAmountsData.USD;
 
// Radio button amounts
var format = formats[currency][language] || formats[currency]['default'] || formats[currency] || '\t';
var radioAmounts = pickAmountArray( radioAmountsData, currency, hpc, hpcSet );
if ( radioAmounts.length ) {
// Change buttons
for (var j = 0; j < radioAmounts.length; j++) {
var $radio = $("#input_amount_" + j);
var $label = $("label[for='input_amount_" + j + "']");
$radio.val( radioAmounts[j] );
$label.text( donationForm.formatCurrency( radioAmounts[j] ) );
}
}
 
// Radio buttonAppeal amounts
var radioAmountsappealAmounts = pickAmountArray( radioAmountsDataappealAmountsData, currency, hpc, hpcSet );
if ( radioAmountsappealAmounts.length ) {
var appealAmountString = appealAmounts.map( donationForm.formatCurrency ).join( ', ');
// Change buttons
$('.consider-amounts').html(appealAmountString);
for (var j = 0; j < radioAmounts.length; j++) {
}
var $radio = $("#input_amount_" + j);
var $label = $("label[for='input_amount_" + j + "']");
$radio.val( radioAmounts[j] );
$label.text( format.replace('\t', radioAmounts[j]) );
}
}
 
// Appeal amounts
var appealAmounts = pickAmountArray( appealAmountsData, currency, hpc, hpcSet );
if ( appealAmounts.length ) {
// 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);
}
 
}
 
function pickAmountArray( data, currency, hpc, hpcSet ) {
/**
* Choose the amounts for radio buttons / appeal based on hpc
* @param {Object} data
* @param {String} currency
* @param {Number} hpc
* @param {String} hpcSet
* @return {Array} Array of amounts (as numbers)
*/
 
var set, amounts;
 
if ( !(currency in data) ) {
return [];
}
}
 
if ( $.isArray(data[currency]) ) {
// No variant sets
set = data[currency];
} else {
// We need to go deeper. Check the variants.
if ( hpcSet in data[currency] ) {
set = data[currency][hpcSet];
} else {
set = data[currency]['default'];
}
}
}
}
 
// Find correct amount array for this hpc
for (var i = 0; i < set.length; i++) {
if ( set[i][0] > hpc ) {
break;
}
}
amounts = set[i][1];
}
}
 
return amounts;
 
}
 
function preSelect() {
/* Check for a 'preSelect' url parameter, and select that option.
If there isn't an option, add it to the "Other" box and select that */
var preSelectAmount = parseFloat( mw.util.getParamValue('preSelect') );
if ( preSelectAmount > 0 ) {
var $preSelectOption = $('input[name="amount"][value="' + preSelectAmount + '"]');
if ( $preSelectOption.length ) {
// Select existing input
$preSelectOption.prop('checked', true);
} else {
$('#input_amount_other_box').val( preSelectAmount );
$('#input_amount_other').prop('checked', true);
}
}
donationForm.updateFeeDisplay();
}
}
}
 
function addCardTypesClass(country) {
/**
* Add card types class to credit card button, so we can show correct logos
* Banner equivalent: https://meta.wikimedia.org/wiki/MediaWiki:FundraisingBanners/LocalizeJS-2017.js
* @param {String} country ISO code
*/
var cardTypes = {
// Big 6
'US' : 'vmad',
'CA' : 'vma',
'GB' : 'vmaj',
'IE' : 'vmaj',
'AU' : 'vmaj',
'NZ' : 'vma',
// Euro countries
'AT' : 'vmaj',
'BE' : 'vmaj',
'ES' : 'vmaj',
'FR' : 'vma', // Adyen - Carte Bancaire was removed
'IT' : 'vmaj',
'LU' : 'vmaj',
'LV' : 'vma',
'NL' : 'vmaj',
'PT' : 'vmaj',
'SK' : 'vmaj',
'GR' : 'vma',
// Others
// Others
'DK' : 'vma',
'HUCZ' : 'vmavmad',
'ILDK' : 'vmadvma', // Adyen
'JPHU' : 'vmjvma',
'MYIL' : 'vmajvmad', // Adyen
'NOJP' : 'vmavmaj',
'PLMY' : 'vmavmaj',
'RONO' : 'vma',
'SEPL' : 'vma',
'UARO' : 'vma', // Adyen
'ZASE' : 'vmvma',
'UA' : 'vma', // Adyen
};
'ZA' : 'vm',
if ( cardTypes[country] ) {
'ZZ' : 'vmad' // For testing
$('.paymentmethod-cc').addClass('cctypes-' + cardTypes[country] );
};
}
if ( cardTypes[country] ) {
$('.paymentmethod-cc').addClass('cctypes-' + cardTypes[country] );
$('.cc-text-label').addClass('sr-only');
}
}
 
/* Form functions */
function clearOther(box) {
document.getElementById('input_amount_other').checked = true;
box.value = "";
}
 
function selectOther() {
document.getElementById('input_amount_other').checked = true;
}
 
function selectAmount() {
$('#input_amount_other_box').val('');
}
 
Line 681 ⟶ 769:
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
 
if ( donationForm.validate( skipAmountValidation ) ) {
 
var params = {};
 
params.currency = donationForm.currency;
// Overrides for specific cc gateways
params.country = donationForm.country;
if ( paymentMethod === 'cc-adyen' ) {
params.payment_method = 'cc';
params.gateway = 'adyen';
params.ffname = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
params.payment_method = 'cc';
params.gateway = 'astropay';
} else {
params.payment_method = paymentMethod;
}
 
// Overrides for specific cc gateways
if ( paymentSubMethod ) {
if ( paymentMethod === 'cc-adyen' ) {
params.payment_submethod = paymentSubMethod;
params.payment_method = 'cc';
}
params.gateway = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
params.payment_method = 'cc';
params.gateway = 'astropay';
} else {
params.payment_method = paymentMethod;
}
 
if ( params.payment_method === 'cc' && params.country === 'ZA' ) {
var frequency = $('input[name="frequency"]:checked').val();
params.gateway = 'astropay';
if ( frequency !== 'monthly' ) {
}
params.recurring = false;
} else {
params.recurring = true;
}
 
if ( paymentSubMethod ) {
params.currency_code = donationForm.currency;
params.payment_submethod = paymentSubMethod;
params.country = donationForm.country;
}
params.uselang = mw.config.get('wgPageContentLanguage'); // see T281285 for why not wgUserLanguage
 
let frequency = donationForm.getFrequency();
if ( params.uselang === 'pt' && params.country === 'BR' ) {
if ( frequency === 'monthly' ) {
params.uselang = 'pt-br';
params.recurring = '1';
}
if ( params.uselangfrequency_unit === 'esmonth' &&;
} else if ( frequency === 'annual' ) {
( params.country === 'AR' || params.country === 'CL' ||
params.recurring = '1';
params.country === 'CO' || params.country === 'MX' ||
params.frequency_unit = 'year';
params.country === 'PE' || params.country === 'UY' ||
}
params.country === 'US' )
) {
params.uselang = 'es-419';
}
 
params.uselang = mw.config.get('wgPageContentLanguage'); // see T281285 for why not wgUserLanguage
var amount = donationForm.getAmount();
if ( $('#ptf-checkbox').prop('checked') ) {
amount = amount + donationForm.calculateFee( amount );
donationForm.extraData.ptf = 1;
}
params.amount = amount;
 
if ( params.uselang === 'pt' && params.country === 'BR' ) {
// Email optin
params.uselang = 'pt-br';
if ( $('input[name="opt_in"]').length > 0 ) {
}
var opt_inValue = $('input[name="opt_in"]:checked').val();
if ( params.uselang === 'es' &&
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
( params.country === 'AR' || params.country === 'CL' ||
}
params.country === 'CO' || params.country === 'MX' ||
params.country === 'PE' || params.country === 'UY' ||
params.country === 'US' )
) {
params.uselang = 'es-419';
}
 
var amount = donationForm.getAmount();
// Default to variant = panExplain for India
if ( $('#ptf-checkbox').prop('checked') ) {
// TODO: make this default payments side - https://phabricator.wikimedia.org/T259146
amount = amount if (+ donationForm.countrycalculateFee( === 'IN'amount ) {;
donationForm.extraData.ptf = 1;
params.variant = 'panExplain';
}
}
params.amount = amount;
 
// Email optin
if ( mw.util.getParamValue( 'pym_variant' ) ) {
if ( $('input[name="opt_in"]').length > 0 ) {
params.variant = mw.util.getParamValue( 'pym_variant' );
var opt_inValue = $('input[name="opt_in"]:checked').val();
}
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
if ( mw.util.getParamValue( 'pym_appeal' ) ) {
}
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
 
if ( mw.util.getParamValue( 'pym_variant' ) ) {
// Check for monthly convert. TODO: make it possible to test JS variants
params.variant if (= mw.util.getParamValue( 'monthlyconvertpym_variant' ) ) {;
}
mc.main( params, donationForm.finalStep );
if ( params.recurring && params.variant && params.variant.match( /monthlyConvert/ ) ) {
} else {
// Post-payments monthly convert makes no sense if it's already recurring
donationForm.finalStep( params );
// Avoid things like T312905
}
delete params.variant;
}
 
// TODO: refactor this to a list of parameters to pass unchanged
} else {
// or just pass everything by default?
donationForm.extraData.validateError = 1; // Flag they had an error, even if fixed later
if ( mw.util.getParamValue( 'pym_appeal' ) ) {
}
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
// https://phabricator.wikimedia.org/T381405
if ( mw.util.getParamValue( 'contact_id' ) ) {
params.contact_id = mw.util.getParamValue( 'contact_id' );
}
if ( mw.util.getParamValue( 'contact_hash' ) ) {
params.contact_hash = mw.util.getParamValue( 'contact_hash' );
}
// SMS
var recipient_id = mw.util.getParamValue( 'recipient_id' );
if ( recipient_id ) {
if ( isNaN( parseFloat( recipient_id ) ) ) {
// Lop off last 2 characters and decode base64
params.recipient_id = atob( recipient_id.slice(0, -2) );
} else {
params.recipient_id = recipient_id;
}
}
 
// Monthly convert
return false; // don't submit if called by a button
if ( mc ) { // check just in-case this wasn't loaded for some reason
mc.main( params, donationForm.finalStep );
} else {
donationForm.finalStep( params );
}
 
} else {
donationForm.extraData.validateError = 1; // Flag they had an error, even if fixed later
}
 
return false; // don't submit if called by a button
};
 
Line 770 ⟶ 883:
donationForm.finalStep = function( params ) {
 
var uriurl = new mw.UriURL('https://payments.wikimedia.org/index.php/Special:GatewayFormChooserGatewayChooser');
 
// Skip form chooser for Apple Pay / Google Pay
if ( params.payment_method === 'apple' || params.payment_method === 'google' ) {
url = new URL('https://payments.wikimedia.org/index.php/Special:AdyenCheckoutGateway');
}
 
// Skip form chooser for Venmo
if ( params.payment_method === 'venmo' ) {
url = new URL('https://payments.wikimedia.org/index.php/Special:BraintreeGateway');
}
 
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );
 
// Tracking data
params.wmf_medium = paramsmw.utm_mediumutil.getParamValue( 'wmf_medium' ) =|| mw.util.getParamValue( 'utm_medium' );
params.wmf_campaign = mw.util.getParamValue( 'wmf_campaign' params.utm_campaign) =|| mw.util.getParamValue( 'utm_campaign' );
params.utm_sourcewmf_source = donationForm.buildUtmSourcebuildTrackingSource( params );
params.utm_keywmf_key = donationForm.buildUtmKeybuildTrackingKey( donationForm.extraData );
if ( document.referrer ) { // TODO: do we need this?
// Strip protocol to stop firewall complaining
params.referrer = document.referrer.replace(/https?:\/\//i, '');
}
}
 
for ( var key uriof Object.extendkeys( params ); ) {
url.searchParams.set( key, params[key] );
}
 
if ( window.top !== window.self ) {
// In a frame, open payments in a new tab
window.open( uriurl.toString() );
} else {
window.location.href = uriurl.toString();
}
}
};
 
/**
* Build a utm_sourcewmf_source value, including the landing page info.
*
* Own function so it can be overriden for weird tests
*
* @param {Object} params
* @return {string} utm_sourcewmf_source
*/
donationForm.buildUtmSourcebuildTrackingSource = function( params ) {
 
var utm_sourcewmf_source = mw.util.getParamValue( 'utm_sourcewmf_source' ) +|| 'mw.util.getParamValue( 'utm_source' );
wmf_source += '.';
 
var fullDottedPaymentMethod = params.payment_method;
if ( params.recurring ) {
fullDottedPaymentMethod = 'r' + fullDottedPaymentMethod;
}
}
if ( params.payment_submethod ) {
fullDottedPaymentMethod = fullDottedPaymentMethod + '.' + params.payment_submethod;
}
}
 
/* Get URL parameter, but remove parts using old format. Allow fallback to a default value */
var getParam = function( param, removeText, dflt ) {
if ( mw.util.getParamValue( param ) ) {
return mw.util.getParamValue( param ).replace( removeText, '' );
} else {
return dflt;
}
}
};
 
/* The landing page info, separated by ~. This mostly exists for legacy reasons */
utm_source wmf_source += getParam( 'template' , 'Lp-layout' , 'default' ) + '~';
utm_source wmf_source += getParam( 'appeal-template' , 'Appeal-template-' , 'default' ) + '~';
utm_source wmf_source += getParam( 'appeal' , 'Appeal-' , 'default' ) + '~';
utm_source wmf_source += getParam( 'form-template' , 'Form-template-' , 'default' ) + '~';
utm_source wmf_source += getParam( 'form-countryspecific', 'Form-countryspecific-', 'control' );
 
utm_source wmf_source += '.' + fullDottedPaymentMethod;
 
return utm_sourcewmf_source;
 
};
 
/**
* Build a string for utm_keywmf_key from extra tracking data
*
* @param {Object} data
* @return {string} utm_keywmf_key
*/
donationForm.buildUtmKeybuildTrackingKey = function(data) {
var existingKey = mw.util.getParamValue( var'wmf_key' existingUtmKey) =|| mw.util.getParamValue( 'utm_key' ),
dataArray = [];
 
if ( existingUtmKeyexistingKey ) {
dataArray.push( existingUtmKeyexistingKey );
}
}
for (var key in data) {
if (data.hasOwnProperty(key)) {
dataArray.push( key + '_' + data[key] );
}
}
}
}
return dataArray.join('~');
};
 
/* Return amount selected or input */
donationForm.getAmount = function() {
var form = document.forms['.donateForm'],
amount = null;
donationForm.extraData.otherAmt = 0;
 
// If there are some amount radio buttons, then look for the checked one
if ( form.amount ) {
for ( var i = 0; i < form.amount.length; i++ ) {
if ( form.amount[i].checked ) {
amount = parseFloat( form.amount[i].value );
}
}
}
}
}
}
// Check the "other" amount box
if ( document.getElementById('input_amount_other').checked ) {
amount = donationForm.parseOtherAmount( form.input_amount_other_box.value );
donationForm.extraData.otherAmt = 1;
}
}
 
return amount;
 
};
Line 891 ⟶ 1,017:
*/
donationForm.parseOtherAmount = function( value ) {
var amount;
 
value = value.replace(/[,.](\d)$/, '\:$10');
value = value.replace(/[,.](\d)(\d)$/, '\:$1$2');
value = value.replace(/[\$£€¥,.]/g, '');
value = value.replace(/:/, '.');
 
amount = parseFloat( value );
if ( isNaN( amount ) ) {
return 0;
} else {
return amount;
}
}
};
 
Line 911 ⟶ 1,037:
donationForm.validate = function( skipAmountValidation ) {
 
var error = false;
var form = document.forms['.donateForm'];
 
// Reset all errors
$('.lp-haserror').removeClass('lp-haserror');
$('.lp-error').hide();
 
if ( !skipAmountValidation && !donationForm.validateAmount() ) {
error = true;
}
}
 
if ( form.opt_in ) {
if ( $('input[name="opt_in"]:checked').val() === undefined ) {
$('#error-optin').show().focus();
error = true;
} else {
$('#error-optin').hide();
}
}
}
}
 
return !error;
};
 
Line 940 ⟶ 1,066:
donationForm.validateAmount = function() {
 
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().focus();
return false;
} else if ( amount > donationForm.maxUSD * minAmountmaxLocal ) {
$('.amount-options').addClass('lp-haserror');
$('.lp-error-bigamount').show().focus();
return false;
} else {
$('.amount-options').removeClass('lp-haserror');
$('.lp-error-smallamount, .lp-error-bigamount').hide();
return true;
}
}
 
};
 
donationForm.toggleMonthlygetFrequency = function(monthly) {
return document.forms.donateForm.dataset.frequency || 'onetime';
if (monthly) {
};
$('#form-wrapper').addClass('form-monthly');
 
} else {
donationForm.setFrequency = function( frequency ) {
$('#form-wrapper').removeClass('form-monthly');
// TODO: add some validation to reject invalid frequency values
}
let form = document.forms.donateForm;
 
form.frequency.value = frequency; // change input
form.dataset.frequency = frequency;
};
 
/* Wrapper for compatibility with old forms */
donationForm.toggleMonthly = function( monthly ) {
if ( monthly ) {
donationForm.setFrequency( 'monthly' );
} else {
donationForm.setFrequency( 'onetime' );
}
};
 
donationForm.updateFeeDisplay = function() {
var selectedAmount = donationForm.getAmount(),
feeAmount = donationForm.calculateFee( selectedAmount ),
feeText;
minAmount = donationForm.minimums[ donationForm.currency ] || 1,
maxAmount = donationForm.maxUSD * minAmount,
feeText;
 
feeText = donationForm.formatCurrency( feeAmount );
if ( feeAmount % 1 !== 0 ) { // Not a whole number
feeText = feeAmount.toFixed(2);
} else {
feeText = feeAmount.toString();
}
 
$('.ptf label span').text( feeText );
if ( selectedAmount + feeAmount <= maxAmountdonationForm.maxLocal ) {
$('.ptf').slideDown();
}
}
};
 
Line 994 ⟶ 1,126:
donationForm.calculateFee = function( amount ) {
 
// Minimum fee/PTF amounts. Default is 0.35.
// Updated 2019-05-21 to approx 0.35 USD equivalent
var feeMinimums = {
'DKK' : 2,
'HUF' : 100,
'ILS' : 1.2,
'INR' : 254,
'JPY' : 35,
'MYR' : 1,
'NOK' : 3,
'PLN' : 1.35,
'RONCZK' : 17.5,
'SEKRON' : 31.5,
'UAHSEK' : 103,
'ZARUAH' : 510,
'ZAR' : 5,
// Latin America
// Latin America // Updated 2024-08-22 to approx 0.35 USD equivalent
'BRL' : 2,
'ARSBRL' : 321.75,
'CLPARS' : 255300,
'COPCLP' : 1300300,
'MXNCOP' : 7.41400,
'PENMXN' : 1.36,
'UYUPEN' : 151.52,
'UYU' : 14
};
};
 
var feeMultiplier = 0.04,
feeMinimum = feeMinimums[ donationForm.currency ] || 0.35,
feeAmount = amount * feeMultiplier;
 
if ( feeAmount < feeMinimum ) {
feeAmount = feeMinimum;
}
}
return parseFloat( feeAmount.toFixed(2) );
};
 
 
donationForm.initOptin = function() {
$('.optin-options').on('change', function(e) {
 
$('#error-optin').hide();
 
// Only do all this if we have translated prompts
if ( $('.optin-no-prompt').data('is-translated') === 'yes' ) {
if ( e.target.id === 'optin-no' ) {
$('.optin-no-prompt').removeClass('is-positive');
if ( !$('.optin-no-prompt').is(':visible') ) {
$('.optin-no-prompt').slideDown();
}
}
} else {
$('.optin-no-prompt').addClass('is-positive');
}
}
}
}
});
};
 
Line 1,058 ⟶ 1,191:
*/
donationForm.otherInputControl = function( inputElement ) {
if ( inputElement ) {
inputElement.onkeypress = function(e) {
// Allow special keys in Firefox
if ((e.code == 'ArrowLeft') || (e.code == 'ArrowRight') ||
(e.code == 'ArrowUp') || (e.code == 'ArrowDown') ||
(e.code == 'Delete') || (e.code == 'Backspace')) {
return;
}
}
var chr = String.fromCharCode(e.which);
if ('0123456789., '.indexOf(chr) === -1) {
return false;
}
}
};
};
}
}
};
 
/**
* Should we show Apple Pay?
* Make language and country into a standard javascript Intl locale identifier
*
* Note there is a ~500ms delay in Safari when checking, so only call this if needed
*
* Currently only used in monthlyconvert, but this could be useful
*
* @param {string} language
* @param {string} country
* @return {stringboolean} locale identifier
*/
donationForm.getLocaleshouldShowApplePay = function( language,( country ) {
if ( language === location.search.match('en-gbforceApplePay') ) {
return true;
language = 'en';
}
}
if ( language === 'es-419'window.ApplePaySession ) {
if ( ApplePaySession.canMakePayments() ) {
language = 'es';
return true;
}
}
if ( language === 'pt-br' ) {
}
language = 'pt';
return false;
}
return language + '-' + country;
};
 
/*
Based on github:braintree/braintree-web/src/venmo/shared/supports-venmo.js
See also on meta: MediaWiki:FundraisingBanners/VenmoBrowserCheck.js
*/
donationForm.isVenmoSupported = function(options) {
var options = options || {
allowNewBrowserTab: false,
allowWebviews: true,
allowDesktop: true,
allowDesktopWebLogin: true
};
var ua = window.navigator.userAgent;
 
var merchantAllowsReturningToNewBrowserTab,
merchantAllowsWebviews,
merchantAllowsDesktopBrowsers;
var isMobileDevice = isAndroid() || isIos();
var isAndroidChrome = isAndroid() && isChrome();
var isMobileDeviceThatSupportsReturnToSameTab = isIosSafari() || isAndroidChrome;
var isKnownUnsupportedMobileBrowser = isIosChrome() || isFacebookOwnedBrowserOnAndroid() || isSamsung();
 
options = options || {};
// NEXT_MAJOR_VERSION allowDesktop will default to true, but can be opted out
merchantAllowsDesktopBrowsers =
(options.allowDesktopWebLogin || options.allowDesktop) === true;
merchantAllowsReturningToNewBrowserTab = options.hasOwnProperty(
"allowNewBrowserTab"
)
? options.allowNewBrowserTab
: true;
// NEXT_MAJOR_VERSION webviews are not supported, except for the case where
// the merchant themselves is presenting venmo in a webview using the deep
// link url to get back to their app. For the next major version, we should
// just not have this option and instead require the merchant to determine
// if the venmo button should be displayed when presenting it in the
// merchant's app via a webview.
merchantAllowsWebviews = options.hasOwnProperty("allowWebviews")
? options.allowWebviews
: true;
 
if (isKnownUnsupportedMobileBrowser) {
return false;
}
 
if (
!merchantAllowsWebviews &&
(isAndroidWebview() || isIosWebview())
) {
return false;
}
 
if (!isMobileDevice) {
return merchantAllowsDesktopBrowsers;
}
 
if (!merchantAllowsReturningToNewBrowserTab) {
return isMobileDeviceThatSupportsReturnToSameTab;
}
 
return isMobileDevice;
 
/* -- functions mostly from github:braintree/browser-detection library -- */
 
function isAndroid() {
return /Android/i.test(ua);
}
 
function isIos(checkIpadOS = true) {
const iOsTest = /iPhone|iPod|iPad/i.test(ua);
return checkIpadOS ? iOsTest || isIpadOS() : iOsTest;
}
 
function isIpadOS() {
// "ontouchend" is used to determine if a browser is on an iPad, otherwise
// user-agents for iPadOS behave/identify as a desktop browser
return /Mac|iPad/i.test(ua) && "ontouchend" in window.document;
}
 
function isEdge() {
return ua.indexOf("Edge/") !== -1 || ua.indexOf("Edg/") !== -1;
}
 
function isSamsung() {
return /SamsungBrowser/i.test(ua);
}
 
function isDuckDuckGo() {
return ua.indexOf("DuckDuckGo/") !== -1;
}
 
function isOpera() {
return (
ua.indexOf("OPR/") !== -1 ||
ua.indexOf("Opera/") !== -1 ||
ua.indexOf("OPT/") !== -1
);
}
 
function isSilk() {
return ua.indexOf("Silk/") !== -1;
}
 
function isChrome() {
return (
(ua.indexOf("Chrome") !== -1 || ua.indexOf("CriOS") !== -1) &&
!isEdge() &&
!isSamsung() &&
!isDuckDuckGo() &&
!isOpera() &&
!isSilk()
);
}
 
function isIosFirefox() {
return /FxiOS/i.test(ua);
}
 
function isWebkit() {
const webkitRegexp = /webkit/i;
return webkitRegexp.test(ua);
}
 
function isIosChrome() {
return ua.indexOf("CriOS") > -1;
}
 
function isFacebook() {
return ua.indexOf("FBAN") > -1;
}
 
function isIosSafari() {
return (
isIos() &&
isWebkit() &&
!isIosChrome() &&
!isIosFirefox() &&
!isFacebook()
);
}
 
function isFacebookOwnedBrowserOnAndroid() {
var e = ua.toLowerCase();
return -1 < e.indexOf("huawei") && -1 < e.indexOf("fban") || isAndroid() && (-1 < e.indexOf("fb_iab") || -1 < e.indexOf("instagram"));
}
 
function isSamsungBrowser() {
return /SamsungBrowser/i.test(ua);
}
 
function isAndroidWebview() {
return isAndroid() && -1 < ua.toLowerCase().indexOf("wv");
}
 
function isGoogleSearchApp() {
return /\bGSA\b/.test(ua);
}
 
function isIosGoogleSearchApp() {
return isIos() && isGoogleSearchApp();
}
 
function isIosWebview() {
if (isIos()) {
// The Google Search iOS app is technically a webview and doesn't support popups.
if (isIosGoogleSearchApp()) {
return true;
}
// Historically, a webview could be identified by the presence of AppleWebKit and _no_ presence of Safari after.
return /.+AppleWebKit(?!.*Safari)/i.test(ua);
}
return false;
}
};
 
/* End form functions */
Line 1,101 ⟶ 1,405:
$(document).ready(function() {
 
mw.loader.using( ['mediawiki.util'] ).done( function() {
 
var form = document.forms.donateForm;
 
// Minimum amount is usually about 1 USD
donationForm.minLocal = donationForm.currencyRates[ donationForm.currency ];
donationForm.minLocal = Math.ceil( donationForm.minLocal * 100 ) / 100; // Round it up
donationForm.maxUSD = 25000;
donationForm.maxLocal = Math.floor( donationForm.currencyRates[ donationForm.currency ] * donationForm.maxUSD );
 
// Overrides for India
if ( donationForm.currency === 'INR' ) {
donationForm.minLocal = 10;
// Until https://phabricator.wikimedia.org/T370583 fixed?
donationForm.maxUSD = 3000;
donationForm.maxLocal = 250000;
}
 
// Block typing symbols in Other field
donationForm.otherInputControl( document.getElementById('input_amount_other_box') );
 
// Clear errors and update fee when selected/entered
$('.amount-options').on( 'input change', function() {
// Ideally we would validate the amount, but this causes issues with focus
$('.amount-options .lp-error').hide();
donationForm.updateFeeDisplay();
});
 
// Disable submitting form with Enter key
$('form[name="donateForm"]').on('keypress', function(e) {
var code = ( e.keyCode ? e.keyCode : e.which );
if ( code == 13 ) {
e.preventDefault();
}
});
 
// But allow Enter on buttons
$('.payment-method-button').keyup(function(e) {
if (event.keyCode === 13) {
e.target.click();
}
});
 
if ( form ) {
 
// hide frequency options for some countries
var form = document.forms['donateForm'];
if ( donationForm.noRecurringCountries.indexOf( donationForm.country ) !== -1 ) {
$('#frequency_onetime').prop('checked', true);
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
 
if ( donationForm.noRecurringPaypalCountries.indexOf( donationForm.country ) !== -1 ) {
// These get used in quite a few places
$( '.paymentmethod-pp, .paymentmethod-pp-usd' ).addClass( 'not-monthly-capable' );
donationForm.currency = form.currency_code.value;
}
donationForm.country = mw.util.getParamValue('country');
 
// Format amounts on buttons
// Block typing symbols in Other field
$( '.amount-options li' ).each( function( index ) {
donationForm.otherInputControl( document.getElementById('input_amount_other_box') );
let amount = this.querySelector( 'input' ).value;
if ( amount !== 'Other' ) {
this.querySelector( 'label' ).innerText = donationForm.formatCurrency( amount );
}
});
 
addCardTypesClass( donationForm.country );
// Validate amount and update fee when selected/entered
$('.amount-options').on( 'input change', function() {
donationForm.validateAmount();
donationForm.updateFeeDisplay();
});
 
// Only show Amazon for links from Ways to give
// Disable submitting form with Enter key
if (
$('form[name="donateForm"]').on('keypress', function(e) {
mw.util.getParamValue( 'wmf_source' ) === 'Waystogive' ||
var code = ( e.keyCode ? e.keyCode : e.which );
mw.util.getParamValue( 'wmf_source' ) === 'Ways_to_Give'
if ( code == 13 ) {
) {
e.preventDefault();
$('.paymentmethod-amazon').show();
}
}
});
 
// Apple Pay
// But allow Enter on buttons
if ( $('.paymentmethod-applepay').length > 0 ) {
$('.payment-method-button').keyup(function(e) {
if ( !donationForm.shouldShowApplePay( donationForm.country ) ) {
if (event.keyCode === 13) {
$('.paymentmethod-applepay').remove();
e.target.click();
}
}
}
});
 
// Venmo browser check
if ( form ) {
if ( $('.paymentmethod-venmo').length > 0 ) {
if ( !donationForm.isVenmoSupported() || donationForm.country !== 'US' ) {
$('.paymentmethod-venmo').remove();
}
}
 
// Dumb hack to remove ACH for Portal test against Fundraise Up
// hide frequency options for some countries
if ( mw.util.getParamValue( 'wmf_source' ) === 'portalBanner_en6C_2024_overlayBanner4WikiForm' ) {
if ( donationForm.noRecurringCountries.indexOf( donationForm.country ) !== -1 ) {
$('.paymentmethod-ach').remove();
$('#frequency_onetime').prop('checked', true);
}
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
 
}
addCardTypesClass( donationForm.country );
}
 
// Links open in new tab
$('.links-in-new-tab a').attr('target', '_blank');
 
// Disable logo link
$('#p-logo a').attr( { href: '#', title: '' } );
 
// These don't need to be tabbable on the landing page
$('#searchInput, .mw-jump-link').attr('tabindex', '-1');
 
$('.input_amount_other').click(function() {
$('#input_amount_other_box').focus();
});
 
// Allow preselecting monthlyfrequency if possible
if (
if( mw.util.getParamValue('monthly')
&& donationForm.noRecurringCountries.indexOf( donationForm.country ) === -1 ) {
&& mw.util.getParamValue( 'utm_medium' ) !== 'endowment'
$('#frequency_monthly').click();
&& mw.util.getParamValue( 'wmf_medium' ) !== 'endowment'
}
) {
if ( mw.util.getParamValue( 'frequency' ) ) {
donationForm.setFrequency( mw.util.getParamValue( 'frequency' ) );
} else if ( mw.util.getParamValue('monthly') && mw.util.getParamValue('monthly') !== '0' ) {
// old method with "monthly=" parameter
donationForm.setFrequency( 'monthly' );
} else {
donationForm.setFrequency( 'onetime' );
}
}
 
donationForm.initOptin();
 
try {
adjustHPC();
preSelect(); // Make sure to do this *after* other fiddling with values
donationForm.localizeErrors();
}
}
finally {
$('.ptffrb-monthly-pitch, .frb-monthly-pitch-thanks').appendTo('.amountfrequency-options');
$('.optin-optionsptf').insertAfterappendTo('.amount-options');
$('.optin-options').insertAfter('.amount-options');
$('.consider-amounts').show();
$('#actual.consider-formamounts').show();
$('#actual-form-loading').hideshow();
$('#actual-form-loading').hide();
}
}
 
});
 
});