MediaWiki:DonationForm T201415.js: Difference between revisions
Content deleted Content added
use boolean for param.recurring |
rm amountGiven usage |
||
(5 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('');
}
Line 680 ⟶ 679:
*/
donationForm.redirectPayment = function( paymentMethod, paymentSubMethod, skipAmountValidation ) {
if ( donationForm.validate( skipAmountValidation ) ) {
Line 688 ⟶ 685:
var params = {};
// Overrides for specific cc gateways
if (typeof paymentSubMethod == 'undefined') {▼
paymentSubMethod = '';▼
}▼
if ( paymentMethod === 'cc-adyen' ) {
paymentMethod = 'cc';▼
params.payment_method = 'cc';
params.gateway = 'adyen';
params.ffname = 'adyen';
}▼
if ( paymentMethod === 'cc-dlocal' ) {▼
params.payment_method = 'cc';
params.gateway = 'astropay';
} else {
}
// 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' ) {
params.recurring = false;
} else {
Line 721 ⟶ 708:
}
params.
}▼
var amount = donationForm.getAmount();
Line 733 ⟶ 719:
params.amount = amount;
/
if ( $('input[name="opt_in"]').length > 0 ) {
var opt_inValue = $('input[name="opt_in"]:checked').val();
params.opt_in
▲ }
▲ // Default to variant = panExplain for India
▲ // TODO: make this default payments side - https://phabricator.wikimedia.org/T259146
▲ }
if ( mw.util.getParamValue( 'pym_variant' ) ) {
params.variant = mw.util.getParamValue( 'pym_variant' );
▲ }
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?▼
// Strip protocol to stop firewall complaining
▲ // TODO: do we need this?
}
▲ params.referrer = document.referrer.replace(/https?:\/\//i, "");
uri.extend( params );
Line 855:
otherAmount = otherAmount.replace(/[\$£€¥,.]/g, '');
otherAmount = otherAmount.replace(/:/, '.');
amount = otherAmount;
donationForm.extraData.otherAmt = 1;
Line 888 ⟶ 887:
if ( form.opt_in ) {
if ( $(
$('#error-optin').show();
error = true;
Line 905 ⟶ 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 952 ⟶ 949:
*/
donationForm.calculateFee = function( amount ) {
// Minimum fee/PTF amounts. Default is 0.35.
Line 981 ⟶ 976:
var feeMultiplier = 0.04,
feeMinimum = feeMinimums[
feeAmount = amount * feeMultiplier;
if ( feeAmount < feeMinimum ) {
feeAmount = feeMinimum;
}
return parseFloat( feeAmount.toFixed(2) );
Line 1,017 ⟶ 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,030 ⟶ 1,029:
}
var chr = String.fromCharCode(e.which);
if (
return false;
}
Line 1,060 ⟶ 1,059:
// 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,072 ⟶ 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();
}
|