MediaWiki:Gadget-GlobalScript.js: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
 
(22 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 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() {
$(function() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'UserMerge') {
$('#searchform').on('submit', function() {
$('input[name="wpnewuser"]').val('Anonymous');
$('#searchInput').val($('#searchInput').val().replace(/[‘’]/g, "'").replace(/[“”]/g, '"'));
$('input[name="wpdelete"]').prop('checked', true);
});
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);
}
}
});
});


/* Default Special:RefreshSpecial to uncheck all */
/* SmashWiki: Match active tabber tab to infobox */
$(function() {
$(function() {
if (mw.config.get('wgCanonicalSpecialPageName') === 'RefreshSpecial') {
if ($('.infobox .tabber').length && $('.infobox th').length) {
$('form[name="RefreshSpecial"] input[type="checkbox"]').prop('checked', false);
var bgColor = $('.infobox th').css('background');
$('form[name="RefreshSpecial"] ul').css('margin-bottom', '24px');
if (bgColor !== 'none' && bgColor !== 'rgb(255, 255, 255)')
$('form[name="RefreshSpecial"] li:last-of-type').hide();
$('head').append('<style type="text/css">body .mw-parser-output .infobox ul.tabbernav li.tabberactive a { background: ' + bgColor + '; }</style>');
}
}
});
});