MediaWiki:Common.js
MediaWiki interface page
More actions
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)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
/* Main page: the big "Search" button opens the skin's search box. */
( function () {
if ( !mw.config.get( 'wgIsMainPage' ) ) {
return;
}
mw.hook( 'wikipage.content' ).add( function () {
var trigger = document.getElementById( 'fw-mainpage-search-trigger' );
var input = document.getElementById( 'searchInput' );
if ( !trigger || !input ) {
return;
}
function openSearch() {
if ( mw.config.get( 'skin' ) === 'citizen' ) {
/* Citizen hides the header while scrolling down; bring it back. */
if ( document.body.classList.contains( 'citizen-scroll--down' ) ) {
document.body.classList.remove( 'citizen-scroll--down' );
document.body.classList.add( 'citizen-scroll--up' );
}
/* Citizen's search lives in a collapsed panel and focuses the input when opened. */
var details = document.getElementById( 'citizen-search-details' );
if ( details ) {
details.open = true;
return;
}
}
input.focus();
}
trigger.addEventListener( 'click', openSearch );
trigger.addEventListener( 'keydown', function ( e ) {
if ( e.key === 'Enter' || e.key === ' ' ) {
e.preventDefault();
openSearch();
}
} );
} );
}() );