MediaWiki:Gadget-GlobalScript.js: Difference between revisions

From SmashWiki, the Super Smash Bros. wiki
Jump to navigationJump to search
mNo edit summary
mNo edit summary
Line 28: Line 28:
if ($('body.skin-minerva').length)
if ($('body.skin-minerva').length)
setTimeout(function() { $('.header-action button').click(unicodeFixer) }, 3000);
setTimeout(function() { $('.header-action button').click(unicodeFixer) }, 3000);
}
});
/* SmashWiki: Match active tabber tab to infobox */
$(function() {
if ($('.infobox .tabber').length && $('.infobox th').length) {
var bgColor = $('.infobox th').css('background');
if (bgColor !== 'none' && bgColor !== 'rgb(255, 255, 255)')
$('head').append('<style type="text/css">body .mw-parser-output .infobox ul.tabbernav li.tabberactive a { background: ' + bgColor + '; }</style>');
}
}
});
});

Revision as of 23:31, January 26, 2024

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

/* Clean-up Unicode */
function unicodeFixer() {
	var textAreas = ['#wpTextbox1', '#wikitext-editor'];
	for (var i = 0; i < textAreas.length; i++) {
		if ($(textAreas[i]).length)
			$(textAreas[i]).val($(textAreas[i]).val().replace(/[\u200B-\u200F\uFEFF]/g, '').replace(/[‘’]{3}/g, "'''").replace(/[‘’]{2}/g, "''"));
	}
}
$(function() {
	$('#searchform').on('submit', function() {
		$('#searchInput').val($('#searchInput').val().replace(/[‘’]/g, "'").replace(/[“”]/g, '"'));
	});
	if (['edit', 'submit'].includes(mw.config.get('wgAction')) && ![8, 274, 828, 2300].includes(mw.config.get('wgNamespaceNumber'))) {
		$('.editButtons input').click(unicodeFixer);
		if ($('body.skin-minerva').length)
			setTimeout(function() { $('.header-action button').click(unicodeFixer) }, 3000);
	}
});

/* SmashWiki: Match active tabber tab to infobox */
$(function() {
	if ($('.infobox .tabber').length && $('.infobox th').length) {
		var bgColor = $('.infobox th').css('background');
		if (bgColor !== 'none' && bgColor !== 'rgb(255, 255, 255)')
			$('head').append('<style type="text/css">body .mw-parser-output .infobox ul.tabbernav li.tabberactive a { background: ' + bgColor + '; }</style>');
	}
});