MediaWiki:DonationForm T201415.js: Difference between revisions
Content deleted Content added
clean trailing spaces |
rm amountGiven usage |
||
(8 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
var currency = form.currency_code.value;▼
var minAmount = donationForm.minimums[ currency ];
Line 253:
var hpcSet = mw.util.getParamValue('hpcSet');
var currency =
var language = mw.config.get('wgUserLanguage');
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('');
$('input[name="amountGiven"]').val('');▼
}
Line 680 ⟶ 679:
*/
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
if ( donationForm.validate( skipAmountValidation ) ) {
var
var params = {};
// Overrides for specific cc gateways
paymentSubMethod = '';▼
}▼
if ( paymentMethod === 'cc-adyen' ) {
} else if (
} else {
}
params.payment_submethod = paymentSubMethod;
▲ form.payment_method.value = 'cc';
▲ form.gateway.value = 'astropay';
}
var frequency = $(
if ( frequency !== 'monthly' ) {
} else {
}
params.uselang = mw.config.get('wgUserLanguage');
var
if (
donationForm.extraData.ptf = 1;▼
}
// Email optin
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 (
▲ }
▲ donationForm.extraData.ptf = 1;
}▼
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?
}
} else {
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 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;▼
▲ var minAmount = donationForm.minimums[ 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 988 ⟶ 1,012:
var form = document.forms['donateForm'];
// These get used in quite a few places
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 ) {
▲ form.utm_medium.value = mw.util.getParamValue( 'utm_medium' );
▲ form.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' );
▲ form.utm_key.value = mw.util.getParamValue( 'utm_key' );
▲ // Strip protocol to stop firewall throwing fits
▲ form.referrer.value = document.referrer.replace(/https?:\/\//i, "");
// 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();
▲ }
▲ // Default to variant = panExplain for India
▲ // https://phabricator.wikimedia.org/T259146
}
|