MediaWiki:DonationForm.js: Difference between revisions

Content deleted Content added
Load monthly convert JS if needed
split out parseOtherAmount function so we can re-use it for monthlyconvert other amount
Line 270:
var language = mw.config.get('wgPageContentLanguage');
 
// If changing, please update https://docs.google.com/spreadsheets/d/1e02TsZ_bKDAS1BMVBCdyo9D7RGln_wCGnkg7IF5kU5s/edit
var radioAmountsData = {
'USD' : {
Line 848:
/* Return amount selected or input */
donationForm.getAmount = function() {
var form = document.forms['donateForm'];,
var amount = null;
donationForm.extraData.otherAmt = 0;
 
Line 856:
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 ) {
if ( form.input_amount_other_box.value !== '' ) {
var otherAmountamount = donationForm.parseOtherAmount( form.input_amount_other_box.value );
otherAmount = otherAmount.replace(/[,.](\d)$/, '\:$10');
otherAmount = otherAmount.replace(/[,.](\d)(\d)$/, '\:$1$2');
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
amount = otherAmount;
donationForm.extraData.otherAmt = 1;
}
 
amount =return parseFloat(amount);
 
};
if ( isNaN(amount) ) {
 
/**
* Parse Other field value into amount
*
* 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
*/
donationForm.parseOtherAmount = function( value ) {
var amount = otherAmount;
 
otherAmountvalue = otherAmountvalue.replace(/[,.](\d)$/, '\:$10');
otherAmountvalue = otherAmountvalue.replace(/[,.](\d)(\d)$/, '\:$1$2');
otherAmountvalue = otherAmountvalue.replace(/[\$£€¥,.]/g, '');
otherAmountvalue = otherAmountvalue.replace(/:/, '.');
amount = parseFloat( value );
if ( isNaN( amount ) ) {
return 0;
} else {
return amount;
}
 
};
 
 
/**
Line 1,035 ⟶ 1,047:
// Load monthly convert JS if needed
// TODO: allow loading different JS variants, either here or defined in the Template
if ( mw.util.getParamValue('monthlyconvert') ) {
mw.loader.load( '/w/index.php?title=MediaWiki:MonthlyConvert.js&action=raw&ctype=text/javascript' );
}
}
 
// These get used in quite a few places