MediaWiki:Gadget-GlobalScript.js: Difference between revisions

From Halopedia, the Halo wiki

No edit summary
mNo edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all skins on both desktop and mobile */
/* 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 */
/* Add autocollapse support to mw-collapsible */
Line 12: Line 17:
mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);
mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);


/* Replace smart quotes */
/* Fix search suggestions on mobile devices */
function quoteFixer() {
$(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'];
var textAreas = ['#wpTextbox1', '#wikitext-editor'];
for (var i = 0; i < textAreas.length; i++) {
for (var i = 0; i < textAreas.length; i++) {
if ($(textAreas[i]).length)
if ($(textAreas[i]).length)
$(textAreas[i]).val($(textAreas[i]).val().replace(/[‘’]/g, "'").replace(/[“”]/g, '"'));
$(textAreas[i]).val($(textAreas[i]).val().replace(/[\u200B-\u200F\uFEFF]/g, '').replace(/[‘’]{3}/g, "'''").replace(/[‘’]{2}/g, "''"));
}
}
}
}
$(function() {
$(function() {
if (['edit', 'submit'].includes(mw.config.get('wgAction')) && ![8, 10, 274, 828, 2300].includes(mw.config.get('wgNamespaceNumber'))) {
$('#searchform').on('submit', function() {
$('.editButtons input').click(quoteFixer);
$('#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)
if ($('body.skin-minerva').length)
setTimeout(function() { $('.header-action button').click(quoteFixer) }, 3000);
setTimeout(function() { $('.header-action button').click(unicodeFixer) }, 3000);
}
}
});
/* 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);
});
});
});



Latest revision as of 07:52, September 27, 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);
	}
});

/* SocialProfile: Point social talk tabs to user talk */
$(function() {
	var namespace = mw.config.get('wgCanonicalNamespace');
	if (namespace === 'UserProfile' || namespace === 'UserWiki') {
		var talkTab;
		if (mw.config.get('skin') == 'nimbus') {
			talkTab = $('a#ca-talk');
			talkTab.removeClass('tab-new');
		} else if (mw.config.get('skin') == 'minerva') {
			talkTab = $('a[data-event-name="tabs.talk"]');
			talkTab.removeClass('new');
		} else {
			talkTab = $('#ca-talk a');
			$('#ca-talk').removeClass('new');
		}
		var talkUrl = talkTab.attr('href').replace('index.php?title=', '').replace(namespace, 'User').replace('?action=edit&redlink=1', '');
		var subIndex = talkUrl.indexOf('/', 1);
		if (subIndex > 0)
			talkUrl = talkUrl.substring(0, subIndex);
		talkTab.attr('href', talkUrl);
	}
});

/* SocialProfile: Prevent repeated button clicks */
$(function() {
	$('.site-button[type="button"]').click(function() {
		$(this).prop('disabled', true);
	});
});