MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| (37 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
// 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 () { | |||
// Lista de secções principais com subpáginas. | |||
// Para adicionares uma nova secção no futuro, basta acrescentar o nome aqui. | |||
var sidebarSections = ['SENSBLUE MONARCH', 'SENSBLUE ATLAS']; | |||
function setupSidebarDropdowns() { | |||
// 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; | |||
sidebarSections.forEach(function (sectionName) { | |||
var slug = sectionName.replace(/ /g, '_'); | |||
// 1. Identifica as subpáginas desta secção pelo URL (funciona para qualquer subpágina, incluindo novas) | |||
$sidebar.find('li').each(function () { | |||
var $li = $(this); | |||
var $link = $li.find('a, .mw-selflink').first(); | |||
var href = $link.attr('href') || ''; | |||
var isSubpage = href.indexOf(slug + '/') !== -1; | |||
if (isSubpage) { | |||
$li.addClass('wiki-submenu').attr('data-group', slug); | |||
} | |||
}); | |||
// 2. Procura o item pai (ex: "SENSBLUE MONARCH") na barra lateral | |||
var $parentLi = $sidebar.find('li').filter(function () { | |||
var text = $(this).clone().children().remove().end().text().trim() || $(this).text().trim(); | |||
return text === sectionName; | |||
}).first(); | |||
// 3. Injeta a seta nativa se encontrar o link e ainda não a tiver | |||
if ($parentLi.length && !$parentLi.find('.wiki-toggle-btn').length) { | |||
$parentLi.css({ | |||
'display': 'flex', | |||
'align-items': 'center', | |||
'justify-content': 'flex-start' | |||
}); | |||
$parentLi.find('a, .mw-selflink, span').css({ | |||
'display': 'inline', | |||
'width': 'auto' | |||
}); | |||
var $toggleBtn = $('<span class="wiki-toggle-btn"></span>'); | |||
$parentLi.append($toggleBtn); | |||
$toggleBtn.on('click', function (e) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
$sidebar.find('.wiki-submenu[data-group="' + slug + '"]').toggleClass('is-open'); | |||
$(this).toggleClass('is-active'); | |||
}); | |||
} | |||
}); | |||
} | |||
// GATILHO COMPATÍVEL COM ANÓNIMOS: Executa em múltiplos estágios do carregamento | |||
$(document).ready(setupSidebarDropdowns); | |||
$(window).on('load', setupSidebarDropdowns); | |||
mw.hook('wikipage.content').add(setupSidebarDropdowns); | |||
}); | |||
// ========================================================================== | |||
// 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); | |||
// Proteção total ao cabeçalho global | |||
if ($listItem.find('.vector-toc-title, #vector-toc-collapsed-button, .vector-toc-header').length > 0 || $listItem.hasClass('vector-toc-title')) { | |||
return; | |||
} | |||
var $subList = $listItem.children('.vector-toc-list, ul'); | |||
// Só injeta o botão se contiver subcapítulos | |||
if ($subList.length > 0 && $subList.children('.vector-toc-list-item, li').length > 0) { | |||
if ($listItem.children('.toc-toggle-arrow').length === 0) { | |||
// 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) { | |||
e.preventDefault(); | |||
e.stopPropagation(); | |||
$listItem.toggleClass('toc-expanded'); | |||
}); | |||
$listItem.prepend($arrow); | |||
} | |||
} | |||
}); | |||
// 2. LÓGICA DA SETA (ALL MODELS) | |||
// Deteta o clique no contentor nativo do MediaWiki que criaste | |||
$('.variations-toggle').css('cursor', 'pointer').click(function() { | |||
// Encontra a seta com a classe .arrow-icon dentro do bloco clicado | |||
var $arrow = $(this).find('.arrow-icon'); | |||
// Alterna a classe de rotação configurada no CSS | |||
$arrow.toggleClass('rotated'); | |||
}); | |||
| Line 86: | Line 216: | ||
'<a '+linkStyle+' href="https://atronia.eu/hardware/monarch/" target="_blank">Monarch</a>' + | '<a '+linkStyle+' href="https://atronia.eu/hardware/monarch/" target="_blank">Monarch</a>' + | ||
'<a '+linkStyle+' href="https://atronia.eu/hardware/atlas/" target="_blank">Atlas</a>' + | '<a '+linkStyle+' href="https://atronia.eu/hardware/atlas/" target="_blank">Atlas</a>' + | ||
'<a '+linkStyle+' | '<a '+linkStyle+' target="_blank">Probes</a>' + | ||
'<a '+linkStyle+' | '<a '+linkStyle+' target="_blank">Accessories</a>' + | ||
'</div>' + | '</div>' + | ||
'<div><h4 '+titleStyle+'>Solutions</h4>' + | '<div><h4 '+titleStyle+'>Solutions</h4>' + | ||