MediaWiki:Common.js

From the Super Mario Wiki, the Mario encyclopedia
Revision as of 23:34, March 6, 2022 by Porplemontage (talk | contribs)
Jump to navigationJump to search

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.
/* Any JavaScript here will be loaded for all users on every page load. */

/* Fix desktop anchor ad close button */
$('body.newbie').on('click', '#ssrt-close-anchor-button', function() {
	$('body > .ad-sticky-wrapper').hide();
});

/* Add subpages toolbox link on user pages */
$(function() {
	var title = mw.config.get('wgTitle');
	if (mw.config.get('wgCanonicalNamespace') === 'User' && !title.includes('/') && mw.config.get('skin') !== 'timeless') {
		var subpagesLink = '/Special:PrefixIndex/User:' + title + '/';
		mediaWiki.util.addPortletLink('p-tb', subpagesLink, 'User subpages', 't-subpages', 'Subpages of this page');
	}
});

/* Balance main page Shroom/MWE boxes and filler links */
$(function() {
	function mainPageMaintain() {
		var leftHeight = $('#featured').outerHeight(true) + $('#poll').outerHeight(true);
		var rightHeight = $('#news').outerHeight(true) + $('#dyk').outerHeight(true);
		var i, len; var divIds = ['shroom', 'mwe'];
		for (i = 0, len = divIds.length; i < len; ++i) {
			if (leftHeight < rightHeight) {
				$('#' + divIds[i] + '-left').attr('style', '');
				$('#' + divIds[i] + '-right').attr('style', 'display:none !important');
				leftHeight = leftHeight + $('#' + divIds[i] + '-left').outerHeight(true);
			} else {
				$('#' + divIds[i] + '-right').attr('style', '');
				$('#' + divIds[i] + '-left').attr('style', 'display:none !important');
				rightHeight = rightHeight + $('#' + divIds[i] + '-right').outerHeight(true);
			}
		}
		var heightDif; divIds = ['maintain', 'rc', 'random', 'faq', 'editing'];
		for (i = 0, len = divIds.length; i < len; ++i) {
			heightDif = Math.abs(leftHeight - rightHeight);
			if (heightDif > 26) {
				if ( leftHeight < rightHeight ) {
					$('#' + divIds[i] + '-left').attr('style', '');
					$('#' + divIds[i] + '-right').attr('style', 'display:none !important');
					leftHeight = leftHeight + $('#' + divIds[i] + '-left').outerHeight(true);
				} else {
					$('#' + divIds[i] + '-right').attr('style', '');
					$('#' + divIds[i] + '-left').attr('style', 'display:none !important');
					rightHeight = rightHeight + $('#' + divIds[i] + '-right').outerHeight(true);
				}
			} else {
				$('#' + divIds[i] + '-left').attr('style', 'display:none !important');
				$('#' + divIds[i] + '-right').attr('style', 'display:none !important');
			}
		}
	}
	if (mw.config.get('wgTitle') === 'Main Page') {
		$(mainPageMaintain);
		$(window).resize(function() {
			var timeout = 100;
			if (document.getElementsByClassName('pollspinner')[0])
				timeout = 500;
			clearTimeout(window.resizeFinished);
			window.resizeFinished = setTimeout(function() {
				$(mainPageMaintain);
			}, timeout);
		});
	}
});