MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
rm weird recoloring of other box |
No edit summary |
||
(48 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
* Any JavaScript here will be loaded for all users on every page load. |
* Any JavaScript here will be loaded for all users on every page load. |
||
**/ |
**/ |
||
function parseParams( url ) { |
|||
// Helper function to get querystring parameters as a JS object |
|||
// Located here as MediaWiki messes up the ampersand when included inline using rawHTML |
|||
// TODO: Replace with mw.Uri or mw.util.getParamValue() everywhere, and remove |
|||
var ret={}; |
|||
if ( url.indexOf( '?' ) === -1 ) { |
|||
return ret; |
|||
} |
|||
var s = url.split( '?' ).slice( 1 ).join(); |
|||
var t = s.split( '&' ); |
|||
for ( var i = 0; i < t.length; ++i ) { |
|||
var z = t[ i ].split( '=' ); |
|||
z.push( null ); |
|||
ret[ z[ 0 ] ] = z[ 1 ]; |
|||
} |
|||
return ret; |
|||
} |
|||
function getQuerystring( key ) { |
function getQuerystring( key ) { |
||
Line 28: | Line 9: | ||
var qs = regex.exec( window.location.search ); |
var qs = regex.exec( window.location.search ); |
||
return qs == null ? '' : qs[1]; |
return qs == null ? '' : qs[1]; |
||
} |
|||
function checkPaymentOutages() { |
|||
/* Check against the scheduled payment method outages |
|||
* in global variable "outages" (loaded cross-wiki from meta) |
|||
* and hide the relevant button for any which are ongoing. |
|||
*/ |
|||
// var outages = outages || []; // don't die if it hasn't loaded... |
|||
var now = new Date(); |
|||
for (var i = outages.length - 1; i >= 0; i--) { |
|||
if ( now > outages[i]['start'] ) { |
|||
if ( now < outages[i]['end'] ) { |
|||
if ( (typeof outages[i]['country'] === 'undefined') || (outages[i]['country'] == country) ) { |
|||
$('.paymentmethod-' + outages[i]['method']).hide(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
} |
||
Line 71: | Line 32: | ||
var radioAmountsData = { |
var radioAmountsData = { |
||
'USD' : { |
'USD' : { |
||
'default' : [ |
'default' : [ |
||
[ 0, [ 5, 10, 20, 25, 35, 50, 100 ] ], |
[ 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 ] ], |
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ], |
||
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ], |
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ], |
||
Line 84: | Line 47: | ||
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ] |
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ] |
||
], |
], |
||
' |
'low2016' : [ |
||
[ 0, [ |
[ 0, [ 3, 5, 10, 20, 30, 50, 100 ] ], |
||
[ 5, [ |
[ 5, [ 5, 10, 20, 35, 50, 100, 150 ] ], |
||
[ 10, [ |
[ 10, [ 10, 15, 20, 35, 50, 100, 150 ] ], |
||
[ 15, [ |
[ 15, [ 15, 20, 25, 35, 50, 100, 150 ] ], |
||
[ 20, [ 25, 35, 50, 75, 100, 150 |
[ 20, [ 20, 25, 35, 50, 75, 100, 150 ] ], |
||
[ 25, [ |
[ 25, [ 25, 35, 50, 75, 100, 150, 250 ] ], |
||
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ], |
[ 35, [ 25, 50, 75, 100, 200, 250, 300 ] ], |
||
[ 50, [ 25, 50, 75, 100, 200, 250, 300 ] ], |
|||
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ], |
[ 75, [ 25, 50, 75, 100, 200, 300, 500 ] ], |
||
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ], |
[ 100, [ 25, 50, 100, 150, 250, 500, 1000 ] ], |
||
Line 99: | Line 61: | ||
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2000 ] ], |
[ 500, [ 100, 250, 500, 750, 1000, 1500, 2000 ] ], |
||
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ] |
[ 1000, [ 500, 1000, 2000, 2500, 3000, 4000, 5000 ] ] |
||
], |
|||
'v3' : [ // Med ask for lowest # in string |
|||
[ 0, [ 5, 10, 20, 25, 35, 50, 100 ] ], |
|||
[ 10, [ 15, 20, 25, 35, 50, 100, 150 ] ], |
|||
[ 20, [ 25, 35, 50, 75, 100, 150, 250 ] ], |
|||
[ 35, [ 25, 40, 50, 100, 150, 200, 250 ] ], |
|||
[ 50, [ 35, 50, 75, 125, 200, 250, 300 ] ], |
|||
[ 75, [ 35, 50, 75, 100, 200, 300, 500 ] ], |
|||
[ 100, [ 50, 75, 100, 150, 250, 500, 1000 ] ], |
|||
[ 150, [ 100, 150, 200, 250, 350, 500, 1000 ] ], |
|||
[ 200, [ 150, 200, 250, 300, 400, 500, 1000 ] ], |
|||
[ 500, [ 250, 500, 750, 1000, 1500, 2000, 2500 ] ], |
|||
[ 1000, [ 1000, 2000, 2500, 3000, 3500, 4000, 5000 ] ] |
|||
] |
] |
||
}, |
}, |
||
'EUR' : [ |
|||
[ 0, [ 5, 10, 20, 25, 35, 50, 100 ] ], |
|||
[ 10, [ 10, 20, 25, 35, 50, 100, 150 ] ], |
|||
[ 20, [ 20, 25, 35, 50, 75, 100, 250 ] ], |
|||
[ 35, [ 20, 35, 50, 100, 150, 200, 250 ] ], |
|||
[ 50, [ 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 ] ] |
|||
], |
|||
'BRL' : [ |
'BRL' : [ |
||
[ 0, [ 15, 25, 50, 75, 100, 150, 300 ] ], |
[ 0, [ 15, 25, 50, 75, 100, 150, 300 ] ], |
||
Line 143: | Line 79: | ||
], |
], |
||
'JPY' : [ |
'JPY' : [ |
||
[ 0, [ |
[ 0, [ 500, 1000, 2000, 2500, 4000, 5000, 10000 ] ], |
||
[ 5, [ 1000, 1500, 2500, |
[ 5, [ 1000, 1500, 2500, 4000, 5000, 10000, 15000 ] ], |
||
[ 10, [ 1500, 2000, 3000, |
[ 10, [ 1500, 2000, 3000, 4000, 5000, 10000, 15000 ] ], |
||
[ 15, [ 2000, |
[ 15, [ 2000, 2500, 3500, 5000, 7500, 10000, 25000 ] ], |
||
[ 20, [ |
[ 20, [ 2500, 3500, 5000, 7500, 10000, 15000, 25000 ] ], |
||
[ 25, [ 4000, 5000, 7500, 10000 |
[ 25, [ 3000, 4000, 5000, 7500, 10000, 15000, 25000 ] ], |
||
[ 35, [ 5000, 7500, 10000, |
[ 35, [ 2500, 5000, 7500, 10000, 20000, 30000, 50000 ] ], |
||
[ 75, [ 5000, 7500, 10000, |
[ 75, [ 2500, 5000, 7500, 10000, 20000, 50000, 100000 ] ], |
||
[ 100, [ 5000, |
[ 100, [ 5000, 10000, 15000, 20000, 35000, 50000, 100000 ] ], |
||
[ 500, [ 10000, 25000, 50000, |
[ 500, [ 10000, 25000, 50000, 75000, 100000, 150000, 200000 ] ] |
||
], |
], |
||
'SEK' : [ |
'SEK' : [ |
||
Line 163: | Line 99: | ||
radioAmountsData.AUD = radioAmountsData.USD; |
radioAmountsData.AUD = radioAmountsData.USD; |
||
radioAmountsData.CAD = radioAmountsData.USD; |
radioAmountsData.CAD = radioAmountsData.USD; |
||
radioAmountsData.GBP = radioAmountsData.USD; |
radioAmountsData.GBP = radioAmountsData.USD; |
||
radioAmountsData.NZD = radioAmountsData.USD; |
radioAmountsData.NZD = radioAmountsData.USD; |
||
radioAmountsData.EUR = radioAmountsData.USD; |
|||
var appealAmountsData = { |
var appealAmountsData = { |
||
Line 177: | Line 114: | ||
[ 150, [ 75, 100, 200 ] ], |
[ 150, [ 75, 100, 200 ] ], |
||
[ 200, [ 100, 200, 300 ] ] |
[ 200, [ 100, 200, 300 ] ] |
||
], |
|||
'EUR' : [ |
|||
[ 0, [ 3, 5, 10 ] ], |
|||
[ 4, [ 5, 10, 20 ] ], |
|||
[ 7, [ 10, 20, 50 ] ], |
|||
[ 14, [ 15, 20, 50 ] ], |
|||
[ 20, [ 20, 50, 100 ] ], |
|||
[ 40, [ 30, 50, 100 ] ], |
|||
[ 68, [ 50, 100, 150 ] ] |
|||
], |
], |
||
'JPY' : [ |
'JPY' : [ |
||
Line 211: | Line 139: | ||
appealAmountsData.GBP = appealAmountsData.USD; |
appealAmountsData.GBP = appealAmountsData.USD; |
||
appealAmountsData.NZD = appealAmountsData.USD; |
appealAmountsData.NZD = appealAmountsData.USD; |
||
appealAmountsData.EUR = appealAmountsData.USD; |
|||
var formats = { |
var formats = { |
||
Line 305: | Line 234: | ||
} |
} |
||
function |
function preSelect() { |
||
/* Check for a 'preSelect' url parameter, and select that option. |
|||
// prefill other amount box if param provided |
|||
If there isn't an option, add it to the "Other" box and select that */ |
|||
var otherVal = mw.util.getParamValue( 'otherVal' ); |
|||
var preSelectAmount = mw.util.getParamValue('preSelect'); |
|||
if( isNaN( parseFloat( otherVal ) ) ) { |
|||
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); |
|||
} |
|||
} |
} |
||
otherVal = parseFloat( otherVal ); |
|||
$("#input_amount_other").attr( 'checked', true ); |
|||
$("#input_amount_other_box").val( otherVal ); |
|||
} |
} |
||
Line 320: | Line 254: | ||
document.getElementById("input_amount_other").checked = true; |
document.getElementById("input_amount_other").checked = true; |
||
box.value = ""; |
box.value = ""; |
||
} |
|||
function selectOther() { |
|||
document.getElementById("input_amount_other").checked = true; |
|||
} |
} |
||
function resetOther(box) { |
function resetOther(box) { |
||
box.value = "</html>{{int:donate_interface-other}}<html>"; |
box.value = "</html>{{int:donate_interface-other}}<html>"; |
||
} |
} |
||
Line 335: | Line 273: | ||
$(document).ready(function() { |
$(document).ready(function() { |
||
mw.loader.using( ['mediawiki.util'] ).done( function() { |
|||
// Disable submitting form with return key |
|||
$( 'form[name="paypalcontribution"]' ).bind( 'keypress', function(e) { |
|||
var code = ( e.keyCode ? e.keyCode : e.which ); |
|||
if ( code == 13 ) return false; |
|||
}); |
|||
// Block typing symbols in input field, otherwise Safari allows them and then chokes |
|||
if ( document.paypalcontribution ) { |
|||
// https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431 |
|||
document.paypalcontribution.utm_medium.value = mw.util.getParamValue( 'utm_medium' ); |
|||
document.paypalcontribution.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' ); |
|||
var amountOtherInput = document.getElementById('input_amount_other_box'); |
|||
document.paypalcontribution.utm_key.value = mw.util.getParamValue( 'utm_key' ); |
|||
if ( amountOtherInput ) { |
|||
document.paypalcontribution.referrer.value = document.referrer; |
|||
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 |
// Disable submitting form with Enter key |
||
$('form[name="paypalcontribution"]').on('keypress', function(e) { |
|||
$("#p-logo a").attr("href", "#"); |
|||
var code = ( e.keyCode ? e.keyCode : e.which ); |
|||
$("#p-logo a").attr("title", ""); |
|||
if ( code == 13 ) { |
|||
e.preventDefault(); |
|||
}; |
|||
}); |
|||
// But allow Enter on buttons |
|||
// Monthly |
|||
$('.payment-method-button').keyup(function(e) { |
|||
if( mw.util.getParamValue('monthly') ) { |
|||
if (event.keyCode === 13) { |
|||
$('#frequency_monthly').click(); |
|||
e.target.click(); |
|||
} |
|||
} |
|||
}); |
|||
if ( document.paypalcontribution ) { |
|||
$(".frequency-options label").click(function() { |
|||
document.paypalcontribution.utm_medium.value = mw.util.getParamValue( 'utm_medium' ); |
|||
$(".frequency-options label").removeClass("checked"); |
|||
document.paypalcontribution.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' ); |
|||
$(this).addClass("checked"); |
|||
document.paypalcontribution.utm_key.value = mw.util.getParamValue( 'utm_key' ); |
|||
}); |
|||
// Strip protocol to stop firewall throwing fits |
|||
$(".radiobuttons-cell label").click(function() { |
|||
document.paypalcontribution.referrer.value = document.referrer.replace(/https?:\/\//i, ""); |
|||
$(".radiobuttons-cell label").removeClass("checked"); |
|||
$(this).addClass("checked"); |
|||
// 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(); |
|||
} |
|||
} |
|||
// Disable logo link |
|||
$("#p-logo a").attr("href", "#"); |
|||
$("#p-logo a").attr("title", ""); |
|||
// This is 1 by default, make it 0 |
|||
$('#searchInput').attr('tabindex', 0); |
|||
$(".input_amount_other").click(function() { |
|||
$("#input_amount_other_box").focus(); |
|||
}); |
|||
// Allow preselecting monthly |
|||
if( mw.util.getParamValue('monthly') ) { |
|||
$('#frequency_monthly').click(); |
|||
} |
|||
try { |
|||
adjustHPC(); |
|||
preSelect(); // Make sure to do this *after* other fiddling with values |
|||
} |
|||
finally { |
|||
$('.consider-amounts').show(); |
|||
$('#actual-form').show(); |
|||
$('#actual-form-loading').hide(); |
|||
} |
|||
$(".input_amount_other").click(function() { |
|||
$("#input_amount_other_box").focus(); |
|||
}); |
}); |
||
/** |
|||
// hide frequency options in India, where we can only handle one-time donations |
|||
* Code for fundraising Thank You pages |
|||
if (document.paypalcontribution.country.value === 'IN') { |
|||
* e.g. https://wikimediafoundation.org/wiki/Thank_You/en |
|||
$("#frequency_onetime").attr('checked', true); |
|||
*/ |
|||
$(".frequency-options").hide(); |
|||
if ( mw.config.get('wgTitle').substring(0,9) === 'Thank You' ) { |
|||
$("#cancel-monthly").hide(); |
|||
} |
|||
mw.loader.using( 'mediawiki.util', function() { |
|||
adjustHPC(); |
|||
adjustOtherVal(); |
|||
var paymentMethod = mw.util.getParamValue('payment_method'), |
|||
$('.consider-amounts').show(); |
|||
country = mw.util.getParamValue('country'); |
|||
$('#actual-form').show(); |
|||
$('#actual-form-loading').hide(); |
|||
if ( paymentMethod === 'bt' ) { |
|||
document.getElementById('ty-banktransfer').style.display = 'block'; |
|||
} |
|||
if ( paymentMethod === 'bitcoin' ) { |
|||
document.getElementById('ty-bitcoin').style.display = 'block'; |
|||
} |
|||
if ( paymentMethod === 'bpay' ) { |
|||
document.getElementById('ty-bpay').style.display = 'block'; |
|||
} |
|||
if ( country === 'US' || country === 'CA' ) { |
|||
document.getElementById('ty-store').style.display = 'block'; |
|||
} |
|||
// Load list of payment outages from meta, and hide any which are current |
|||
$.getScript('//meta.wikimedia.org/w/index.php?' + $.param( { title:'MediaWiki:FR2013/Resources/PaymentOutages.js', action:'raw', ctype:'text/javascript' } ), |
|||
function() { |
|||
setTimeout(checkPaymentOutages(), 250); // allow time for script to have _executed_ (not just loaded) |
|||
}); |
}); |
||
} |
|||
}); |
|||
$(document).ready(function() { |
|||
/* HACK to run certain inline scripts when document ready (e.g. so jquery is avaliable) |
|||
TODO: Make suitable for multiple scripts. Or figure out a better way to do this. |
|||
*/ |
|||
if ( typeof inlineScriptWhenReady !== 'undefined') { |
|||
inlineScriptWhenReady(); |
|||
} |
|||
}); |
}); |
Revision as of 10:31, 16 May 2018
/**
* Any JavaScript here will be loaded for all users on every page load.
**/
function getQuerystring( key ) {
// TODO: Replace with mw.util.getParamValue() everywhere, and remove
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 ] ]
],
'low2016' : [
[ 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, [ 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 ] ]
]
},
'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);
}
}
}
/* Form functions */
function clearOther(box) {
document.getElementById("input_amount_other").checked = true;
box.value = "";
}
function selectOther() {
document.getElementById("input_amount_other").checked = true;
}
function resetOther(box) {
box.value = "</html>{{int:donate_interface-other}}<html>";
}
function selectAmount() {
$('#input_amount_other_box').val('');
$('input[name="amountGiven"]').val('');
}
/* 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();
}
}
// Disable logo link
$("#p-logo a").attr("href", "#");
$("#p-logo a").attr("title", "");
// This is 1 by default, make it 0
$('#searchInput').attr('tabindex', 0);
$(".input_amount_other").click(function() {
$("#input_amount_other_box").focus();
});
// Allow preselecting monthly
if( mw.util.getParamValue('monthly') ) {
$('#frequency_monthly').click();
}
try {
adjustHPC();
preSelect(); // Make sure to do this *after* other fiddling with values
}
finally {
$('.consider-amounts').show();
$('#actual-form').show();
$('#actual-form-loading').hide();
}
});
/**
* Code for fundraising Thank You pages
* e.g. https://wikimediafoundation.org/wiki/Thank_You/en
*/
if ( mw.config.get('wgTitle').substring(0,9) === 'Thank You' ) {
mw.loader.using( 'mediawiki.util', function() {
var paymentMethod = mw.util.getParamValue('payment_method'),
country = mw.util.getParamValue('country');
if ( paymentMethod === 'bt' ) {
document.getElementById('ty-banktransfer').style.display = 'block';
}
if ( paymentMethod === 'bitcoin' ) {
document.getElementById('ty-bitcoin').style.display = 'block';
}
if ( paymentMethod === 'bpay' ) {
document.getElementById('ty-bpay').style.display = 'block';
}
if ( country === 'US' || country === 'CA' ) {
document.getElementById('ty-store').style.display = 'block';
}
});
}
});
$(document).ready(function() {
/* HACK to run certain inline scripts when document ready (e.g. so jquery is avaliable)
TODO: Make suitable for multiple scripts. Or figure out a better way to do this.
*/
if ( typeof inlineScriptWhenReady !== 'undefined') {
inlineScriptWhenReady();
}
});