MediaWiki:DonationForm mctest.js: Difference between revisions
Content deleted Content added
split finalStep from redirectPayments, so we can call it back from monthlyconvert if needed |
add utility function donationForm.getLocale |
||
(3 intermediate revisions by the same user not shown) | |||
Line 711:
params.country = donationForm.country;
params.uselang = mw.config.get('wgPageContentLanguage'); // see T281285 for why not wgUserLanguage
if ( params.uselang === 'pt' && params.country === 'BR' ) {
params.uselang = 'pt-br';
Line 750:
}
// Check for monthly convert. TODO: make it possible to test JS variants
donationForm.finalStep( params );▼
if ( mw.util.getParamValue('monthlyconvert') ) {▼
mc.main( params, donationForm.finalStep );
} else {▼
▲ donationForm.finalStep( params );
▲ }
} else {
Line 787 ⟶ 792:
window.location.href = uri.toString();
}
};
/**
Line 881 ⟶ 886:
* Does some awful regex stuff to rm symbols and turn the string into a number
* Remember some locales flip . & , for decimal point/thousands separator
*
* @param {string} value Value of "Other" field
* @return {float} Float with amount, or 0 if NaN
Line 892 ⟶ 897:
value = value.replace(/[\$£€¥,.]/g, '');
value = value.replace(/:/, '.');
amount = parseFloat( value );
if ( isNaN( amount ) ) {
Line 1,043 ⟶ 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
*
* @param {Element} inputElement The element to block typing on
*/
donationForm.otherInputControl = function( inputElement ) {
if ( inputElement ) {
};▼
▲ }
};
/**
* 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,051 ⟶ 1,104:
var form = document.forms['donateForm'];
▲ if ( mw.util.getParamValue('monthlyconvert') ) {
▲ }
// These get used in quite a few places
Line 1,062 ⟶ 1,109:
donationForm.country = mw.util.getParamValue('country');
// Block typing symbols in
▲ // https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431
▲ var amountOtherInput = document.getElementById('input_amount_other_box');
▲ 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
|