Template:2011FR/lp-form-biggerbutton



{ font-style: italic; font-weight:bold; }
 * 1) amount_table_header

select#input_currency_code { width:8em; font-size:70%; } 

//--- Utility Functions--- function arrayToObject(variable) //This is a helper function: converts an array to object literal with keys // then it can be used for quick "in" tests { var obj = {};

for (var i=0; i<variable.length; i++) {   obj[variable[i]]=''; }

return obj; }

function getQuerystring( key ) // This function to parse the information passed by central notice { key = key.replace( /[\[]/, '\\\[' ).replace( /[\]]/, '\\\]' ); var regex = new RegExp( '[\\?&]' + key + '=([a-zA-Z0-9\_\-]*)' ); var qs = regex.exec( window.location.search ); return qs == null ? '' : qs[1]; }

function getQuerystring2(key, default_) // This function to parse the information passed by central notice { if (default_==null) default_="";

key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); var regex = new RegExp("[\\?&]"+key+"=([^&#]*)"); var queryed = regex.exec(window.location.href);

if(queryed == null) return default_; else return queryed[1]; }

function getLandingPage //This function returns the path to the landing page. { var path = "  ";

if ( path == "default" ) {   pathArray = window.location.pathname.split( '/' ); return pathArray[2]; } else return path; }

//--Template Independent Arrays--- var country2currency = { } var currency2country = { }

var currencyPositions = { }; var euroPositions = { };

var currencySymbols = { }; var currencyMinimums = { };

var acceptedCC = arrayToObject([ ]); var acceptedPayPal = arrayToObject([ ]); var acceptedBankTransfer = arrayToObject([ ]);

// Calling Template Defined Arrays var currencyTypes = new Array ; var currencyDonationAmounts = { }; var currencyDisplay = new Array ;

//-Variables var countryCode = getQuerystring ('country'); if(countryCode == '') countryCode = 'US';

var languageCode = getQuerystring ('language'); if(languageCode == '') languageCode = 'en';

var currency = country2currency[countryCode]; if(typeof(currency) == 'undefined') {   currency = 'USD'; countryCode = 'US'; }

//- Body functions --- function updateButtons( currency ) //This function determines what buttons are displayed for each currency. { document.getElementById('cc-donate-button').style.display = "none"; document.getElementById('paypal-donate-button').style.display = "none"; document.getElementById('banktransfer-donate-button').style.display = "none"; if ( currency in acceptedCC ) {   //is this template still needed? document.getElementById('cc-donate-button').style.display = " "; } if (currency in acceptedPayPal ) {   //why not this? document.getElementById('paypal-donate-button').style.display = "block"; } if (currency in acceptedBankTransfer ) {   //or this? document.getElementById('banktransfer-donate-button').style.display = "block"; } }

function updateSymbol //This function displays the correct currency symbol based on currency selected and language { $('.amount-label-symbol').remove;

if (typeof(currencySymbols[currency]) == 'undefined') return;

if (currencyPositions[currency] == 'after') {   $('.amount-label').append(' ' + currencySymbols[currency] + ' '); } else if(currencyPositions[currency] == 'euro') {   if(euroPositions[languageCode] == 'before') {     $('.amount-label').prepend(' ' + currencySymbols[currency] + ' '); }   else {     $('.amount-label').append(' ' + currencySymbols[currency] + ' '); } }  else {   $('.amount-label').prepend(' ' + currencySymbols[currency] + ' '); } }

function updateValue //This function updates the asking amounts based on country and currency. { for(i=0; i<10; i++) {   if(typeof(currencyDonationAmounts[countryCode][i]) == 'undefined') {     break; }

if(currencyDisplay[i] != 0) {     document.getElementById("input_amount_" + i).value = currencyDonationAmounts[countryCode][i]; document.getElementById("input_amount_label_" + i).innerHTML = currencyDonationAmounts[countryCode][i]; } } }

function updateMenuChange(temp) //This function manages the updating when the drop down menu changes. { currency = temp; countryCode = currency2country[currency];

updateButtons(currency); updateValue; updateSymbol(currency); resetOtherBox; }

//--form junk function validateForm( form ) //This function checks the validity of the form. {

var error = true;

// Get amount selection var amount = null; for ( var i = 0; i < form.amount.length; i++ ) { if ( form.amount[i].checked ) { amount = form.amount[i].value; } }  if ( form.amountGiven.value != "") { var otherAmount = form.amountGiven.value; otherAmount = otherAmount.replace(/[,.](\d)$/, '\:$10'); otherAmount = otherAmount.replace(/[,.](\d)(\d)$/, '\:$1$2'); otherAmount = otherAmount.replace(/[,.]/g, ''); otherAmount = otherAmount.replace(/:/, '.'); form.amountGiven.value = otherAmount; amount = otherAmount; }

// Check amount is a real number error = ( amount == null || isNaN( amount ) || amount.value <= 0 ); // Check amount is at least the minimum var currency = form.currency_code[form.currency_code.selectedIndex].value; if ( typeof( currencyMinimums[currency] ) == 'undefined' ) { currencyMinimums[currency] = 1; } if ( amount < currencyMinimums[currency] || error ) { alert( ' '.replace('$1', currencyMinimums[currency] + ' ' + currency ) ); error = true; } return !error; }

function DefaultSubmit(formfield, Action) //This function manages the submit action of the form. { var keycode; if (window.event) {   keycode = window.event.keyCode; } else if (Action) {   keycode = Action.which; } else return true;

if (keycode == 13) {   if (document.getElementById('cc-donate-button').style.display == "block") {     redirectPayment('cc'); }   else if (document.getElementById('paypal-donate-button').style.display == "block") {     redirectPayment('pp'); }   return false; } else return true; }

function redirectPayment(paymentType) //This function directs the payment to the proper method. { if (paymentType == 'cc') {   var paymentType = 'cc'; var action_url = "https://payments.wikimedia.org/index.php/Special:PayflowProGateway?uselang= \x26masthead=\x26form_name=\x26text_template=\x26language= " ; } if (paymentType == 'pp') {   action_url="http://wikimediafoundation.org/wiki/Special:ContributionTracking/  "; } document.paypalcontribution.action = action_url; document.paypalcontribution.utm_source.value = getQuerystring( 'utm_source' ) + '.' + getLandingPage + '.' + paymentType; if(validateForm(document.paypalcontribution)) {   if(typeof(OWA) !== 'undefined') {     OWATracker.shareStateByPost( document.paypalcontribution ); }   document.paypalcontribution.submit; } }

          





var items = 1; for(i=0; i<10; i++) {     if(items%4 == 0) {       document.getElementById("amount-box").innerHTML += " "; }

if(typeof(currencyDonationAmounts[countryCode][i]) == 'undefined' ) {       break; }     //This adds the radio options according to the flags passed to the template. if(currencyDisplay[i] != 0) {       document.getElementById("amount-box").innerHTML += " " + "<label for='input_amount_" + i + "' class='amount-label' id='input_amount_label_" + i + "'> " + currencyDonationAmounts[countryCode][i] + " ";

items++; }   }

<input type="radio" name="amount" id="input_amount_other" value="" /><label for="input_amount_other"> <input type="text" name="amountGiven" size="3" style="color:#666666;" onclick="this.value=''; clearOtherBox;" onfocus="this.form.input_amount_other.checked=true;" onKeyPress="return DefaultSubmit(this,event)" />

<select name="currency_code" id="input_currency_code" size="1" style="width:8em; font-size:80%;" onchange="resetOtherBox; updateMenuChange(this.value);">

<script type="text/javascript" language="javascript"> var opt = document.createElement("option"); opt.selected = true; opt.text = currency + " – " + currencySymbols[currency]; opt.value = currency; document.getElementById("input_currency_code").options.add(opt); //       var opt = document.createElement("option"); opt.text = "---"; opt.value = "USD"; document.getElementById("input_currency_code").options.add(opt)

for(i=0; i<currencyTypes.length; i++) {         opt = document.createElement("option"); opt.text = currencyTypes[i] + " – " + currencySymbols[currencyTypes[i]]; opt.value = currencyTypes[i];

document.getElementById("input_currency_code").options.add(opt); }

<input type="button" value=" " class="button" onclick="redirectPayment('cc')"; style="width: 20em; white-space:normal;" /> <input type="button" value=" " class="button" onclick="redirectPayment('pp');" style="width: 20em;" /> <input type="button" value=" " class="button" onclick="redirectPayment('bt');" style="width: 20em; display: none;" />

    *  *  *  <p style="margin-top: 1em;">

<script type="text/javascript"> function resetOtherBox //This function resets the "Other" Box to the default values. { document.getElementsByName("amountGiven")[0].style.color = "#666666"; document.getElementsByName("amountGiven")[0].value = ""; }

function clearOtherBox //This function empties the "Other" Box. { document.getElementsByName("amountGiven")[0].style.color = "#000000"; document.getElementsByName("amountGiven")[0].value = ""; }

document.paypalcontribution.utm_medium.value = getQuerystring( 'utm_medium' ); document.paypalcontribution.utm_campaign.value = getQuerystring( 'utm_campaign' ); document.paypalcontribution.country.value = getQuerystring ( 'country_code' ); document.paypalcontribution.referrer.value = document.referrer;

( function( $ ) { $(document).ready(function{ updateButtons(currency); updateValue; updateSymbol(currency); resetOtherBox; }) } )( jQuery );