MediaWiki:Common.js: Difference between revisions

Content deleted Content added
No edit summary
indentation to tabs
(4 intermediate revisions by the same user not shown)
Line 1:
/**
* MediaWiki:Common.js - Any JavaScript here will be loaded for all users on every page load.
**/
Line 39:
}
 
// Allow manual country selection and reload
// Run this only when needed
var enableCountrySelect = function() {
var language = mw.config.get('wgPageContentLanguage'),
countrySelect = document.getElementById('country-select');
 
// Translations
if ( language !== 'en' && language !== 'en-gb' ) {
const translationsUrl = 'https://donate.wikimedia.org/wiki/Module:Country_links/data.json?action=raw';
$.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-change') ) {
document.getElementById('country-change').addEventListener( 'click', function(e) {
document.getElementById('country-change-select').style.display = 'block';
enableCountrySelect();
});
});
enableCountrySelect();
}
}
 
if ( document.getElementById('countrygeolocate-selecterror') ) {
// TODO: only do this when actually needed e.g. geolocate error
enableCountrySelect();
if ( document.getElementById('country-select') ) {
}
enableCountrySelect();
 
}
try {
let uri = new mw.Uri( window.location.href );
if ( uri.query.showCountryConfirm ) {
document.getElementById('country-confirm').style.display = 'block';
}
} catch (error) {
console.warn('Error parsing URL. Possibly due to unreplaced % signs?');
}
 
// Code for Thank You pages - https://donate.wikimedia.org/wiki/MediaWiki:ThankYouPage.js