MediaWiki:FR2013/Resources/Banner2.js
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.
<script>
// Various common actions for banner setup.
var getQuerystring = function(key) {
// Should not be used any more, use mw.util.getParamValue() instead
// Kept for now though because this returns '' instead of null if key is not present
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];
};
$(document).ready( function () {
// Allow overriding the geolocation for testing different countries
if(mw.util.getParamValue('country')) {
Geo.country = mw.util.getParamValue('country');
}
var language = mw.config.get('wgUserLanguage'),
currency = getCurrency(Geo.country);
// Localize links in the smallprint
$('#{{{banner}}}-legal a, #frbanner-legal a, .frbanner-legal a').each(function(index) {
// 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");
});
// Show the correct 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();
}
// Find instances of %AVERAGE% in banner text, and replace with correct average for currency & country
$(".frbanner, div#{{{banner}}}, #frbanner3").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, div#{{{banner}}}, #frbanner3").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);
});
</script>