MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
No edit summary
extra code for country select: translations etc
Line 40: Line 40:


// Allow manual country selection and reload
// Allow manual country selection and reload
// Run this only when needed
var countrySelect = document.getElementById('country-select');
var enableCountrySelect = function() {
if ( countrySelect ) {
var language = mw.config.get('wgPageContentLanguage'),
document.getElementById('country-select-go').addEventListener( 'click', function(e) {
countrySelect = document.getElementById('country-select');
if ( countrySelect.value ) {

mw.loader.using( ['mediawiki.Uri'] ).done( function() {
// Translations
var uri = new mw.Uri( document.location.href );
if ( language !== 'en' && language !== 'en-gb' ) {
uri.query.country = countrySelect.value;
const translationsUrl = 'https://donate.wikimedia.org/wiki/Module:Country_links/data.json?action=raw'
document.location = uri.toString();
$.getJSON( translationsUrl, function( translations ) {
});
if ( translations[language] ) {
}
var list = Array.from( countrySelect.options );
});
list.forEach( option => {
}
option.innerText = translations[language][option.value] || option.innerText;
});
// Sort for new language
list.sort( function(a, b) {
return a.innerText.localeCompare( b.innerText );
});
for ( var i = 0; i < list.length; i++ ) {
list[i].parentNode.appendChild( list[i] );
}
}
});
}

document.getElementById('country-select-go').addEventListener( 'click', function(e) {
if ( countrySelect.value ) {
mw.loader.using( ['mediawiki.Uri'] ).done( function() {
var uri = new mw.Uri( document.location.href );
uri.query.country = countrySelect.value;
document.location = uri.toString();
});
}
});
}

if ( document.getElementById('country-select') ) {
enableCountrySelect();
}


// Code for Thank You pages - https://donate.wikimedia.org/wiki/MediaWiki:ThankYouPage.js
// Code for Thank You pages - https://donate.wikimedia.org/wiki/MediaWiki:ThankYouPage.js