MediaWiki:Common.js

From Adventure Koala

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)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* 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();
  }
}() );