MediaWiki:Common.js
From Artifacts of Capitalism
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.
// Replace the Chameleon search-box placeholder and button text
$(function() {
// input field
var inp = document.querySelector('#searchInput, input[name="search"]');
if ( inp ) {
inp.placeholder = 'Find an artifact…'; // your new placeholder
}
// submit button (magnifying-glass)
var btn = document.querySelector('#searchButton, button[type="submit"].mw-searchButton');
if ( btn ) {
btn.textContent = 'Go'; // your new label, if you like
}
});
// Tag login + create-account pages so CSS can target reliably
mw.loader.using([]).then(function () {
var sp = mw.config.get('wgCanonicalSpecialPageName');
if (sp === 'Userlogin' || sp === 'CreateAccount') {
document.documentElement.classList.add('aoc-auth');
document.body.classList.add('aoc-auth');
}
});
mw.loader.using(['mediawiki.util'], function () {
function qs(sel){ return document.querySelector(sel); }
var toggler = qs('.p-navbar .navbar-toggler');
var collapse = qs('.p-navbar .navbar-collapse');
var search = qs('.p-navbar #p-search');
// Drawer toggle
if (toggler && collapse) {
toggler.addEventListener('click', function (e) {
e.preventDefault();
var isOpen = collapse.classList.toggle('show');
document.body.classList.toggle('offcanvas-open', isOpen);
});
}
// Click outside drawer to close
document.addEventListener('click', function (e) {
if (!collapse || !collapse.classList.contains('show')) return;
var inside = collapse.contains(e.target) || (toggler && toggler.contains(e.target));
if (!inside) {
collapse.classList.remove('show');
document.body.classList.remove('offcanvas-open');
}
});
// Lightweight search overlay on mobile
if (search) {
var overlay = document.createElement('div');
overlay.className = 'aoc-search-overlay';
overlay.innerHTML = search.innerHTML; // reuse existing search form
document.body.appendChild(overlay);
search.addEventListener('click', function () {
overlay.classList.add('show');
var input = overlay.querySelector('input[type="search"], input[type="text"]');
if (input) setTimeout(function(){ input.focus(); }, 10);
});
// close overlay on submit or outside click/escape
overlay.addEventListener('submit', function(){ overlay.classList.remove('show'); });
document.addEventListener('keydown', function(e){ if (e.key === 'Escape') overlay.classList.remove('show'); });
document.addEventListener('click', function(e){
if (!overlay.classList.contains('show')) return;
if (!overlay.contains(e.target) && !search.contains(e.target)) overlay.classList.remove('show');
});
}
});