MediaWiki:Gadget-MobileScript.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 9: | Line 9: | ||
} | } | ||
mw.hook('wikipage.collapsibleContent').add(mwMobileCollapse); | mw.hook('wikipage.collapsibleContent').add(mwMobileCollapse); | ||
/* Add mobile options toolbox link on Timeless */ | |||
$(function() { | |||
var title = mw.config.get('wgTitle'); | |||
if (mw.config.get('skin') === 'timeless') { | |||
var optionsLink = '/Special:MobileOptions'; | |||
mediaWiki.util.addPortletLink('p-tb', optionsLink, 'Mobile options', 't-options', 'Options for the mobile site'); | |||
} | |||
}); | |||
/* Move navboxes to dedicated section */ | /* Move navboxes to dedicated section */ |
Revision as of 21:52, September 16, 2021
/* Any JavaScript here will be loaded for users of the mobile site */
/* 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() {
var title = mw.config.get('wgTitle');
if (mw.config.get('skin') === 'timeless') {
var optionsLink = '/Special:MobileOptions';
mediaWiki.util.addPortletLink('p-tb', optionsLink, 'Mobile options', 't-options', 'Options for the mobile site');
}
});
/* Move navboxes to dedicated section */
$(function() {
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');
if ($.trim($('.navbox-section').text()) == '') {
$('.navbox-heading').attr('style', 'display:none !important');
$('.navbox-section').attr('style', 'display:none !important');
}
}
});
/* 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);
});