MediaWiki:Resources/landingpage.js: Difference between revisions

From Donate
Jump to navigation Jump to search
Content deleted Content added
rm until I can be certain it's working
No edit summary
Line 78: Line 78:
asks['GBP'] = asks['USD'];
asks['GBP'] = asks['USD'];
asks['NZD'] = asks['USD'];
asks['NZD'] = asks['USD'];

var appealasks = {
'USD' : {
0 : [5, 10, 20],
10 : [10, 20, 50],
20 : [20, 30, 50],
35 : [20, 30, 50],
50 : [20, 50, 100],
75 : [50, 75, 100],
100 : [75, 100, 150],
150 : [75, 100, 200],
200 : [100, 200, 300]
}
};
appealasks['AUD'] = appealasks['USD'];
appealasks['CAD'] = appealasks['USD'];
appealasks['EUR'] = appealasks['USD'];
appealasks['GBP'] = appealasks['USD'];
appealasks['NZD'] = appealasks['USD'];


var symbols = {
var symbols = {
Line 119: Line 138:
}
}
}
}
}
if( currency in appealasks ){
if( appealasks[currency].length < 1 ){
return;
}
for( var prev in appealasks[currency] ){
// this assumes that JS returns keys in sorted order, most do
if( prev > hpc ){
break;
}
appealask = appealasks[currency][prev];
}
var considerAmountString = "";
for( var j = 0; j < appealask.length; j++ ) {
considerAmountString += symbol + appealask[j] + ', ';
}
considerAmountString = considerAmountString.trim();
$('.consider-amounts').html(considerAmountString);
}
}



Revision as of 03:30, 7 December 2013

<html>
<script>
function getQuerystring( key ) {
  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 checkPaymentOutages() {
    /*  Check against the scheduled payment method outages
     *  in global variable "outages" (loaded cross-wiki from meta)
     *  and hide the relevant button for any which are ongoing.
     */
    
    // var outages = outages || []; // don't die if it hasn't loaded...
    var now = new Date();
    
    for (var i = outages.length - 1; i >= 0; i--) {
        if ( now > outages[i]['start'] ) {
            if ( now < outages[i]['end'] ) {

                if ( (typeof outages[i]['country'] === 'undefined') || (outages[i]['country'] == country) ) {
                    $('.paymentmethod-' + outages[i]['method']).hide();
                }

            }
        }
    }
}



$(document).ready(function(){

    $.getScript('//meta.wikimedia.org/w/index.php?' + $.param( { title:'MediaWiki:FR2013/Resources/PaymentOutages.js', action:'raw' } ),
        function() {
            setTimeout(checkPaymentOutages(), 250); // allow time for script to have _executed_ (not just loaded)
        });

    // Disable submitting form with return key
    $( 'form' ).bind( 'keypress', function(e) {
      var code = ( e.keyCode ? e.keyCode : e.which );
      if ( code == 13 ) return false;
    } );

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

    // Highest previous contribution adjustments (for emails)
    var hpc = getQuerystring( 'hpc' );
    if( hpc == '' || isNaN( parseFloat( hpc ) ) ){
        // go ahead and try mrc as well
        hpc = getQuerystring( 'mrc' );
        if( hpc == '' || isNaN( parseFloat( hpc ) ) ){
            return;
        }
    }
    hpc = parseFloat( hpc );

    var asks = {
        'USD' : {
            0 : [5, 10, 20, 25, 35, 50, 100],
            10 : [10, 20, 25, 35, 50, 100, 150],
            20 : [20, 25, 35, 50, 75, 100, 250],
            35 : [20, 35, 50, 100, 150, 200, 250],
            50 : [20, 35, 50, 100, 150, 200, 250],
            75 : [25, 50, 75, 100, 200, 300, 500],
            100 : [25, 50, 100, 150, 250, 500, 1000],
            150 : [50, 100, 150, 200, 350, 500, 1000],
            200 : [50, 100, 200, 300, 400, 500, 1000]
        }
    };
    asks['AUD'] = asks['USD'];
    asks['CAD'] = asks['USD'];
    asks['EUR'] = asks['USD'];
    asks['GBP'] = asks['USD'];
    asks['NZD'] = asks['USD'];

    var appealasks = {
        'USD' : {
            0 : [5, 10, 20],
            10 : [10, 20, 50],
            20 : [20, 30, 50],
            35 : [20, 30, 50],
            50 : [20, 50, 100],
            75 : [50, 75, 100],
            100 : [75, 100, 150],
            150 : [75, 100, 200],
            200 : [100, 200, 300]            
        }
    };
    appealasks['AUD'] = appealasks['USD'];
    appealasks['CAD'] = appealasks['USD'];
    appealasks['EUR'] = appealasks['USD'];
    appealasks['GBP'] = appealasks['USD'];
    appealasks['NZD'] = appealasks['USD'];

    var symbols = {
        'USD' : '$',
        'AUD' : '$',
        'CAD' : '$',
        'EUR' : '€',
        'GBP' : '£',
        'NZD' : '$'
    };

    var ask = null;
    var symbol = '';

    var currency = $("input[name='currency_code']").val();
    if( currency in symbols ){
        symbol = symbols[currency];
    }
    if( currency in asks ){
        if( asks[currency].length < 1 ){
            return;
        }
        for( var prev in asks[currency] ){
            // this assumes that JS returns keys in sorted order, most do
            if( prev > hpc ){
                break;
            }
            ask = asks[currency][prev];
        }
        if( ask != null ){
            for( var j = 0; j < ask.length; j++ ){
                var radio = $("#input_amount_" + j);
                var label = $("label[for='input_amount_" + j + "']");
                if( radio != null ){
                    if( label != null ){
                        // I know an && could be used here, but they are getting escaped
                        radio.val( ask[j] );
                        label.text( symbol + ask[j] );
                    }
                }
            }
        }
    }
    if( currency in appealasks ){
        if( appealasks[currency].length < 1 ){
            return;
        }
        for( var prev in appealasks[currency] ){
            // this assumes that JS returns keys in sorted order, most do
            if( prev > hpc ){
                break;
            }
            appealask = appealasks[currency][prev];
        }
        var considerAmountString = "";
        for( var j = 0; j < appealask.length; j++ ) {
            considerAmountString += symbol + appealask[j] + ', ';
        }
        considerAmountString = considerAmountString.trim();
        $('.consider-amounts').html(considerAmountString);
    }

    // prefill other amount box if param provided
    var otherVal = getQuerystring( 'otherVal' );
    if( otherVal == '' || isNaN( parseFloat( otherVal ) ) ){
        return;
    }
    otherVal = parseFloat( otherVal );
    $("#input_amount_other").attr( 'checked', true );
    $("#input_amount_other_box").val( otherVal );
    
});
</script>
</html>