MediaWiki:Mobile.js

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

/* Fix media negative margin bug for wide galleries */ $('.gallerybox .mediaContainer').each(function(i, obj) {	if ($(this).parent.css('margin-top') < '15px')		$(this).parent.css('margin', '15px auto'); });

/* Add subpages link on user pages */ $(function {	var namespace = mw.config.get('wgCanonicalNamespace');	var title = mw.config.get('wgTitle');	if (namespace === 'User' && title.indexOf('/') < 0)		$('.user-links').append(' Subpages'); });

/* Adjust margin of thumbs with no caption */ function thumbFixer { $('.thumb').each(function(i, obj) {		if (!$(this).find('.thumbcaption').text) {			if (window.matchMedia('all and (max-width: 719px)').matches)				$(this).css('margin-bottom', '0.75em');			else				$(this).css('margin-bottom', '');		}	}); } $(thumbFixer); $(window).resize(function {	$(thumbFixer); });

/* 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('.toc-mobile { max-width: ' + maxWidth + 'px; } '); } }); 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); });

/* SocialProfile: Point social talk tabs to user talk */ $(function {	var namespace = mw.config.get('wgCanonicalNamespace');	if (namespace === 'UserProfile' || namespace === 'UserWiki') {		var talkTab = $('.talk.mw-ui-button.button');		var talkTitle = talkTab.attr('data-title').replace(namespace, 'User');		var talkUrl = talkTab.attr('href').replace(namespace, 'User');		var subIndex = talkUrl.indexOf('/', 1);		if (subIndex > 0) {			talkUrl = talkUrl.substring(0, subIndex);			talkTitle = talkTitle.substring(0, subIndex - 1);		}		talkTab.attr('href', talkUrl);		talkTab.attr('data-title', talkTitle);	} });

/* SocialProfile: Fix profile edit redirect */ setTimeout(function {	if (mw.config.get('wgCanonicalNamespace') === 'UserProfile' || (mw.config.get('wgCanonicalNamespace') === 'User' && document.getElementById('user-page-left'))) {		var editUrl = $('link[rel="edit"]').attr('href');		$('.edit-page').attr('href', editUrl);	} }, 1000);