MediaWiki:DonationForm mctest.js: Difference between revisions

Content deleted Content added
moved monthllyconvert js loading to common.js
add utility function donationForm.getLocale
 
(One intermediate revision by the same user not shown)
Line 1,048:
});
};
 
/**
* Block typing letters and symbols in given input. Used for Other amount inputs
*
* If we don't do this, Safari allows typing them and then chokes on submit
// * https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431
*
* @param {Element} inputElement The element to block typing on
*/
donationForm.otherInputControl = function( inputElement ) {
if ( inputElement ) {
amountOtherInputinputElement.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;
}
};
}
};
 
/**
* Make language and country into a standard javascript Intl locale identifier
*
* Currently only used in monthlyconvert, but this could be useful
*
* @param {string} language
* @param {string} country
* @return {string} locale identifier
*/
donationForm.getLocale = function( language, country ) {
if ( language === 'en-gb' ) {
language = 'en';
}
if ( language === 'es-419' ) {
language = 'es';
}
if ( language === 'pt-br' ) {
language = 'pt';
}
return language + '-' + country;
};
 
 
/* End form functions */
Line 1,061 ⟶ 1,109:
donationForm.country = mw.util.getParamValue('country');
 
// Block typing symbols in inputOther field, otherwise Safari allows them and then chokes
var amountOtherInput =donationForm.otherInputControl( document.getElementById('input_amount_other_box') );
// 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;
}
};
}
 
// Validate amount and update fee when selected/entered