MediaWiki:DonationForm T201415.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
re-order slightly to match banners
more misc cleanup
Line 1: Line 1:
/* jshint strict:false */
/** MediaWiki:DonationForm.js - loaded on all donation forms
/** MediaWiki:DonationForm.js - loaded on all donation forms
* TODO: lots of cleanup
* TODO: lots of cleanup
Line 526: Line 527:
};
};


var format = formats[currency][language] || formats[currency]["default"] || formats[currency] || '\t';
var format = formats[currency][language] || formats[currency]['default'] || formats[currency] || '\t';


// Radio button amounts
// Radio button amounts
Line 657: Line 658:
/* Form functions */
/* Form functions */
function clearOther(box) {
function clearOther(box) {
document.getElementById("input_amount_other").checked = true;
document.getElementById('input_amount_other').checked = true;
box.value = "";
box.value = "";
}
}


function selectOther() {
function selectOther() {
document.getElementById("input_amount_other").checked = true;
document.getElementById('input_amount_other').checked = true;
}
}


Line 679: Line 680:
*/
*/
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {

var form = document.forms['donateForm'];


if ( donationForm.validate( skipAmountValidation ) ) {
if ( donationForm.validate( skipAmountValidation ) ) {
Line 687: Line 686:
var params = {};
var params = {};


// Overrides for specific cc gateways
if (typeof paymentSubMethod == 'undefined') {
paymentSubMethod = '';
}

// Adyen override for cc
if ( paymentMethod === 'cc-adyen' ) {
if ( paymentMethod === 'cc-adyen' ) {
paymentMethod = 'cc';
params.payment_method = 'cc';
params.payment_method = 'cc';
params.gateway = 'adyen';
params.gateway = 'adyen';
params.ffname = 'adyen';
params.ffname = 'adyen';
} else if ( paymentMethod === 'cc-dlocal' ) {
}

// dLocal override for cc
if ( paymentMethod === 'cc-dlocal' ) {
paymentMethod = 'cc';
params.payment_method = 'cc';
params.payment_method = 'cc';
params.gateway = 'astropay';
params.gateway = 'astropay';
} else {
params.payment_method = paymentMethod;
}
}


params.payment_method = paymentMethod;
if ( paymentSubMethod ) {
if ( paymentSubMethod ) {
params.payment_submethod = paymentSubMethod;
params.payment_submethod = paymentSubMethod;
Line 713: Line 704:
var frequency = $('input[name="frequency"]:checked').val();
var frequency = $('input[name="frequency"]:checked').val();
if ( frequency !== 'monthly' ) {
if ( frequency !== 'monthly' ) {
frequency = 'onetime';
params.recurring = false;
params.recurring = false;
} else {
} else {
Line 730: Line 720:
params.amount = amount;
params.amount = amount;


/* Email optin */
// Email optin
if ( $('input[name="opt_in"]').length > 0 ) {
if ( $('input[name="opt_in"]').length > 0 ) {
var opt_inValue = $('input[name="opt_in"]:checked').val();
var opt_inValue = $('input[name="opt_in"]:checked').val();
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
params.opt_in = opt_inValue; // donationForm.validate() already checked it's 1 or 0
}
}


Line 751: Line 741:
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );
donationForm.extraData.time = Math.round( (Date.now() - donationForm.loadedTime)/1000 );


// Tracking data
params.utm_medium = mw.util.getParamValue( 'utm_medium' );
params.utm_medium = mw.util.getParamValue( 'utm_medium' );
params.utm_campaign = mw.util.getParamValue( 'utm_campaign' );
params.utm_campaign = mw.util.getParamValue( 'utm_campaign' );
params.utm_source = donationForm.buildUtmSource( params );
params.utm_source = donationForm.buildUtmSource( params );
params.utm_key = donationForm.buildUtmKey( donationForm.extraData );
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
// Strip protocol to stop firewall complaining
params.referrer = document.referrer.replace(/https?:\/\//i, '');
params.referrer = document.referrer.replace(/https?:\/\//i, '');
Line 900: Line 889:


if ( form.opt_in ) {
if ( form.opt_in ) {
if ( $("input[name='opt_in']:checked").val() === undefined ) {
if ( $('input[name="opt_in"]:checked').val() === undefined ) {
$('#error-optin').show();
$('#error-optin').show();
error = true;
error = true;
Line 962: Line 951:
*/
*/
donationForm.calculateFee = function( amount ) {
donationForm.calculateFee = function( amount ) {

var form = document.forms['donateForm'];


// Minimum fee/PTF amounts. Default is 0.35.
// Minimum fee/PTF amounts. Default is 0.35.
Line 995: Line 982:


if ( feeAmount < feeMinimum ) {
if ( feeAmount < feeMinimum ) {
feeAmount = feeMinimum;
feeAmount = feeMinimum;
}
}
return parseFloat( feeAmount.toFixed(2) );
return parseFloat( feeAmount.toFixed(2) );
Line 1,044: Line 1,031:
}
}
var chr = String.fromCharCode(e.which);
var chr = String.fromCharCode(e.which);
if ("0123456789., ".indexOf(chr) === -1) {
if ('0123456789., '.indexOf(chr) === -1) {
return false;
return false;
}
}
Line 1,086: Line 1,073:


// Disable logo link
// Disable logo link
$("#p-logo a").attr("href", "#");
$('#p-logo a').attr('href', '#');
$("#p-logo a").attr("title", "");
$('#p-logo a').attr('title', '');


// These don't need to be tabbable on the landing page
// These don't need to be tabbable on the landing page
$('#searchInput, .mw-jump-link').attr('tabindex', '-1');
$('#searchInput, .mw-jump-link').attr('tabindex', '-1');


$(".input_amount_other").click(function() {
$('.input_amount_other').click(function() {
$("#input_amount_other_box").focus();
$('#input_amount_other_box').focus();
});
});