MediaWiki:Gadget-GlobalScript.js

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

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

/* 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);

/* 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);				}); }		});	} });