MediaWiki:Gadget-susaresources.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.
/* global jQuery, mediaWiki, Geo, $ */
if ( $.inArray(mw.config.get('wgPageName'), ['Mental_health_resources' ]) !== -1) {
mw.loader.using( 'ext.centralNotice.geoIP', 'mediawiki.api' ).then( function() { return mw.geoIP.getPromise(); } ).then( function ( geo ) {
var api = new mw.Api(),
countrysection,
countrycode,
countrylist = [];
$("#first-group").show(); // all are hidden by default
$("#first-group").children(".resources").each(function () {
$(this).hide();
countrylist.push($(this).attr("class").replace("resources resources-", ""));
});
// countrycode = prompt("Enter country code:", "GB"); // fall back in lieu of geolookup
countrycode = Geo.country;
if ($.inArray(countrycode, countrylist) == -1) {
$("#nocountrywarn").html("We're sorry, but there are not currently resources for " + countrycode + ". Please feel free to suggest some on the <a href='https://office.wikimedia.org/wiki/Talk:Support_and_Safety/MH_Resources&action=edit§ion=new'>talk page</a>.");
countrycode = "XX"; //default worldwide group
}
if (Geo.country === null) {
countrycode = "XX"; // as a default
}
countrysection = "#first-group .resources-" + countrycode;
$(countrysection).show();
});
}