MediaWiki:Common.js: Difference between revisions
From Artifacts of Capitalism
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
| Line 19: | Line 19: | ||
document.documentElement.classList.add('aoc-auth'); | document.documentElement.classList.add('aoc-auth'); | ||
document.body.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'); | |||
}); | |||
} | } | ||
}); | }); | ||
Revision as of 23:53, 23 August 2025
// 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');
});
}
});