MediaWiki:DonationForm.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
try merging in Template:2012FR/Form-section/Processing/Default again |
add localizeErrors method, and put minimums here for now |
||
Line 2: | Line 2: | ||
* TODO: lots of cleanup |
* TODO: lots of cleanup |
||
*/ |
*/ |
||
var donationForm = {}; |
|||
donationForm.minimums = { |
|||
/* From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php */ |
|||
'ADF' : 5.65, |
|||
'ADP' : 143, |
|||
'AED' : 3.67, |
|||
'AFA' : 73, |
|||
'AFN' : 73, |
|||
'ALL' : 109, |
|||
'AMD' : 477, |
|||
'ANG' : 1.79, |
|||
'AOA' : 278, |
|||
'AON' : 278, |
|||
'ATS' : 12, |
|||
'AUD' : 1.39, |
|||
'AWG' : 1.78, |
|||
'AZM' : 8486, |
|||
'AZN' : 1.7, |
|||
'BAM' : 1.69, |
|||
'BBD' : 2, |
|||
'BDT' : 83, |
|||
'BEF' : 35, |
|||
'BGL' : 1.69, |
|||
'BGN' : 1.69, |
|||
'BHD' : 0.38, |
|||
'BIF' : 1748, |
|||
'BMD' : 1, |
|||
'BND' : 1.38, |
|||
'BOB' : 6.8, |
|||
'BRL' : 4.15, |
|||
'BSD' : 1, |
|||
'BTN' : 72, |
|||
'BWP' : 11, |
|||
'BYR' : 21035, |
|||
'BZD' : 1.98, |
|||
'CAD' : 1.32, |
|||
'CDF' : 1573, |
|||
'CHF' : 0.98, |
|||
'CNY' : 6.83, |
|||
'CRC' : 572, |
|||
'CUC' : 1, |
|||
'CUP' : 25, |
|||
'CVE' : 95, |
|||
'CYP' : 0.51, |
|||
'CZK' : 22, |
|||
'DEM' : 1.69, |
|||
'DJF' : 178, |
|||
'DKK' : 6.42, |
|||
'DOP' : 50, |
|||
'DZD' : 118, |
|||
'ECS' : 24094, |
|||
'EEK' : 13, |
|||
'EGP' : 18, |
|||
'ESP' : 143, |
|||
'ETB' : 27, |
|||
'EUR' : 0.87, |
|||
'FIM' : 5.12, |
|||
'FJD' : 2.1, |
|||
'FKP' : 0.78, |
|||
'FRF' : 5.65, |
|||
'GBP' : 0.78, |
|||
'GEL' : 2.52, |
|||
'GHC' : 47467, |
|||
'GHS' : 4.75, |
|||
'GIP' : 0.78, |
|||
'GMD' : 48, |
|||
'GNF' : 8983, |
|||
'GRD' : 294, |
|||
'GTQ' : 7.5, |
|||
'GYD' : 204, |
|||
'HKD' : 7.85, |
|||
'HNL' : 24, |
|||
'HRK' : 6.4, |
|||
'HTG' : 68, |
|||
'HUF' : 282, |
|||
'IDR' : 14966, |
|||
'IEP' : 0.68, |
|||
'ILS' : 3.61, |
|||
'INR' : 72, |
|||
'IQD' : 1178, |
|||
'IRR' : 42000, |
|||
'ISK' : 109, |
|||
'ITL' : 1669, |
|||
'JMD' : 136, |
|||
'JOD' : 0.71, |
|||
'JPY' : 112, |
|||
'KES' : 100, |
|||
'KGS' : 69, |
|||
'KHR' : 4025, |
|||
'KMF' : 424, |
|||
'KPW' : 135, |
|||
'KRW' : 1120, |
|||
'KWD' : 0.31, |
|||
'KYD' : 0.84, |
|||
'KZT' : 369, |
|||
'LAK' : 8393, |
|||
'LBP' : 1508, |
|||
'LKR' : 162, |
|||
'LRD' : 154, |
|||
'LSL' : 15, |
|||
'LTL' : 2.98, |
|||
'LUF' : 35, |
|||
'LVL' : 0.61, |
|||
'LYD' : 1.37, |
|||
'MAD' : 9.39, |
|||
'MDL' : 17, |
|||
'MGA' : 3311, |
|||
'MGF' : 9150, |
|||
'MKD' : 53, |
|||
'MMK' : 1529, |
|||
'MNT' : 2460, |
|||
'MOP' : 8.08, |
|||
'MRO' : 357, |
|||
'MTL' : 0.37, |
|||
'MUR' : 33, |
|||
'MVR' : 15, |
|||
'MWK' : 717, |
|||
'MYR' : 4.15, |
|||
'MZM' : 59754, |
|||
'MZN' : 60, |
|||
'NAD' : 15, |
|||
'NGN' : 359, |
|||
'NIO' : 32, |
|||
'NLG' : 1.9, |
|||
'NOK' : 8.4, |
|||
'NPR' : 114, |
|||
'NZD' : 1.52, |
|||
'OMR' : 0.39, |
|||
'PAB' : 1, |
|||
'PEN' : 3.3, |
|||
'PGK' : 3.26, |
|||
'PHP' : 54, |
|||
'PKR' : 123, |
|||
'PLN' : 3.72, |
|||
'PTE' : 173, |
|||
'PYG' : 5763, |
|||
'QAR' : 3.57, |
|||
'ROL' : 39889, |
|||
'RON' : 3.99, |
|||
'RSD' : 101, |
|||
'RUB' : 68, |
|||
'RWF' : 862, |
|||
'SAR' : 3.75, |
|||
'SBD' : 7.6, |
|||
'SCR' : 13, |
|||
'SDD' : 1795, |
|||
'SDG' : 18, |
|||
'SDP' : 2261, |
|||
'SEK' : 9.08, |
|||
'SGD' : 1.38, |
|||
'SHP' : 0.78, |
|||
'SIT' : 207, |
|||
'SKK' : 26, |
|||
'SLL' : 8430, |
|||
'SOS' : 542, |
|||
'SRD' : 7.41, |
|||
'SRG' : 7408, |
|||
'STD' : 21070, |
|||
'SVC' : 8.75, |
|||
'SYP' : 215, |
|||
'SZL' : 15, |
|||
'THB' : 33, |
|||
'TJS' : 9.36, |
|||
'TMM' : 17050, |
|||
'TMT' : 3.41, |
|||
'TND' : 2.76, |
|||
'TOP' : 2.29, |
|||
'TRL' : 6629223, |
|||
'TRY' : 6.63, |
|||
'TTD' : 6.64, |
|||
'TWD' : 31, |
|||
'TZS' : 2281, |
|||
'UAH' : 28, |
|||
'UGX' : 3749, |
|||
'USD' : 1, |
|||
'UZS' : 7780, |
|||
'VEB' : 6050841136, |
|||
'VEF' : 6050841, |
|||
'VND' : 23150, |
|||
'VUV' : 111, |
|||
'WST' : 2.64, |
|||
'XAF' : 565, |
|||
'XCD' : 2.7, |
|||
'XOF' : 565, |
|||
'XPF' : 103, |
|||
'YER' : 250, |
|||
'YUN' : 101, |
|||
'ZAR' : 15, |
|||
'ZMK' : 5176, |
|||
'ZWD' : 373, |
|||
/* Astropay currencies have higher minimums - 1.50 USD */ |
|||
'ARS' : 58.5, |
|||
'BRL' : 6.23, |
|||
'CLP' : 1035, |
|||
'COP' : 4640, |
|||
'MXN' : 28.5 |
|||
}; |
|||
/* Localize the amount errors. Call when initialising form. */ |
|||
donationForm.localizeErrors = function() { |
|||
var currency = document.paypalcontribution.currency_code.value; |
|||
var minAmount = donationForm.minimums[ currency ]; |
|||
$('.lp-error-smallamount').text( function( index, oldText ) { |
|||
return oldText.replace( '$1', minAmount + ' ' + currency ); |
|||
}); |
|||
$('.lp-error-bigamount').text( function( index, oldText ) { |
|||
return oldText.replace( '$1', 10000 * minAmount ) |
|||
.replace( '$2', currency ) |
|||
.replace( '$3', 'benefactors@wikimedia.org' ); |
|||
}); |
|||
}; |
|||
function getQuerystring( key ) { |
function getQuerystring( key ) { |
||
Line 341: | Line 556: | ||
/* -- Moved from Template:2012FR/Form-section/Processing/Default -- */ |
/* -- Moved from Template:2012FR/Form-section/Processing/Default -- */ |
||
var donationForm = {}; |
|||
donationForm.redirectPayment = function(paymentMethod, paymentSubMethod, skipValidation) { |
donationForm.redirectPayment = function(paymentMethod, paymentSubMethod, skipValidation) { |
||
Line 548: | Line 761: | ||
adjustHPC(); |
adjustHPC(); |
||
preSelect(); // Make sure to do this *after* other fiddling with values |
preSelect(); // Make sure to do this *after* other fiddling with values |
||
donationForm.localizeErrors() |
|||
} |
} |
||
finally { |
finally { |
Revision as of 16:42, 28 March 2019
/** MediaWiki:DonationForm.js - loaded on all donation forms
* TODO: lots of cleanup
*/
var donationForm = {};
donationForm.minimums = {
/* From https://github.com/wikimedia/wikimedia-fundraising-SmashPig/blob/master/PaymentData/ReferenceData/CurrencyRates.php */
'ADF' : 5.65,
'ADP' : 143,
'AED' : 3.67,
'AFA' : 73,
'AFN' : 73,
'ALL' : 109,
'AMD' : 477,
'ANG' : 1.79,
'AOA' : 278,
'AON' : 278,
'ATS' : 12,
'AUD' : 1.39,
'AWG' : 1.78,
'AZM' : 8486,
'AZN' : 1.7,
'BAM' : 1.69,
'BBD' : 2,
'BDT' : 83,
'BEF' : 35,
'BGL' : 1.69,
'BGN' : 1.69,
'BHD' : 0.38,
'BIF' : 1748,
'BMD' : 1,
'BND' : 1.38,
'BOB' : 6.8,
'BRL' : 4.15,
'BSD' : 1,
'BTN' : 72,
'BWP' : 11,
'BYR' : 21035,
'BZD' : 1.98,
'CAD' : 1.32,
'CDF' : 1573,
'CHF' : 0.98,
'CNY' : 6.83,
'CRC' : 572,
'CUC' : 1,
'CUP' : 25,
'CVE' : 95,
'CYP' : 0.51,
'CZK' : 22,
'DEM' : 1.69,
'DJF' : 178,
'DKK' : 6.42,
'DOP' : 50,
'DZD' : 118,
'ECS' : 24094,
'EEK' : 13,
'EGP' : 18,
'ESP' : 143,
'ETB' : 27,
'EUR' : 0.87,
'FIM' : 5.12,
'FJD' : 2.1,
'FKP' : 0.78,
'FRF' : 5.65,
'GBP' : 0.78,
'GEL' : 2.52,
'GHC' : 47467,
'GHS' : 4.75,
'GIP' : 0.78,
'GMD' : 48,
'GNF' : 8983,
'GRD' : 294,
'GTQ' : 7.5,
'GYD' : 204,
'HKD' : 7.85,
'HNL' : 24,
'HRK' : 6.4,
'HTG' : 68,
'HUF' : 282,
'IDR' : 14966,
'IEP' : 0.68,
'ILS' : 3.61,
'INR' : 72,
'IQD' : 1178,
'IRR' : 42000,
'ISK' : 109,
'ITL' : 1669,
'JMD' : 136,
'JOD' : 0.71,
'JPY' : 112,
'KES' : 100,
'KGS' : 69,
'KHR' : 4025,
'KMF' : 424,
'KPW' : 135,
'KRW' : 1120,
'KWD' : 0.31,
'KYD' : 0.84,
'KZT' : 369,
'LAK' : 8393,
'LBP' : 1508,
'LKR' : 162,
'LRD' : 154,
'LSL' : 15,
'LTL' : 2.98,
'LUF' : 35,
'LVL' : 0.61,
'LYD' : 1.37,
'MAD' : 9.39,
'MDL' : 17,
'MGA' : 3311,
'MGF' : 9150,
'MKD' : 53,
'MMK' : 1529,
'MNT' : 2460,
'MOP' : 8.08,
'MRO' : 357,
'MTL' : 0.37,
'MUR' : 33,
'MVR' : 15,
'MWK' : 717,
'MYR' : 4.15,
'MZM' : 59754,
'MZN' : 60,
'NAD' : 15,
'NGN' : 359,
'NIO' : 32,
'NLG' : 1.9,
'NOK' : 8.4,
'NPR' : 114,
'NZD' : 1.52,
'OMR' : 0.39,
'PAB' : 1,
'PEN' : 3.3,
'PGK' : 3.26,
'PHP' : 54,
'PKR' : 123,
'PLN' : 3.72,
'PTE' : 173,
'PYG' : 5763,
'QAR' : 3.57,
'ROL' : 39889,
'RON' : 3.99,
'RSD' : 101,
'RUB' : 68,
'RWF' : 862,
'SAR' : 3.75,
'SBD' : 7.6,
'SCR' : 13,
'SDD' : 1795,
'SDG' : 18,
'SDP' : 2261,
'SEK' : 9.08,
'SGD' : 1.38,
'SHP' : 0.78,
'SIT' : 207,
'SKK' : 26,
'SLL' : 8430,
'SOS' : 542,
'SRD' : 7.41,
'SRG' : 7408,
'STD' : 21070,
'SVC' : 8.75,
'SYP' : 215,
'SZL' : 15,
'THB' : 33,
'TJS' : 9.36,
'TMM' : 17050,
'TMT' : 3.41,
'TND' : 2.76,
'TOP' : 2.29,
'TRL' : 6629223,
'TRY' : 6.63,
'TTD' : 6.64,
'TWD' : 31,
'TZS' : 2281,
'UAH' : 28,
'UGX' : 3749,
'USD' : 1,
'UZS' : 7780,
'VEB' : 6050841136,
'VEF' : 6050841,
'VND' : 23150,
'VUV' : 111,
'WST' : 2.64,
'XAF' : 565,
'XCD' : 2.7,
'XOF' : 565,
'XPF' : 103,
'YER' : 250,
'YUN' : 101,
'ZAR' : 15,
'ZMK' : 5176,
'ZWD' : 373,
/* Astropay currencies have higher minimums - 1.50 USD */
'ARS' : 58.5,
'BRL' : 6.23,
'CLP' : 1035,
'COP' : 4640,
'MXN' : 28.5
};
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
var currency = document.paypalcontribution.currency_code.value;
var minAmount = donationForm.minimums[ currency ];
$('.lp-error-smallamount').text( function( index, oldText ) {
return oldText.replace( '$1', minAmount + ' ' + currency );
});
$('.lp-error-bigamount').text( function( index, oldText ) {
return oldText.replace( '$1', 10000 * minAmount )
.replace( '$2', currency )
.replace( '$3', 'benefactors@wikimedia.org' );
});
};
function getQuerystring( key ) {
// TODO: Replace with mw.util.getParamValue() everywhere, and remove
// note might be relying on different behaviour when parameter not present
key = key.replace( /[\[]/, '\\\[' ).replace( /[\]]/, '\\\]' );
var regex = new RegExp( '[\\?&]' + key + '=([a-zA-Z0-9\.\_\-]*)' );
var qs = regex.exec( window.location.search );
return qs === null ? '' : qs[1];
}
function adjustHPC() {
/* Adjust amounts based on highest previous contribution (hpc)
or most recent contribution (mrc) parameter. Used for emails.
TODO: split data out? */
// 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;
}
}
var hpcSet = mw.util.getParamValue('hpcSet');
var currency = $("input[name='currency_code']").val();
var language = mw.config.get('wgUserLanguage');
var radioAmountsData = {
'USD' : {
'default' : [
[ 0, [ 5, 10, 20, 25, 35, 50, 100 ] ],
[ 5, [ 10, 15, 20, 35, 50, 100, 150 ] ],
[ 10, [ 15, 20, 25, 35, 50, 100, 150 ] ],
[ 15, [ 20, 25, 35, 50, 75, 100, 250 ] ],
[ 20, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 25, [ 30, 40, 50, 75, 100, 150, 250 ] ],
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ],
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ],
[ 150, [ 50, 100, 150, 200, 350, 500, 1000 ] ],
[ 200, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2000 ] ],
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ]
],
'LTLA' : [
[ 0, [ 3, 10, 15, 20, 35, 50, 100 ] ],
[ 5, [ 5, 10, 20, 35, 50, 100, 150 ] ],
[ 10, [ 10, 20, 35, 50, 75, 100, 150 ] ],
[ 15, [ 15, 25, 35, 50, 75, 100, 250 ] ],
[ 20, [ 20, 30, 50, 75, 100, 150, 250 ] ],
[ 25, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ],
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ],
[ 150, [ 50, 100, 150, 200, 350, 500, 1000 ] ],
[ 200, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2000 ] ],
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ]
],
'midtier2018' : [
[ 0, [ 3, 5, 10, 20, 30, 50, 100 ] ],
[ 5, [ 5, 10, 20, 35, 50, 100, 150 ] ],
[ 10, [ 10, 15, 20, 35, 50, 100, 150 ] ],
[ 15, [ 15, 20, 25, 35, 50, 100, 150 ] ],
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ],
[ 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 ] ]
],
'LT2018' : [
[ 0, [ 5, 10, 20.18, 25, 35, 50, 100 ] ],
[ 5, [ 10, 15, 20.18, 35, 50, 100, 150 ] ],
[ 10, [ 15, 20.18, 25, 35, 50, 100, 150 ] ],
[ 15, [ 20.18, 25, 35, 50, 75, 100, 250 ] ],
[ 20, [ 25, 35, 50, 75, 100, 150, 250 ] ],
[ 25, [ 30, 40, 50, 75, 100, 150, 250 ] ],
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ],
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ],
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ],
[ 150, [ 50, 100, 150, 200, 350, 500, 1000 ] ],
[ 200, [ 100, 150, 200, 300, 400, 500, 1000 ] ],
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2018 ] ],
[ 1000, [ 500, 1000, 2018, 2500, 3000, 4000, 5000 ] ]
]
},
'BRL' : [
[ 0, [ 15, 25, 50, 75, 100, 150, 300 ] ],
[ 5, [ 25, 35, 50, 75, 100, 200, 300 ] ],
[ 10, [ 30, 50, 75, 100, 150, 300, 500 ] ],
[ 15, [ 50, 75, 100, 150, 225, 300, 500 ] ],
[ 20, [ 50, 100, 150, 225, 300, 400, 500 ] ],
[ 25, [ 75, 125, 200, 250, 300, 400, 500 ] ],
[ 35, [ 100, 150, 225, 300, 500, 750, 1000 ] ],
[ 75, [ 100, 150, 225, 300, 500, 1000, 1500 ] ],
[ 100, [ 100, 150, 300, 500, 1000, 1500, 3000 ] ],
[ 150, [ 250, 500, 750, 1000, 1500, 3000, 5000 ] ],
[ 200, [ 500, 1000, 2000, 3000, 4000, 5000, 10000 ] ],
[ 500, [ 1000, 2500, 5000, 7500, 10000, 12500, 15000 ] ],
[ 1000, [ 1000, 2500, 5000, 7500, 10000, 12500, 15000 ] ]
],
'JPY' : [
[ 0, [ 500, 1000, 2000, 2500, 4000, 5000, 10000 ] ],
[ 5, [ 1000, 1500, 2500, 4000, 5000, 10000, 15000 ] ],
[ 10, [ 1500, 2000, 3000, 4000, 5000, 10000, 15000 ] ],
[ 15, [ 2000, 2500, 3500, 5000, 7500, 10000, 25000 ] ],
[ 20, [ 2500, 3500, 5000, 7500, 10000, 15000, 25000 ] ],
[ 25, [ 3000, 4000, 5000, 7500, 10000, 15000, 25000 ] ],
[ 35, [ 2500, 5000, 7500, 10000, 20000, 30000, 50000 ] ],
[ 75, [ 2500, 5000, 7500, 10000, 20000, 50000, 100000 ] ],
[ 100, [ 5000, 10000, 15000, 20000, 35000, 50000, 100000 ] ],
[ 500, [ 10000, 25000, 50000, 75000, 100000, 150000, 200000 ] ]
],
'SEK' : [
[ 0, [ 20, 50, 100, 200, 300, 500, 1000 ] ],
[ 3, [ 30, 50, 100, 200, 300, 500, 1000 ] ],
[ 5, [ 50, 100, 150, 200, 300, 500, 1000 ] ],
[ 23, [ 50, 100, 200, 300, 500, 750, 1000 ] ]
]
};
radioAmountsData.AUD = radioAmountsData.USD;
radioAmountsData.CAD = radioAmountsData.USD;
radioAmountsData.GBP = radioAmountsData.USD;
radioAmountsData.NZD = radioAmountsData.USD;
radioAmountsData.EUR = radioAmountsData.USD;
var appealAmountsData = {
'USD' : [
[ 0, [ 5, 10, 20 ] ],
[ 10, [ 10, 20, 50 ] ],
[ 20, [ 20, 30, 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 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 = formats[currency][language] || formats[currency]["default"] || formats[currency] || '\t';
// Radio button amounts
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( 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 = mw.util.getParamValue('preSelect');
if ( preSelectAmount > 0 ) {
$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);
}
}
}
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' : 'CBvma', // Adyen
'IT' : 'vmaj',
'LU' : 'vmaj',
'LV' : 'vma',
'NL' : 'vmaj',
'PT' : 'vmaj',
'SK' : 'vmaj',
// Others
'DK' : 'vma',
'HU' : 'vma',
'IL' : 'vmad', // Adyen
'JP' : 'vmaj',
'MY' : 'vmaj',
'NO' : 'vma',
'PL' : 'vma',
'RO' : 'vma',
'SE' : 'vma',
'UA' : 'vma', // Adyen
'ZA' : 'vm'
};
if ( cardTypes[country] ) {
$('.paymentmethod-cc').addClass('cctypes-' + cardTypes[country] );
}
}
/* 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('');
$('input[name="amountGiven"]').val('');
}
/* -- Moved from Template:2012FR/Form-section/Processing/Default -- */
donationForm.redirectPayment = function(paymentMethod, paymentSubMethod, skipValidation) {
var form = document.paypalcontribution; // we should really change this some day
if ( skipValidation || validateForm(form) ) {
if (typeof paymentSubMethod == 'undefined') {
paymentSubMethod = '';
}
var paymentsURL = 'https://payments.wikimedia.org/index.php/Special:GatewayFormChooser';
form.action = paymentsURL;
if (typeof paymentSubMethod == 'undefined') {
paymentSubMethod = '';
}
// WorldPay override for cc
if( paymentMethod === 'cc-wp' ) {
paymentMethod = 'cc';
form.payment_method.value = 'cc';
form.gateway.value = 'worldpay';
form.ffname.value = 'worldpay';
}
// Adyen override for cc
if( paymentMethod === 'cc-adyen' ) {
paymentMethod = 'cc';
form.payment_method.value = 'cc';
form.gateway.value = 'adyen';
form.ffname.value = 'adyen';
}
/* Temporary redirect variant for 3DS issues - https://phabricator.wikimedia.org/T219445 */
var country = form.country.value;
if ( paymentMethod === 'cc' ) {
if ( country === 'NO' || country === 'SE' || country === 'PL' ) {
form.variant.value = 'redirect';
}
}
var frequency = $("input[name='frequency']:checked").val();
if( frequency !== 'monthly' ){
frequency = 'onetime';
form.recurring.value = 'false';
} else {
form.recurring.value = 'true';
}
form.payment_method.value = paymentMethod;
form.payment_submethod.value = paymentSubMethod;
donationForm.addAnalytics();
var full_dotted_payment_method = paymentMethod;
if ( form.recurring.value == 'true' ) {
full_dotted_payment_method = 'r' + full_dotted_payment_method;
}
if ( paymentSubMethod ) {
full_dotted_payment_method = form.payment_method.value + '.' + paymentSubMethod;
}
form.utm_source.value += '.' + full_dotted_payment_method;
form.method = "GET";
form.submit();
}
return false; // don't submit if called by a button
};
donationForm.addAnalytics = function() {
// stuffs parameters into utm_source to make them available for analytics
// TODO: replace getQueryString with mw.util.getParamValue()
var form = document.paypalcontribution;
form.utm_source.value = getQuerystring( 'utm_source' ) + '.';
if(getQuerystring( 'template' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'template' ).replace("Lp-layout-","") + '~';
}
if(getQuerystring( 'appeal-template' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'appeal-template' ).replace("Appeal-template-","") + '~';
}
if(getQuerystring( 'appeal' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'appeal' ).replace("Appeal-","") + '~';
}
if(getQuerystring( 'form-template' ) == '') {
form.utm_source.value += 'default' + '~';
} else {
form.utm_source.value += getQuerystring( 'form-template' ).replace("Form-template-","") + '~';
}
if(getQuerystring( 'form-countryspecific' ) == '') {
form.utm_source.value += 'control';
} else {
form.utm_source.value += getQuerystring( 'form-countryspecific' ).replace("Form-countryspecific-","");
}
form.utm_campaign.value = getQuerystring( 'utm_campaign' );
};
donationForm.toggleMonthly = function(monthly) {
if (monthly) {
$('#form-wrapper').addClass('form-monthly');
} else {
$('#form-wrapper').removeClass('form-monthly');
}
};
/* End form functions */
$(document).ready(function() {
mw.loader.using( ['mediawiki.util'] ).done( function() {
// Block typing symbols in input field, otherwise Safari allows them and then chokes
// https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431
var amountOtherInput = document.getElementById('input_amount_other_box');
if ( amountOtherInput ) {
amountOtherInput.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;
}
};
}
// Disable submitting form with Enter key
$('form[name="paypalcontribution"]').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 ( document.paypalcontribution ) {
document.paypalcontribution.utm_medium.value = mw.util.getParamValue( 'utm_medium' );
document.paypalcontribution.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' );
document.paypalcontribution.utm_key.value = mw.util.getParamValue( 'utm_key' );
// Strip protocol to stop firewall throwing fits
document.paypalcontribution.referrer.value = document.referrer.replace(/https?:\/\//i, "");
// hide frequency options in India, where we can only handle one-time donations
if (document.paypalcontribution.country.value === 'IN') {
$("#frequency_onetime").prop('checked', true);
$(".frequency-options").hide();
$("#cancel-monthly").hide();
}
addCardTypesClass(document.paypalcontribution.country.value);
}
// Links open in new tab
$('.links-in-new-tab a').attr('target', '_blank');
// Disable logo link
$("#p-logo a").attr("href", "#");
$("#p-logo a").attr("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 monthly
if( mw.util.getParamValue('monthly') ) {
$('#frequency_monthly').click();
}
// If the optin section has some javascript to run, do that
if ( typeof initOptin === 'function' ) {
initOptin();
}
try {
adjustHPC();
preSelect(); // Make sure to do this *after* other fiddling with values
donationForm.localizeErrors()
}
finally {
$('.optin-options').insertAfter('.amount-options');
$('.consider-amounts').show();
$('#actual-form').show();
$('#actual-form-loading').hide();
}
});
});