MediaWiki:FR2014/Resources/MobileLocalize.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/MobileLocalize.js
  * Do various things to localize mobile banners
  *
  * Dependencies:
  *     MediaWiki:FR2015/Resources/MethodLocalize.js
  */

$(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() {
            // Add parameters for LandingCheck
            var uri = new mw.Uri( $(this).attr("href") );
            uri.extend({
                country:      Geo.country,
                language:     language,
                uselang:      language,
                utm_medium:   'sitenotice',
                utm_campaign: mw.centralNotice.getDataProperty('campaign'),
                utm_source:   mw.centralNotice.getDataProperty('banner')
            });
            $(this).attr( "href", uri.toString() );

            // 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();
        }

        /* --- Amounts --- */

        /* Main amount buttons */
        var asks = fundraisingAmounts.pick(fundraisingAmounts.mobileAsks, currency, Geo.country);

        $('.frbanner-amounts .amount-btn input').each(function(index) {
            var $input = $(this);
            var $label = $('label[for="' + $input.attr('id') + '"]');
            var amount = asks[index];
            $input.val( amount );
            $label.html( currencyLocalize( currency, amount, language) );
        });

        /* "Other" box. Doesn't yet work for symbol after number */
        $('#amount_total_6 label .currencySymbol').html(
            currencyLocalize( currency, '', language )
        );

        // Find instances of %AVERAGE% in banner text, and replace with correct average for currency & country
        $(".frbanner-message, .frbanner2-message, .frbanner3-message").each(function(index){
            var avgString = getAverage(currency, Geo.country, language).replace(/\.$/, ''); // strip any period from end for use in running text
            var newHtml = $(this).html().replace(/%AVERAGE%/g, avgString );
            $(this).html(newHtml);
        });

        // Find instances of %MINIMUM% in banner text, and replace with correct minimum for currency & country
        $(".frbanner-message, .frbanner2-message, .frbanner3-message").each(function(index){
            var ifString = getMinimumString(currency, Geo.country, language).replace(/\.$/, ''); // strip any period from end for use in running text
            var newHtml = $(this).html().replace(/%MINIMUM%/g, ifString );
            $(this).html(newHtml);
        });
        
        /* Replace class "frbanner-currencycode" with currency ISO code */
        $('.frbanner-currencycode').html(currency);

        /* Payment methods */
        {{MediaWiki:FR2015/Resources/MethodLocalize.js}}
        
        
        /*  Check against the scheduled payment method outages below
         *  and hide the relevant button for any which are ongoing.
         */
        {{MediaWiki:FR2013/Resources/PaymentOutages.js}}
        var now = new Date();
     
        for (var i = outages.length - 1; i >= 0; i--) {
            if ( now > outages[i]['start'] && now < outages[i]['end'] ) {
                if (outages[i]['country'] === undefined || outages[i]['country'] == Geo.country) {
                    $('.paymentmethod-' + outages[i]['method']).remove();
                }
            }
        }

    });

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