MediaWiki:Resources/landingpage.js: Difference between revisions

From Donate
Jump to navigation Jump to search
Content deleted Content added
Pgehres (WMF) (talk | contribs)
No edit summary
Pgehres (WMF) (talk | contribs)
No edit summary
Line 36: Line 36:
0 : [5, 10, 20, 25, 35, 50, 100],
0 : [5, 10, 20, 25, 35, 50, 100],
10 : [10, 20, 25, 35, 50, 100, 150],
10 : [10, 20, 25, 35, 50, 100, 150],
20 : [7, 10, 20, 25, 50, 100, 250],
20 : [20, 25, 35, 50, 75, 100, 250],
25 : [20, 25, 35, 50, 75, 100, 250],
35 : [20, 35, 50, 100, 150, 200, 250],
35 : [20, 35, 50, 100, 150, 200, 250],
50 : [20, 35, 50, 100, 150, 200, 250],
50 : [20, 35, 50, 100, 150, 200, 250],

Revision as of 02:54, 26 November 2012

<html>
<script type="text/javascript">
$( document ).ready( function () {
  // Disable submitting form with return key
  $( 'form' ).bind( 'keypress', function(e) {
    var code = ( e.keyCode ? e.keyCode : e.which );
    if ( code == 13 ) return false;
  } );

  $("#p-logo a").attr("href", "#");
  $("#p-logo a").attr("title", "");
} );

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];
}

</script>
<script type="text/javascript">
$(document).ready(function(){
    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, 100],
            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 ask = null;
    var currency = $("input[name='currency_code']").val();

    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( ask[j] );
                    }
                }
            }
        }
    }
});
</script>
</html>