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. */
(function () {
var pageName = mw.config.get("wgPageName");
var skin = mw.config.get("skin");
var isMainPage = mw.config.get("wgIsMainPage");
function onMainPage() {
var searchTrigger = document.getElementById(
"tg-mainpage-search-trigger"
);
var searchInput = document.getElementById("searchInput");
var searchToggle;
function onSearchTriggerClick() {
if (skin === "citizen") {
// HACK: Force sticky header to be visible
var isSearchHidden =
document.body.classList.contains("citizen-scroll--down") &&
window.matchMedia("(max-width: 1119px)");
if (isSearchHidden) {
document.body.classList.remove("citizen-scroll--down");
document.body.classList.add("citizen-scroll--up");
}
// Citizen does not have a visible search bar, you need to expand the search card first
// And Citizen will focus the input automatically
searchToggle.open = true;
} else {
// This should work for all skins that has visible search bar
searchInput.focus();
}
}
// Attach click event listener to search button on the main page
if (searchTrigger && searchInput) {
if (skin === "citizen") {
searchToggle = document.getElementById("citizen-search-details");
}
searchTrigger.addEventListener("click", onSearchTriggerClick);
}
}
function init() {
// Wait for page content to be fully loaded
mw.hook("wikipage.content").add(function () {
if (isMainPage) {
onMainPage();
}
});
}
init();
})();