MediaWiki:DonationForm.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
moving inline javascript from Template:Optin/Default
using slightly better syntax for accessing form
Line 210: Line 210:
/* Localize the amount errors. Call when initialising form. */
/* Localize the amount errors. Call when initialising form. */
donationForm.localizeErrors = function() {
donationForm.localizeErrors = function() {
var currency = document.paypalcontribution.currency_code.value;
var form = document.forms['paypalcontribution'];
var currency = form.currency_code.value;
var minAmount = donationForm.minimums[ currency ];
var minAmount = donationForm.minimums[ currency ];


Line 677: Line 678:
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {


var form = document.paypalcontribution; // we should really change this some day
var form = document.forms['paypalcontribution']; // we should really change this some day


if ( donationForm.validate( skipAmountValidation ) ) {
if ( donationForm.validate( skipAmountValidation ) ) {
Line 805: Line 806:
/* Return amount selected or input */
/* Return amount selected or input */
donationForm.getAmount = function() {
donationForm.getAmount = function() {
var form = document.paypalcontribution;
var form = document.forms['paypalcontribution'];
var amount = null;
var amount = null;
donationForm.extraData.otherAmt = 0;
donationForm.extraData.otherAmt = 0;
Line 847: Line 848:


var error = false;
var error = false;
var form = document.paypalcontribution;
var form = document.forms['paypalcontribution'];


// Reset all errors
// Reset all errors
Line 875: Line 876:
donationForm.validateAmount = function() {
donationForm.validateAmount = function() {


var form = document.forms['paypalcontribution'];
var amount = donationForm.getAmount();
var amount = donationForm.getAmount();
var currency = document.paypalcontribution.currency_code.value;
var currency = form.currency_code.value;
var minAmount = donationForm.minimums[ currency ] || 1;
var minAmount = donationForm.minimums[ currency ] || 1;


Line 921: Line 923:
*/
*/
donationForm.calculateFee = function( amount ) {
donationForm.calculateFee = function( amount ) {

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


// Minimum fee/PTF amounts. Default is 0.35.
// Minimum fee/PTF amounts. Default is 0.35.
Line 948: Line 952:


var feeMultiplier = 0.04,
var feeMultiplier = 0.04,
feeMinimum = feeMinimums[document.paypalcontribution.currency_code.value] || 0.35,
feeMinimum = feeMinimums[ form.currency_code.value ] || 0.35,
feeAmount = amount * feeMultiplier;
feeAmount = amount * feeMultiplier;


Line 982: Line 986:


mw.loader.using( ['mediawiki.util'] ).done( function() {
mw.loader.using( ['mediawiki.util'] ).done( function() {

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


// Block typing symbols in input field, otherwise Safari allows them and then chokes
// Block typing symbols in input field, otherwise Safari allows them and then chokes
// https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431
// https://phabricator.wikimedia.org/T118741, https://phabricator.wikimedia.org/T173431

var amountOtherInput = document.getElementById('input_amount_other_box');
var amountOtherInput = document.getElementById('input_amount_other_box');
if ( amountOtherInput ) {
if ( amountOtherInput ) {
Line 1,023: Line 1,028:
});
});


if ( document.paypalcontribution ) {
if ( form ) {
document.paypalcontribution.utm_medium.value = mw.util.getParamValue( 'utm_medium' );
form.utm_medium.value = mw.util.getParamValue( 'utm_medium' );
document.paypalcontribution.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' );
form.utm_campaign.value = mw.util.getParamValue( 'utm_campaign' );
document.paypalcontribution.utm_key.value = mw.util.getParamValue( 'utm_key' );
form.utm_key.value = mw.util.getParamValue( 'utm_key' );


// Strip protocol to stop firewall throwing fits
// Strip protocol to stop firewall throwing fits
document.paypalcontribution.referrer.value = document.referrer.replace(/https?:\/\//i, "");
form.referrer.value = document.referrer.replace(/https?:\/\//i, "");


// hide frequency options in India, where we can only handle one-time donations
// hide frequency options in India, where we can only handle one-time donations
if (document.paypalcontribution.country.value === 'IN') {
if ( form.country.value === 'IN' ) {
$("#frequency_onetime").prop('checked', true);
$("#frequency_onetime").prop('checked', true);
$(".frequency-options").hide();
$(".frequency-options").hide();
Line 1,038: Line 1,043:
}
}


addCardTypesClass(document.paypalcontribution.country.value);
addCardTypesClass( form.country.value );
}
}