MediaWiki:Gadget-GlobalScript.js: Difference between revisions

m
no edit summary
No edit summary
mNo edit summary
(11 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 */
/* Fix media negative margin bug for wide galleries */
$(function() {
$('.gallerybox audio').each(function(i, obj) {
if ($(this).parent().css('margin-top') < '15px')
$(this).parent().css('margin', '15px auto');
});
});


/* Add autocollapse support to mw-collapsible */
/* Add autocollapse support to mw-collapsible */
Line 20: Line 12:
mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);
mw.hook('wikipage.collapsibleContent').add(mwCollapsibleSetup);


/* Fix links to hidden mw-collapsible sections */
/* Fix search suggestions on mobile devices */
window.onhashchange = function() {
$(function() {
escapedHash = $.escapeSelector(decodeURI(location.hash.split('#').pop()));
$('#searchInput').on('input', function(e) {
hiddenParents = $('#' + escapedHash).parents('.mw-collapsed');
$(this).trigger(jQuery.Event('keydown', {
if (hiddenParents.length) {
keyCode: e.keyCode,
hiddenParents.each(function() {
which: e.which
$(this).find('.mw-collapsible-toggle-collapsed').first().click();
}));
});
$(this).trigger(jQuery.Event('keypress', {
location.href = location.hash;
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() {
$(function() {
if (location.hash)
$('#searchform').on('submit', function() {
window.dispatchEvent(new HashChangeEvent('hashchange'));
$('#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);
}
});
});