MediaWiki:Gadget-GlobalScript.js: Difference between revisions

From Halopedia, the Halo wiki

No edit summary
mNo edit summary
 
(26 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 */
/* Add autocollapse support to mw-collapsible */
$('.gallerybox audio').each(function(i, obj) {
function mwCollapsibleSetup($collapsibleContent) {
if ($(this).parent().css('margin-top') < '15px')
var $element, autoCollapseThreshold = 2;
$(this).parent().css('margin', '15px auto');
$.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:ReplaceText to not announce edits */
/* Fix search suggestions on mobile devices */
$(function() {
$(function() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'ReplaceText')
$('#searchInput').on('input', function(e) {
$('input[id="doAnnounce"]').prop('checked', false);
$(this).trigger(jQuery.Event('keydown', {
keyCode: e.keyCode,
which: e.which
}));
$(this).trigger(jQuery.Event('keypress', {
keyCode: e.keyCode,
which: e.which
}));
});
});
});


/* Default Special:UserMerge to user deletion */
/* Clean-up Unicode */
$(function() {
function unicodeFixer() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'UserMerge') {
var textAreas = ['#wpTextbox1', '#wikitext-editor'];
$('input[name="wpnewuser"]').val('Anonymous');
for (var i = 0; i < textAreas.length; i++) {
$('input[name="wpdelete"]').prop('checked', true);
if ($(textAreas[i]).length)
$(textAreas[i]).val($(textAreas[i]).val().replace(/[\u200B-\u200F\uFEFF]/g, '').replace(/[‘’]{3}/g, "'''").replace(/[‘’]{2}/g, "''"));
}
}
});
}
 
/* Default Special:RefreshSpecial to uncheck all */
$(function() {
$(function() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'RefreshSpecial') {
$('#searchform').on('submit', function() {
$('form[name="RefreshSpecial"] input[type="checkbox"]').prop('checked', false);
$('#searchInput').val($('#searchInput').val().replace(/[‘’]/g, "'").replace(/[“”]/g, '"'));
$('form[name="RefreshSpecial"] li:last-of-type').hide();
});
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);
}
}
});
});
Line 35: Line 51:
var talkTab;
var talkTab;
if (mw.config.get('skin') == 'nimbus') {
if (mw.config.get('skin') == 'nimbus') {
talkTab = $('a[title="Discussion about the content page"]');
talkTab = $('a#ca-talk');
talkTab.removeClass('tab-new');
talkTab.removeClass('tab-new');
} else if (mw.config.get('skin') == 'minerva') {
talkTab = $('a[data-event-name="tabs.talk"]');
talkTab.removeClass('new');
} else {
} else {
talkTab = $('#ca-talk a');
talkTab = $('#ca-talk a');
$('#ca-talk').removeClass('new');
$('#ca-talk').removeClass('new');
}
}
var talkUrl = talkTab.attr('href').replace('index.php?title=', '').replace(namespace, 'User').replace('&action=edit&redlink=1', '');
var talkUrl = talkTab.attr('href').replace('index.php?title=', '').replace(namespace, 'User').replace('?action=edit&redlink=1', '');
var subIndex = talkUrl.indexOf('/', 1);
var subIndex = talkUrl.indexOf('/', 1);
if (subIndex > 0)
if (subIndex > 0)
Line 49: Line 68:
});
});


/* Username inserts for the USERNAME template */
/* SocialProfile: Prevent repeated button clicks */
$(function() {
$(function() {
if (typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || mw.config.get('wgUserName') === null) return;
$('.site-button[type="button"]').click(function() {
$('span.insertusername').each(function() {
$(this).prop('disabled', true);
$(this).text(mw.config.get('wgUserName'));
});
});
});
/* Upload page script */
$(function() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload')
mw.loader.load('/index.php?title=MediaWiki:HalopediaUpload.js' + '&action=raw&ctype=text/javascript');
});
});

Latest revision as of 17:05, February 15, 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);

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