MediaWiki:Gadget-MobileScript.js: Difference between revisions

From the Super Mario Wiki, the Mario encyclopedia
Jump to navigationJump to search
No edit summary
mNo edit summary
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for users of the mobile site */
/* Any JavaScript here will be loaded for users of the mobile site */
/* Expand single talk section */
$(function() {
setTimeout(function() {
if ($('.ns-talk .collapsible-heading').length === 1)
$('.collapsible-heading:not(.open-block)').click();
}, 100);
});


/* Collapse boxes on smaller devices */
/* Collapse boxes on smaller devices */
Line 12: Line 20:
/* Add mobile options toolbox link on Timeless */
/* Add mobile options toolbox link on Timeless */
$(function() {
$(function() {
if (mw.config.get('skin') === 'timeless') {
if (mw.config.get('wgMFMode') && mw.config.get('skin') === 'timeless') {
var optionsLink = '/Special:MobileOptions';
var optionsLink = '/Special:MobileOptions';
mediaWiki.util.addPortletLink('p-tb', optionsLink, 'Mobile options', 't-options', 'Options for the mobile site');
var optionsDesc = 'Settings for the mobile site';
mw.util.addPortletLink('p-tb', optionsLink, 'Mobile options', 't-options', optionsDesc);
}
}
});
});
Line 21: Line 30:
$(function() {
$(function() {
if ($('.navbox-section').length) {
if ($('.navbox-section').length) {
if ($('section:nth-last-of-type(2) > *:not(.navbox):not(.mw-empty-elt)').length > 0
  || $('.section-heading:nth-last-of-type(2) > .mw-headline#References').length > 0
  || $('.section-heading:nth-last-of-type(2) > .mw-headline#Sources').length > 0)
$('section:nth-last-of-type(2) > .navbox').detach().appendTo('.navbox-section');
$('.nav-right').clone().appendTo('.navbox-section');
$('.nav-right').clone().appendTo('.navbox-section');
if ($('section:nth-last-of-type(2) > :not(.navbox):not(.mw-empty-elt)').length
  || $('.section-heading:nth-last-of-type(2) > .mw-headline:is(#Sources, #References)').length) {
$('.skin-timeless section:nth-last-of-type(2) > .navbox').detach().appendTo('.navbox-section');
$('.skin-minerva section:nth-last-of-type(2) > .navbox:not(.multi)').detach().appendTo('.navbox-section');
$('.skin-minerva section:nth-last-of-type(2) > .navbox.multi > tbody > tr > td > .navbox').detach().appendTo('.navbox-section');
}
if ($.trim($('.navbox-section').text()) == '') {
if ($.trim($('.navbox-section').text()) == '') {
$('.navbox-heading').attr('style', 'display:none !important');
$('.navbox-heading').attr('style', 'display:none !important');
$('.navbox-section').attr('style', 'display:none !important');
$('.navbox-section').attr('style', 'display:none !important');
}
if (!$('.navbox-section > :not(.nav-right)').length) {
$('.navbox-heading').addClass('navrights-only');
$('.navbox-section').addClass('navrights-only');
}
}
}
}
});
/* Adjust table of contents to fit with infobox */
$(function() {
var body = $('#bodyContent');
var infobox = $('.infobox');
if (infobox) {
    var maxWidth = Math.round(body.width() - infobox.outerWidth(true) - 10);
    $('head').append('<style type="text/css">.toc-mobile { max-width: ' + maxWidth + 'px; }</style>');
}
});
function tocResizer() {
var body = $('#bodyContent');
var infobox = $('.infobox');
var toc = $('.toc-mobile');
if (infobox && toc) {
    var maxWidth = Math.round(body.width() - infobox.outerWidth(true) - 10);
    toc.css('max-width', maxWidth);
}
}
$(window).resize(function() {
$(tocResizer);
});
});

Latest revision as of 08:23, September 25, 2024

/* Any JavaScript here will be loaded for users of the mobile site */

/* Expand single talk section */
$(function() {
	setTimeout(function() {
		if ($('.ns-talk .collapsible-heading').length === 1)
			$('.collapsible-heading:not(.open-block)').click();
	}, 100);
});

/* Collapse boxes on smaller devices */
function mwMobileCollapse($collapsibleContent) {
	if ($(window).width() < 720)
		$.each($collapsibleContent, function(index, element) {
			$(element).data('mw-collapsible').collapse();
		});
}
mw.hook('wikipage.collapsibleContent').add(mwMobileCollapse);

/* Add mobile options toolbox link on Timeless */
$(function() {
	if (mw.config.get('wgMFMode') && mw.config.get('skin') === 'timeless') {
		var optionsLink = '/Special:MobileOptions';
		var optionsDesc = 'Settings for the mobile site';
		mw.util.addPortletLink('p-tb', optionsLink, 'Mobile options', 't-options', optionsDesc);
	}
});

/* MarioWiki: Move navboxes to dedicated section */
$(function() {
	if ($('.navbox-section').length) {
		$('.nav-right').clone().appendTo('.navbox-section');
		if ($('section:nth-last-of-type(2) > :not(.navbox):not(.mw-empty-elt)').length
		  || $('.section-heading:nth-last-of-type(2) > .mw-headline:is(#Sources, #References)').length) {
			$('.skin-timeless section:nth-last-of-type(2) > .navbox').detach().appendTo('.navbox-section');
			$('.skin-minerva section:nth-last-of-type(2) > .navbox:not(.multi)').detach().appendTo('.navbox-section');
			$('.skin-minerva section:nth-last-of-type(2) > .navbox.multi > tbody > tr > td > .navbox').detach().appendTo('.navbox-section');
		}
		if ($.trim($('.navbox-section').text()) == '') {
			$('.navbox-heading').attr('style', 'display:none !important');
			$('.navbox-section').attr('style', 'display:none !important');
		}
		if (!$('.navbox-section > :not(.nav-right)').length) {
			$('.navbox-heading').addClass('navrights-only');
			$('.navbox-section').addClass('navrights-only');
		}
	}
});