MediaWiki:Gadget-GlobalScript.js: Difference between revisions

From the Kingdom Hearts Wiki, the Kingdom Hearts encyclopedia
Jump to navigationJump to search
No edit summary
mNo edit summary
 
(29 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* JS placed here will be applied to all skins on both desktop and mobile */
/* Any JavaScript here will be loaded for all skins on both desktop and mobile */


/* Fix media negative margin bug for wide galleries */
/* Revert superscript language */
$('.gallerybox audio').each(function(i, obj) {
$(function() {
if ($(this).parent().css('margin-top') < '15px')
$('.mw-parser-output [lang] sup').attr('lang', 'en');
$(this).parent().css('margin', '15px auto');
});
});


/* Default Special:ReplaceText to not announce edits */
/* Add autocollapse support to mw-collapsible */
$(function() {
function mwCollapsibleSetup($collapsibleContent) {
if (mw.config.get('wgCanonicalSpecialPageName') === 'ReplaceText')
var $element, autoCollapseThreshold = 2;
$('input[id="doAnnounce"]').prop('checked', false);
$.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);


/* Default Special:UserMerge to user deletion */
/* Fix search suggestions on mobile devices */
$(function() {
$(function() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'UserMerge') {
$('#searchInput').on('input', function(e) {
$('input[name="wpnewuser"]').val('Anonymous');
$(this).trigger(jQuery.Event('keydown', {
$('input[name="wpdelete"]').prop('checked', true);
keyCode: e.keyCode,
}
which: e.which
}));
$(this).trigger(jQuery.Event('keypress', {
keyCode: e.keyCode,
which: e.which
}));
});
});
});


/* Default Special:RefreshSpecial to uncheck all */
/* Clean-up Unicode */
$(function() {
function unicodeFixer() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'RefreshSpecial') {
var textAreas = ['#wpTextbox1', '#wikitext-editor'];
$('form[name="RefreshSpecial"] input[type="checkbox"]').prop('checked', false);
for (var i = 0; i < textAreas.length; i++) {
$('form[name="RefreshSpecial"] ul').css('margin-bottom', '24px');
if ($(textAreas[i]).length)
$('form[name="RefreshSpecial"] li:last-of-type').hide();
$(textAreas[i]).val($(textAreas[i]).val().replace(/[\u200B-\u200F\uFEFF]/g, '').replace(/[‘’]{3}/g, "'''").replace(/[‘’]{2}/g, "''"));
}
}
});
}
 
/* Username inserts for the USERNAME template */
$(function() {
$(function() {
if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') === null) return;
$('#searchform').on('submit', function() {
$('span.insertusername').each(function() {
$('#searchInput').val($('#searchInput').val().replace(/[‘’]/g, "'").replace(/[“”]/g, '"'));
$(this).text(mw.config.get('wgUserName'));
});
});
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);
}
});
});

Latest revision as of 12:51, 27 September 2024

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

/* Revert superscript language */
$(function() {
	$('.mw-parser-output [lang] sup').attr('lang', 'en');
});

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

/* Fix search suggestions on mobile devices */
$(function() {
	$('#searchInput').on('input', function(e) {
		$(this).trigger(jQuery.Event('keydown', {
			keyCode: e.keyCode,
			which: e.which
		}));
		$(this).trigger(jQuery.Event('keypress', {
			keyCode: e.keyCode,
			which: e.which
		}));
	});
});

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