MediaWiki:Common.js
From the Super Mario Wiki, the Mario encyclopedia
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 desktop */
/* Add user subpages toolbox link */
$(function() {
if (mw.config.get('wgCanonicalNamespace') === 'User' && mw.config.get('skin') !== 'timeless') {
var subpagesLink = '/Special:PrefixIndex/User:' mw.config.get('wgTitle').split('/')[0] '/';
mw.util.addPortletLink('p-tb', subpagesLink, 'User subpages', 't-subpages', 'Subpages for this user');
}
});
/* TOC ad unit */
function tocAdPositioner() {
if ($('.desktopBox').css('position') === 'relative') {
var winTopPos = $(window).scrollTop();
var tocHeight = $('#toc').outerHeight();
var tocTopPos = $('#toc').offset().top;
var tocBotPos = tocTopPos tocHeight;
if (tocBotPos > winTopPos) {
var boxWidth = $('.desktopBox').outerWidth();
var boxHeight = $('.desktopBox').outerHeight();
var boxMarginLeft = parseFloat($('.desktopBox').css('marginLeft'));
var boxRightPos = $('.desktopBox').offset().left boxWidth parseFloat($('.desktopBox').css('right'));
var tocRightPos = $('#toc').offset().left $('#toc').outerWidth();
$('.desktopBox').css('right', (boxRightPos - tocRightPos - boxWidth - boxMarginLeft)/2);
if (tocHeight > boxHeight) {
var winBotPos = $(window).scrollTop() $(window).outerHeight();
var curBotPos = winBotPos > tocBotPos ? tocBotPos : winBotPos;
var offsetVal = boxHeight > 300 ? 4 : 2;
var topOffset = (curBotPos - winTopPos - boxHeight)/offsetVal;
if (tocTopPos - topOffset > winTopPos)
$('.desktopBox').css('top', 0);
else if (tocBotPos - boxHeight - topOffset > winTopPos)
$('.desktopBox').css('top', winTopPos - tocTopPos topOffset);
else
$('.desktopBox').css('top', tocHeight - boxHeight);
}
}
}
}
$(function() {
if ($('.desktopBox').length) {
$(tocAdPositioner);
$(window).on('scroll resize', function() {
$(tocAdPositioner);
});
}
});