MediaWiki:Common.js: Difference between revisions
(Auto-pin sidebar navigation via Soulscribe) |
(Auto-pin sidebar navigation via Soulscribe) |
||
| Line 11: | Line 11: | ||
/* ── Relationship table live filter ────────────────────────────────── */ | /* ── Relationship table live filter ────────────────────────────────── */ | ||
/* | /* Injects a filter input before each .wb-relationship-table and */ | ||
/* hides/shows rows as the user types. Input is injected via JS */ | |||
/* because MediaWiki strips <input> elements from wikitext. */ | |||
( function () { | ( function () { | ||
function initFilters() { | function initFilters() { | ||
document.querySelectorAll( '.wb- | document.querySelectorAll( 'table.wb-relationship-table' ).forEach( function ( table ) { | ||
if ( table.previousElementSibling && table.previousElementSibling.classList.contains( 'wb-rel-filter-wrap' ) ) { | |||
return; // already injected | |||
var | } | ||
var wrap = document.createElement( 'div' ); | |||
wrap.className = 'wb-rel-filter-wrap'; | |||
var input = document.createElement( 'input' ); | |||
input.className = 'wb-rel-filter'; | |||
input.type = 'search'; | |||
input.placeholder = 'Filter by name or type…'; | |||
wrap.appendChild( input ); | |||
table.parentNode.insertBefore( wrap, table ); | |||
input.addEventListener( 'input', function () { | input.addEventListener( 'input', function () { | ||
var q = input.value.toLowerCase().trim(); | var q = input.value.toLowerCase().trim(); | ||
Latest revision as of 08:32, 28 April 2026
/* Soulscribe — auto-generated, do not edit manually */
/* ── Auto-pin the main navigation menu to the left sidebar on desktop ── */
( function () {
if ( window.innerWidth < 1000 ) { return; }
var pinBtn = document.querySelector(
'.vector-pinnable-header-pin-button[data-event-name="pinnable-header.vector-main-menu.pin"]'
);
if ( pinBtn ) { pinBtn.click(); }
}() );
/* ── Relationship table live filter ────────────────────────────────── */
/* Injects a filter input before each .wb-relationship-table and */
/* hides/shows rows as the user types. Input is injected via JS */
/* because MediaWiki strips <input> elements from wikitext. */
( function () {
function initFilters() {
document.querySelectorAll( 'table.wb-relationship-table' ).forEach( function ( table ) {
if ( table.previousElementSibling && table.previousElementSibling.classList.contains( 'wb-rel-filter-wrap' ) ) {
return; // already injected
}
var wrap = document.createElement( 'div' );
wrap.className = 'wb-rel-filter-wrap';
var input = document.createElement( 'input' );
input.className = 'wb-rel-filter';
input.type = 'search';
input.placeholder = 'Filter by name or type…';
wrap.appendChild( input );
table.parentNode.insertBefore( wrap, table );
input.addEventListener( 'input', function () {
var q = input.value.toLowerCase().trim();
var rows = table.querySelectorAll( 'tbody tr' );
rows.forEach( function ( row ) {
var text = row.textContent.toLowerCase();
row.style.display = ( !q || text.indexOf( q ) !== -1 ) ? '' : 'none';
} );
} );
} );
}
if ( document.readyState === 'loading' ) {
document.addEventListener( 'DOMContentLoaded', initFilters );
} else {
initFilters();
}
}() );