MediaWiki:Gadget-GlobalScript.js

/* Any JavaScript here will be loaded for all skins on both desktop and mobile */

/* Add autocollapse support to mw-collapsible */ function mwCollapsibleSetup($collapsibleContent) { var $element, autoCollapseThreshold = 2; $.each($collapsibleContent, function(index, element) {		$element = $(element);		if ($collapsibleContent.length >= autoCollapseThreshold && $element.hasClass('autocollapse'))			$element.data('mw-collapsible').collapse;	}); } mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);

/* Gallery videos */ $(function {	$('.gallery').each(function(i, gallery) { var videos = $(gallery).find('.gallerybox video'); if (!videos.length) return; var boxes = $(gallery).find('.gallerybox'); var onlyVideos = videos.length == boxes.length ? true : false; videos.each(function(ii, video) {			if (onlyVideos)				$(video).css('height', 'auto');			$(video).parent.css({'max-width': 'calc(100% - 30px)', 'margin': '15px auto'});		}); var timeOut = onlyVideos ? 1000 : 0;		setTimeout(function {			var height = 0;			$(gallery).find('.gallerybox .thumb').each(function(ii, thumb) { if ($(thumb).innerHeight > height) height = $(thumb).innerHeight; });			videos.each(function(ii, video) { maxHeight = height - 30; $(video).parent.parent.css({'height': height, 'display': 'flex'}); $(video).parent.css({'width': '100%', 'min-width': '125px', 'margin': 'auto'}); $(video).css({'height': 'auto', 'max-height': maxHeight}); });		}, timeOut); }); });

/* Add disclaimer and URL to copied article text for newbies */ $(function {	if (!mw.config.get('wgUserGroups').includes('autoconfirmed')) {		var notice1 = 'The above text is from the Super Mario Wiki and is available under a Creative Commons license.';		var notice2 = 'Attribution must be provided through a list of authors or a link back to the original article.';		var message = '\n\n' + notice1 + ' ' + notice2 + ' Source: ' + mw.config.get('wgServer');		if (mw.config.get('wgNamespaceNumber') === 0) {			$('#mw-content-text').on('copy', function(e) { var text = window.getSelection.toString; if (text.length > 100) { var articlePath = mw.config.get('wgArticlePath').replace('$1', encodeURIComponent(mw.config.get('wgPageName'))); text = text.concat(message + articlePath); e.originalEvent.clipboardData.setData('text/plain', text); e.preventDefault; }			});		}		$('textarea').on('paste', function(e) { var clipboardData = e.clipboardData || window.clipboardData || e.originalEvent.clipboardData; var clipboard = clipboardData.getData('Text'); regex = new RegExp(message + '[^ \n]+$'); if (regex.test(clipboard)) { var input = $(this); var match = clipboard.match(regex)[0]; var cursor = input[0].selectionStart + clipboard.length - match.length; setTimeout(function {					input.val(input.val.replace(match, ''));					input[0].setSelectionRange(cursor, cursor);				}); }		});	} });

/* Balance main page Shroom/MWE boxes and filler links */ $(function {	function mainPageMaintain {		if ($(window).width >= 720) {			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 > 25) { 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'); }			}		} else { $('#mwe-right').attr('style', ''); $('#mwe-left').attr('style', 'display:none !important'); }	}	if (mw.config.get('wgPageName') === 'Main_Page' || mw.config.get('wgPageName').startsWith("MarioWiki:BJAODN/April_Fool's")) { $(mainPageMaintain); $(window).resize(function {			var timeout = 100;			if (document.getElementsByClassName('pollspinner')[0])				timeout = 500;			clearTimeout(window.resizeFinished);			window.resizeFinished = setTimeout(function { $(mainPageMaintain); }, timeout);		}); } });