MediaWiki:Common.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/**** mobile views ****/
if ($(window).width() < 768) {
/* Wrap Tables for scrolling in mobile views */
$('table').not('.mw-collapsible').not('.pi-horizontal-group').wrap(
'<div style="max-width: 90vw; overflow-x: scroll" class="table-scroll-shadow"></div>'
);
/* Hide heading if infobox exists - shows duplicate information */
var infobox = $('.portable-infobox');
if (infobox.length > 0) {
$('.firstHeading').hide();
}
}
else {
$(window).on("scroll", function() {
var nav = document.getElementById("mw-panel");
if (window.scrollY >= nav.offsetTop) {
nav.classList.add("sticky");
} else {
nav.classList.remove("sticky");
}
});
}
/*$(document).ready(function() {
// Ctrl+I for italic
$(document).keydown(function(e) {
if (e.ctrlKey && e.keyCode === 73) {
var textarea = $('#wpTextbox1').get(0);
var startPos = textarea.selectionStart;
var endPos = textarea.selectionEnd;
var selectedText = textarea.value.substring(startPos, endPos);
var newText = "''" + selectedText + "''";
var beforeText = textarea.value.substring(0, startPos);
var afterText = textarea.value.substring(endPos, textarea.value.length);
textarea.value = beforeText + newText + afterText;
textarea.setSelectionRange(endPos + 4, endPos + 4);
e.preventDefault();
}
});
// Ctrl+B for bold
$(document).keydown(function(e) {
if (e.ctrlKey && e.keyCode === 66) {
var textarea = $('#wpTextbox1').get(0);
var startPos = textarea.selectionStart;
var endPos = textarea.selectionEnd;
var selectedText = textarea.value.substring(startPos, endPos);
var newText = "'''" + selectedText + "'''";
var beforeText = textarea.value.substring(0, startPos);
var afterText = textarea.value.substring(endPos, textarea.value.length);
textarea.value = beforeText + newText + afterText;
textarea.setSelectionRange(endPos + 4, endPos + 4);
e.preventDefault();
}
});
});*/
/* show search dropdown results on mobile */
/* by vGhost on wiki.gg */
if ($(window).width() < 1000) {
var $searchInput = $( 'div#simpleSearch #searchInput,div#simpleSearch input' );
$searchInput.on('input',function(e){
//trigger keydown with e object
$(this).trigger(jQuery.Event('keydown', {
keyCode: e.keyCode,
which: e.which,
}));
$(this).trigger(jQuery.Event('keypress', {
keyCode: e.keyCode,
which: e.which,
}));
})
}