MediaWiki:Common.js: Difference between revisions
Content deleted Content added
No edit summary |
extra code for country select: translations etc |
||
Line 40:
// 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) {▼
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] );
}
}
});
}
});
}
});
}
if ( document.getElementById('country-select') ) {
enableCountrySelect();
}
// Code for Thank You pages - https://donate.wikimedia.org/wiki/MediaWiki:ThankYouPage.js
|