MediaWiki:FR2014/Resources/FullScreenLocalize.js

From Meta, a Wikimedia project coordination wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/** MediaWiki:FR2014/Resources/FullScreenLocalize.js
  * Do various things to localize full-screen banners
  */

$(document).ready(function() {

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

        /* Allow overriding country */
        if( mw.util.getParamValue("country") ) {
            Geo.country = mw.util.getParamValue("country");
        }

        var currency = getCurrency(Geo.country);
        var language = mw.config.get('wgUserLanguage');

        /* Links (in smallprint) */
        $('a.localize, .frbanner-footer a').each(function() {
            var url = $(this).attr("href");
            if( url.indexOf("?") === -1 ) {
                url = url + "?";
            } else {
                url = url + "&";
            }
            $(this).attr("href", url + "country=" + Geo.country + "&language=" + language + "&uselang=" + language);

            // Make links open in new tab
            $(this).attr("target", "_blank");
        });

        /* Legal text variant */
        if (Geo.country === 'US') {
            $('.informationsharing-US').show();
            $('.informationsharing-NL').hide();
            $('.informationsharing-nonUS').hide();
        }
        if (Geo.country === 'NL') {
            $('.informationsharing-US').hide();
            $('.informationsharing-NL').show();
            $('.informationsharing-nonUS').hide();
        }

        /* Main amount buttons */
        $('.frbanner-amounts input[id^="field-amount_total"]').each(function(index) {
            var $input = $(this);
            var $label = $('label[for="' + $input.attr('id') + '"]');
            var amount = convertAsk( $input.val(), currency, Geo.country );
            $input.val( amount );
            $label.html( currencyLocalize( currency, amount, language) );
        });

        /* "Other" box
            Don't know how to do it for the symbol coming after the number though */
        $('.frbanner-amounts #amount_other fieldset label').html(
            currencyLocalize( currency, '', language )
        );

        /* "Average" amount */
        var average = fundraisingAmounts.pick(fundraisingAmounts.averages, currency, Geo.country);
        $('.fr-amount-avg').html(
            currencyLocalize( currency, average, language )
        );

        /* "If everyone" amount */
        var ifEveryone = fundraisingAmounts.pick(fundraisingAmounts.ifEveryone, currency, Geo.country)[0];
        $('.fr-amount-if').html(
            currencyLocalize( currency, ifEveryone, language )
        );

        /* Number of payment method buttons */
        if (Geo.country === 'US' || Geo.country === 'AU') {
            $('.frbanner-form').addClass('frbanner-form-3pm');
        } else if (Geo.country === 'CA' || Geo.country === 'GB' || Geo.country === 'NZ') {
            $('.frbanner-form').addClass('frbanner-form-2pm');
        }

    });

});
/* end of MediaWiki:FR2014/Resources/FullScreenLocalize.js */