MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
// ========================================================================== | // ========================================================================== | ||
// CONTROLADOR DE DROPDOWN | // CONTROLADOR DE DROPDOWN INDEPENDENTE NO ÍNDICE (TOC) | ||
// ========================================================================== | // ========================================================================== | ||
// | // Almeja apenas os itens de lista internos, protegendo o cabeçalho global | ||
$('.vector-toc-list-item').each(function() { | $('.vector-toc-contents .vector-toc-list .vector-toc-list-item').each(function() { | ||
var $listItem = $(this); | var $listItem = $(this); | ||
var $subList = $listItem.children('.vector-toc-list'); | var $subList = $listItem.children('.vector-toc-list'); | ||
// | // Valida se o item tem subcapítulos reais com conteúdo | ||
if ($subList.length > 0 && $subList.children('.vector-toc-list-item').length > 0) { | if ($subList.length > 0 && $subList.children('.vector-toc-list-item').length > 0) { | ||
// | // Cria a seta apenas se ela ainda não existir nesta linha | ||
if ($ | if ($listItem.children('.toc-toggle-arrow').length === 0) { | ||
var $arrow = $('<span class="toc-toggle-arrow">▶</span>'); | var $arrow = $('<span class="toc-toggle-arrow">▶</span>'); | ||
// Evento focado puramente na ação de expandir/recolher a árvore | |||
$arrow.click(function(e) { | $arrow.click(function(e) { | ||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
$listItem.toggleClass('toc-expanded'); | $listItem.toggleClass('toc-expanded'); | ||
}); | }); | ||
// Adiciona a seta | // IMPORTANTE: Adiciona a seta ANTES do link, solta no item de lista | ||
$ | $listItem.prepend($arrow); | ||
} | } | ||
} | } | ||