MediaWiki:DonationForm.js: Difference between revisions
Content deleted Content added
rm fix for phab:T254274#6188493, should be fixed in form chooser now |
decouple URL parameters from <form> phab:T201415, plus some other minor cleanup |
||
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
var minAmount = donationForm.minimums[ currency ];
Line 253:
var hpcSet = mw.util.getParamValue('hpcSet');
var currency =
var language = mw.config.get('wgUserLanguage');
Line 362:
[ 175, [ 175, 200, 300, 400, 500, 750, 1000 ] ],
[ 200, [ 200, 225, 300, 400, 500, 750, 1000 ] ],
],
'2018control' : [
[ 0, [ 5, 10, 20, 25, 35, 50, 100 ] ],
Line 527:
};
var format = formats[currency][language] || formats[currency][
// Radio button amounts
Line 658:
/* Form functions */
function clearOther(box) {
document.getElementById(
box.value = "";
}
function selectOther() {
document.getElementById(
}
function selectAmount() {
$('#input_amount_other_box').val('');
}
Line 674 ⟶ 673:
/**
* Validate form, and if it looks good submit to payments
*
* @param {string} paymentMethod - method e.g. 'cc', 'paypal'
* @param {string} paymentSubMethod - submethod e.g. 'rtbt_ideal' (a submethod of 'rtbt')
Line 680 ⟶ 679:
*/
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
if ( donationForm.validate( skipAmountValidation ) ) {
var
var params = {};
// Overrides for specific cc gateways
if ( paymentMethod === 'cc-adyen' ) {
params.payment_method = 'cc';
params.ffname = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
params.payment_method = 'cc';
params.gateway = 'astropay';
} else {
params.payment_method = paymentMethod;
}
params.payment_submethod = paymentSubMethod;
}
var frequency = $(
if ( frequency !== 'monthly' ) {
} else {
}
params.uselang = mw.config.get('wgUserLanguage');
var
if (
donationForm.extraData.ptf = 1;
}
// 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 (
}
if ( mw.util.getParamValue( 'pym_variant' ) ) {
params.variant = mw.util.getParamValue( 'pym_variant' );
}
if ( mw.util.getParamValue( 'pym_appeal' ) ) {
params.appeal = mw.util.getParamValue( 'pym_appeal' );
}
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );
params.utm_medium if ( document.referrer ) { // TODO: do we need this?
// Strip protocol to stop firewall complaining
params.referrer = document.referrer.replace(/https?:\/\//i, '');
}
uri.extend( params );
donationForm.goToPayments( uri );
} else {
donationForm.extraData.validateError = 1; // Flag they had an error, even if fixed later
Line 750 ⟶ 758:
return false; // don't submit if called by a button
};
donationForm.goToPayments = function( uri ) {
if ( window.top !== window.self ) {
// In a frame, open payments in a new tab
window.open( uri.toString() );
} else {
window.location.href = uri.toString();
}
};
Line 755 ⟶ 773:
* Build a utm_source value, including the landing page info.
*
* Own function so it can be overriden for weird tests
*
* @param {Object} params
* @return {string} utm_source
*/
donationForm.buildUtmSource = function( params ) {
var utm_source = mw.util.getParamValue( 'utm_source' ) + '.';
var fullDottedPaymentMethod = params.payment_method;
if ( params.recurring ) {
fullDottedPaymentMethod = 'r' + fullDottedPaymentMethod;
}
if ( params.payment_submethod ) {
fullDottedPaymentMethod = fullDottedPaymentMethod + '.' + params.payment_submethod;
}
/* Get URL parameter, but remove parts using old format. Allow fallback to a default value */
Line 778 ⟶ 805:
utm_source += getParam( 'form-template' , 'Form-template-' , 'default' ) + '~';
utm_source += getParam( 'form-countryspecific', 'Form-countryspecific-', 'control' );
utm_source += '.' + fullDottedPaymentMethod;
return utm_source;
Line 792 ⟶ 821:
var existingUtmKey = mw.util.getParamValue('utm_key'),
dataArray = [];
if ( existingUtmKey ) {
dataArray.push( existingUtmKey );
Line 826 ⟶ 855:
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
amount = otherAmount;
donationForm.extraData.otherAmt = 1;
Line 859 ⟶ 887:
if ( form.opt_in ) {
if ( $(
$('#error-optin').show();
error = true;
Line 876 ⟶ 904:
donationForm.validateAmount = function() {
var amount = donationForm.getAmount();
var minAmount = donationForm.minimums[ donationForm.currency ] || 1;
if ( amount === null || isNaN(amount) || amount <= 0 || amount < minAmount ) {
Line 923 ⟶ 949:
*/
donationForm.calculateFee = function( amount ) {
// Minimum fee/PTF amounts. Default is 0.35.
Line 952 ⟶ 976:
var feeMultiplier = 0.04,
feeMinimum = feeMinimums[
feeAmount = amount * feeMultiplier;
if ( feeAmount < feeMinimum ) {
feeAmount = feeMinimum;
}
return parseFloat( feeAmount.toFixed(2) );
Line 964 ⟶ 988:
donationForm.initOptin = function() {
$('.optin-options').on('change', function(e) {
$('#error-optin').hide();
Line 988 ⟶ 1,012:
var form = document.forms['donateForm'];
// These get used in quite a few places
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,001 ⟶ 1,029:
}
var chr = String.fromCharCode(e.which);
if (
return false;
}
Line 1,029 ⟶ 1,057:
if ( form ) {
// hide frequency options for some countries
if ( donationForm.noRecurringCountries.indexOf(
$('#frequency_onetime').prop('checked', true);
$('.frequency-options, #cancel-monthly, #donate-recurring-smallprint').hide();
}
addCardTypesClass(
}
Line 1,049 ⟶ 1,071:
// Disable logo link
$(
// These don't need to be tabbable on the landing page
$('#searchInput, .mw-jump-link').attr('tabindex', '-1');
$(
$(
});
// Allow preselecting monthly
if( mw.util.getParamValue('monthly')
&& donationForm.noRecurringCountries.indexOf(
$('#frequency_monthly').click();
}
|