MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary Tag: Reverted |
||
Line 1: | Line 1: | ||
/* Collapsible sidebar | /* Debugging: Collapsible sidebar for Vector & Vector 2022 */ | ||
var COLLAPSIBLE_SECTIONS = [ 'book1', 'book2' ]; | var COLLAPSIBLE_SECTIONS = ['book1', 'book2']; | ||
var DEFAULT_OPEN = false; | var DEFAULT_OPEN = false; | ||
Line 7: | Line 7: | ||
function initCollapsiblePortlet(name) { | function initCollapsiblePortlet(name) { | ||
var portal = document.getElementById('p-' + name); | var portal = document.getElementById('p-' + name); | ||
if (!portal) return; | if (!portal) { | ||
console.warn('CollapsibleSidebar: Portal not found for', name); | |||
return; | |||
} | |||
// | // Try multiple selectors for compatibility | ||
var heading = portal.querySelector('.vector-menu-heading, h3'); | var heading = portal.querySelector('.vector-menu-heading, h3'); | ||
var content = portal.querySelector('.vector-menu-content, .body'); | var content = portal.querySelector('.vector-menu-content, .body'); | ||
if (!heading | |||
if (!heading) { | |||
console.warn('CollapsibleSidebar: Heading not found in portal', name, portal); | |||
return; | |||
} | |||
if (!content) { | |||
console.warn('CollapsibleSidebar: Content not found in portal', name, portal); | |||
return; | |||
} | |||
console.log('CollapsibleSidebar: Initializing portal', name); | |||
portal.classList.add('mw-custom-collapsible'); | portal.classList.add('mw-custom-collapsible'); | ||
Line 23: | Line 36: | ||
function setState(open) { | function setState(open) { | ||
console.log('CollapsibleSidebar: Setting state', name, open); | |||
portal.classList.toggle('is-open', open); | portal.classList.toggle('is-open', open); | ||
heading.setAttribute('aria-expanded', open ? 'true' : 'false'); | heading.setAttribute('aria-expanded', open ? 'true' : 'false'); | ||
Line 30: | Line 44: | ||
// Accessibility & click events | // Accessibility & click events | ||
Revision as of 15:06, 24 August 2025
/* Debugging: Collapsible sidebar for Vector & Vector 2022 */ var COLLAPSIBLE_SECTIONS = ['book1', 'book2']; var DEFAULT_OPEN = false; mw.loader.using(['mediawiki.util']).then(function () { function initCollapsiblePortlet(name) { var portal = document.getElementById('p-' + name); if (!portal) { console.warn('CollapsibleSidebar: Portal not found for', name); return; } // Try multiple selectors for compatibility var heading = portal.querySelector('.vector-menu-heading, h3'); var content = portal.querySelector('.vector-menu-content, .body'); if (!heading) { console.warn('CollapsibleSidebar: Heading not found in portal', name, portal); return; } if (!content) { console.warn('CollapsibleSidebar: Content not found in portal', name, portal); return; } console.log('CollapsibleSidebar: Initializing portal', name); portal.classList.add('mw-custom-collapsible'); // Get saved state var storageKey = 'mwSidebar:' + name; var stored = null; try { stored = localStorage.getItem(storageKey); } catch (e) {} var isOpen = stored === null ? DEFAULT_OPEN : stored === '1'; function setState(open) { console.log('CollapsibleSidebar: Setting state', name, open); portal.classList.toggle('is-open', open); heading.setAttribute('aria-expanded', open ? 'true' : 'false'); content.style.display = open ? '' : 'none'; try { localStorage.setItem(storageKey, open ? '1' : '0'); } catch (e) {} } // Accessibility & click events