Jump to content

MediaWiki:Common.js: Difference between revisions

No edit summary
No edit summary
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. */
$(document).ready(function() {
    // Procura o link de PROBES na sidebar (que tem uma lista debaixo dele)
    $('.mw-sidebar-navigation li, .vector-main-menu li').each(function() {
        var $li = $(this);
        var $nextUl = $li.next('ul'); // Deteta se há sublinks (os 3 asteriscos)
       
        if ($nextUl.length > 0 || $li.find('ul').length > 0) {
            var $subList = $nextUl.length > 0 ? $nextUl : $li.find('ul');
           
            // Esconde os sublinks inicialmente
            $subList.hide();
           
            // Adiciona uma seta clicável antes do texto do link
            var $toggle = $('<span class="menu-toggle-arrow" style="cursor:pointer; margin-right:8px; display:inline-block; transition: transform 0.2s;">▶</span>');
            $li.prepend($toggle);
           
            // Faz com que ao clicar na seta ou no link de PROBES, o menu abra/feche
            $toggle.add($li.children('a')).on('click', function(e) {
                // Se clicou na seta, não deixa o navegador seguir o link '#'
                if ($(e.target).hasClass('menu-toggle-arrow') || $li.children('a').attr('href').indexOf('#') !== -1) {
                    e.preventDefault();
                    $subList.slideToggle('fast');
                   
                    // Roda a seta para baixo quando aberto
                    var isHidden = $subList.is(':hidden');
                    $toggle.css('transform', isHidden ? 'rotate(0deg)' : 'rotate(90deg)');
                }
            });
        }
    });
});