MediaWiki:Common.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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* =========================================
EARTHMC HOMEPAGE SERVER SELECTOR
========================================= */
(function ($, mw) {
'use strict';
var servers = ['Nostra', 'Aurora', 'Nova', 'Classic'];
function selectServer(server, $root) {
if (servers.indexOf(server) === -1) {
return;
}
// Show only the selected server's panel.
servers.forEach(function (name) {
var panel = $root.find('#emc-server-' + name);
panel.prop('hidden', name !== server);
});
// Update the selected button.
$root.find('.emc-server-tab').each(function () {
var active = $(this).attr('data-server') === server;
$(this)
.toggleClass('emc-server-tab-active', active)
.attr('aria-pressed', String(active));
});
}
function initializeServerSelector($content) {
var $root = $content.find('.emc-server-tabs').first();
// Support the selector if it is inside the supplied content.
if (!$root.length && $content.is('.emc-server-tabs')) {
$root = $content;
}
if (!$root.length) {
return;
}
// Find the homepage wrapper containing the panels.
var $home = $root.closest('.emc-home');
if (!$home.length) {
$home = $root.parent();
}
// Avoid duplicate event handlers.
$root.find('.emc-server-tab')
.off('click.emcServer')
.on('click.emcServer', function () {
selectServer($(this).attr('data-server'), $home);
});
// Default to Nostra.
selectServer('Nostra', $home);
}
mw.hook('wikipage.content').add(function ($content) {
initializeServerSelector($content);
});
})(jQuery, mediaWiki);