MediaWiki:DonationForm T201415.js: Difference between revisions

Content deleted Content added
only include referrer param if needed
rm amountGiven usage
 
(4 intermediate revisions by the same user not shown)
Line 1:
/* jshint strict:false */
/** MediaWiki:DonationForm.js - loaded on all donation forms
* TODO: lots of cleanup
Line 213 ⟶ 214:
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
var formcurrency = documentdonationForm.forms['donateForm']currency;
var currency = form.currency_code.value;
var minAmount = donationForm.minimums[ currency ];
 
Line 253:
var hpcSet = mw.util.getParamValue('hpcSet');
 
var currency = $("input[name='currency_code']")donationForm.val()currency;
var language = mw.config.get('wgUserLanguage');
 
Line 527:
};
 
var format = formats[currency][language] || formats[currency]["'default"'] || formats[currency] || '\t';
 
// Radio button amounts
Line 658:
/* 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('');
}
 
Line 680 ⟶ 679:
*/
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
 
var form = document.forms['donateForm'];
 
if ( donationForm.validate( skipAmountValidation ) ) {
Line 688 ⟶ 685:
var params = {};
 
// Overrides for specific cc gateways
if (typeof paymentSubMethod == 'undefined') {
paymentSubMethod = '';
}
 
// Adyen override for cc
if ( paymentMethod === 'cc-adyen' ) {
paymentMethod = 'cc';
params.payment_method = 'cc';
params.gateway = 'adyen';
params.ffname = 'adyen';
} else if ( paymentMethod === 'cc-dlocal'; ) {
}
 
// dLocal override for cc
if ( paymentMethod === 'cc-dlocal' ) {
paymentMethod = 'cc';
params.payment_method = 'cc';
params.gateway = 'astropay';
} else {
params.variantpayment_method = 'panExplain'paymentMethod;
}
 
if (typeof paymentSubMethod == 'undefined') {
// Default to variant = panExplain for India
params.payment_submethod = paymentSubMethod;
// TODO: make this default payments side - https://phabricator.wikimedia.org/T259146
if ( mw.util.getParamValue('country') === 'IN' ) {
params.variant = 'panExplain';
}
 
var frequency = $('input[name="frequency"]:checked').val();
if ( frequency !== 'monthly' ) {
frequency = 'onetime';
params.recurring = false;
} else {
Line 721 ⟶ 708:
}
 
params.payment_methodcurrency_code = paymentMethoddonationForm.currency;
ifparams.country (= paymentSubMethod ) {donationForm.country;
params.payment_submethoduselang = paymentSubMethodmw.config.get('wgUserLanguage');
}
 
var amount = donationForm.getAmount();
Line 733 ⟶ 719:
params.amount = amount;
 
/*/ Email optin */
if ( $('input[name="opt_in"]').length > 0 ) {
var opt_inValue = $('input[name="opt_in"]:checked').val();
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
}
 
// Default to variant = panExplain for India
// TODO: make this default payments side - https://phabricator.wikimedia.org/T259146
if ( paymentMethoddonationForm.country === 'cc-dlocalIN' ) {
paymentSubMethodparams.variant = 'panExplain';
}
 
if ( mw.util.getParamValue( 'pym_variant' ) ) {
params.variant = mw.util.getParamValue( 'pym_variant' );
}
if ( mw.util.getParamValue( 'countrypym_appeal' ) === 'IN' ) {
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
 
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );
 
// Tracking data
params.utm_medium = mw.util.getParamValue( 'utm_medium' );
params.utm_campaign = mw.util.getParamValue( 'utm_campaign' );
params.utm_source = donationForm.buildUtmSource( params );
params.utm_key = donationForm.buildUtmKey( donationForm.extraData );
if ( document.referrer ) { // TODO: do we need this?
 
// TODO: do we need this?
if ( document.referrer ) {
// Strip protocol to stop firewall complaining
params.referrer = document.referrer.replace(/https?:\/\//i, '');
Line 857 ⟶ 855:
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
form.amountGiven.value = otherAmount; // TODO: change this
amount = otherAmount;
donationForm.extraData.otherAmt = 1;
Line 890 ⟶ 887:
 
if ( form.opt_in ) {
if ( $("'input[name='"opt_in'"]:checked"').val() === undefined ) {
$('#error-optin').show();
error = true;
Line 907 ⟶ 904:
donationForm.validateAmount = function() {
 
var form = document.forms['donateForm'];
var amount = donationForm.getAmount();
var minAmount = donationForm.minimums[ donationForm.currency ] || 1;
var currency = form.currency_code.value;
var minAmount = donationForm.minimums[ currency ] || 1;
 
if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmount ) {
Line 954 ⟶ 949:
*/
donationForm.calculateFee = function( amount ) {
 
var form = document.forms['donateForm'];
 
// Minimum fee/PTF amounts. Default is 0.35.
Line 983 ⟶ 976:
 
var feeMultiplier = 0.04,
feeMinimum = feeMinimums[ formdonationForm.currency_code.valuecurrency ] || 0.35,
feeAmount = amount * feeMultiplier;
 
if ( feeAmount < feeMinimum ) {
feeAmount = feeMinimum;
}
return parseFloat( feeAmount.toFixed(2) );
Line 1,019 ⟶ 1,012:
 
var form = document.forms['donateForm'];
 
// These get used in quite a few places
var currency donationForm.currency = form.currency_code.value;
donationForm.country = mw.util.getParamValue('country');
 
// Block typing symbols in input field, otherwise Safari allows them and then chokes
Line 1,032 ⟶ 1,029:
}
var chr = String.fromCharCode(e.which);
if ("'0123456789., "'.indexOf(chr) === -1) {
return false;
}
Line 1,062 ⟶ 1,059:
 
// hide frequency options for some countries
if ( donationForm.noRecurringCountries.indexOf( formdonationForm.country.value ) !== -1 ) {
$('#frequency_onetime').prop('checked', true);
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
 
addCardTypesClass( formdonationForm.country.value );
}
 
Line 1,074 ⟶ 1,071:
 
// Disable logo link
$("'#p-logo a"').attr(" { href",: "'#"', title: '' } );
$("#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')
&& donationForm.noRecurringCountries.indexOf( formdonationForm.country.value ) === -1 ) {
$('#frequency_monthly').click();
}