MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| (23 intermediate revisions by the same user not shown) | |||
| Line 2: | Line 2: | ||
// Força o menu lateral a expandir (Vector 2022) se estiver colapsado | |||
mw.hook('wikipage.content').add(function () { | |||
if (document.documentElement.classList.contains('vector-feature-main-menu-pinned-disabled')) { | |||
var pinButton = document.getElementById('vector-main-menu-dropdown-checkbox'); | |||
if (pinButton) { | |||
// Remove a classe de desativado e força o estado expandido | |||
document.documentElement.classList.remove('vector-feature-main-menu-pinned-disabled'); | |||
document.documentElement.classList.add('vector-feature-main-menu-pinned-enabled'); | |||
} | |||
} | |||
}); | |||
// Força o MediaWiki a carregar os módulos básicos em qualquer tipo de sessão (anónima ou registada) | |||
mw.loader.using(['mediawiki.util', 'jquery'], function () { | |||
function setupAtlasDropdown() { | |||
// Alvo exclusivo: Apenas o menu de navegação da skin, ignorando o índice de conteúdos (Contents) da página | |||
var $sidebar = $('.vector-main-menu, #mw-panel'); | |||
if (!$sidebar.length) return; | |||
// 1. Identifica e esconde as subpáginas apenas no menu lateral | |||
$sidebar.find('li').each(function() { | |||
var $li = $(this); | |||
var text = $li.text().trim(); | |||
// Verifica se apanha as subpáginas pelo URL ou pelo texto exato | |||
var hasSubpage = $li.find('a[href*="SENSBLUE_ATLAS/"], .mw-selflink[href*="SENSBLUE_ATLAS/"]').length > 0 | |||
|| text === 'Datasheet' | |||
|| text === 'Release Notes'; | |||
if (hasSubpage && !text.includes('SENSBLUE ATLAS')) { | |||
$li.addClass('atlas-submenu'); | |||
} | |||
}); | |||
// 2. Procura o item pai (SENSBLUE ATLAS) na barra lateral | |||
var $mainAtlasLi = $sidebar.find('li').filter(function() { | |||
var text = $(this).clone().children().remove().end().text().trim() || $(this).text().trim(); | |||
return text === 'SENSBLUE ATLAS'; | |||
}).first(); | |||
// 3. Injeta a seta nativa se encontrar o link | |||
if ($mainAtlasLi.length && !$mainAtlasLi.find('.atlas-toggle-btn').length) { | |||
$mainAtlasLi.css({ | |||
'display': 'flex', | |||
'align-items': 'center', | |||
'justify-content': 'flex-start' | |||
}); | |||
$mainAtlasLi.find('a, .mw-selflink, span').css({ | |||
'display': 'inline', | |||
'width': 'auto' | |||
}); | |||
var $toggleBtn = $('<span class="atlas-toggle-btn"></span>'); | |||
$mainAtlasLi.append($toggleBtn); | |||
$toggleBtn.on('click', function(e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
$('.atlas-submenu').toggleClass('is-open'); | |||
$(this).toggleClass('is-active'); | |||
}); | |||
} | |||
} | |||
// GATILHO COMPATÍVEL COM ANÓNIMOS: Executa em múltiplos estágios do carregamento | |||
$(document).ready(setupAtlasDropdown); | |||
$(window).on('load', setupAtlasDropdown); | |||
mw.hook('wikipage.content').add(setupAtlasDropdown); | |||
}); | |||
// ========================================================================== | |||
// CONTROLADOR DE DROPDOWN NO ÍNDICE (TOC) - VERSÃO VISUAL FINAL | |||
// ========================================================================== | // ========================================================================== | ||
$('.vector-toc-contents .vector-toc-list .vector-toc-list-item').each(function() { | |||
$(' | |||
var $listItem = $(this); | var $listItem = $(this); | ||
// | // Proteção total ao cabeçalho global | ||
if ($listItem.find('#vector-toc-collapsed-button').length > 0 || $listItem.hasClass('vector-toc-title')) { | if ($listItem.find('.vector-toc-title, #vector-toc-collapsed-button, .vector-toc-header').length > 0 || $listItem.hasClass('vector-toc-title')) { | ||
return; | return; | ||
} | } | ||
var $subList = $listItem.children(' | var $subList = $listItem.children('.vector-toc-list, ul'); | ||
// Só | // Só injeta o botão se contiver subcapítulos | ||
if ($subList.length > 0 && $subList.children(' | if ($subList.length > 0 && $subList.children('.vector-toc-list-item, li').length > 0) { | ||
if ($listItem.children('.toc-toggle-arrow').length === 0) { | if ($listItem.children('.toc-toggle-arrow').length === 0) { | ||
var $arrow = $('<span class="toc-toggle-arrow"> | // Injeta o container da seta preparado para renderizar o SVG do CSS | ||
var $arrow = $('<span class="toc-toggle-arrow"><span class="arrow-icon"></span></span>'); | |||
$arrow.click(function(e) { | $arrow.click(function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
| Line 33: | Line 107: | ||
}); | }); | ||
$listItem.prepend($arrow); | $listItem.prepend($arrow); | ||
} | } | ||