MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary Tag: Reverted |
||
| Line 2: | Line 2: | ||
// | /* Transforma títulos de secção da sidebar em links clicáveis com acordeão independente */ | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
var mapping = { | |||
var | 'SENSBLUE MONARCH': '/wiki/SENSBLUE_MONARCH', | ||
if ( | 'SENSBLUE ATLAS': '/wiki/SENSBLUE_ATLAS' | ||
// | }; | ||
var groups = document.querySelectorAll('.vector-main-menu-group'); | |||
groups.forEach(function (group) { | |||
var labelSpan = group.querySelector('.vector-menu-heading-label'); | |||
var content = group.querySelector('.vector-menu-content'); | |||
if (labelSpan && content && !labelSpan.dataset.linkInit) { | |||
labelSpan.dataset.linkInit = "true"; | |||
var text = labelSpan.textContent.trim(); | |||
if (mapping[text]) { | |||
// 1. Converte o texto do cabeçalho num link direto | |||
labelSpan.innerHTML = '<a href="' + mapping[text] + '" style="color: inherit; text-decoration: none;">' + text + '</a>'; | |||
// 2. Cria o ícone/botão toggle de expandir ao lado | |||
var toggleBtn = document.createElement('span'); | |||
toggleBtn.innerHTML = ' ▾'; // Seta para baixo | |||
toggleBtn.style.cursor = 'pointer'; | |||
toggleBtn.style.paddingLeft = '8px'; | |||
labelSpan.appendChild(toggleBtn); | |||
// 3. Controla a expansão/recolhimento apenas neste bloco | |||
content.style.display = 'none'; // Começa recolhido | |||
toggleBtn.addEventListener('click', function (e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
var isHidden = content.style.display === 'none'; | |||
content.style.display = isHidden ? 'block' : 'none'; | |||
toggleBtn.innerHTML = isHidden ? ' ▴' : ' ▾'; | |||
}); | |||
} | |||
} | } | ||
} | }); | ||
}); | }); | ||