MediaWiki:Common.js: Difference between revisions
(Auto-pin sidebar navigation via Soulscribe) |
(Auto-pin sidebar navigation via Soulscribe) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
/* Soulscribe — auto-generated, do not edit manually */ | /* Soulscribe — auto-generated, do not edit manually */ | ||
/* Auto-pin the main navigation menu to the left sidebar on desktop | |||
/* ── Auto-pin the main navigation menu to the left sidebar on desktop ── */ | |||
( function () { | ( function () { | ||
if ( window.innerWidth < 1000 ) { return; } | if ( window.innerWidth < 1000 ) { return; } | ||
var pinBtn = document.querySelector( | var pinBtn = document.querySelector( | ||
'.vector-pinnable-header-pin-button[data-event-name="pinnable-header.vector-main-menu.pin"]' | '.vector-pinnable-header-pin-button[data-event-name="pinnable-header.vector-main-menu.pin"]' | ||
); | ); | ||
if ( pinBtn ) { pinBtn.click(); } | 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(); | |||
} | |||
}() ); | }() ); | ||
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();
}
}() );