Jump to content

MediaWiki:Common.js: Difference between revisions

No edit summary
Tag: Reverted
No edit summary
 
(2 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. */


/* 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
// Força o menu lateral a expandir (Vector 2022) se estiver colapsado
Line 19: Line 17:
// Força o MediaWiki a carregar os módulos básicos em qualquer tipo de sessão (anónima ou registada)
// 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 () {
mw.loader.using(['mediawiki.util', 'jquery'], function () {
      
 
     function setupAtlasDropdown() {
    // 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
         // 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');
         var $sidebar = $('.vector-main-menu, #mw-panel');
         if (!$sidebar.length) return;
         if (!$sidebar.length) return;


         // 1. Identifica e esconde as subpáginas apenas no menu lateral
         sidebarSections.forEach(function (sectionName) {
        $sidebar.find('li').each(function() {
             var slug = sectionName.replace(/ /g, '_');
             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
            // 1. Identifica as subpáginas desta secção pelo URL (funciona para qualquer subpágina, incluindo novas)
        var $mainAtlasLi = $sidebar.find('li').filter(function() {
            $sidebar.find('li').each(function () {
            var text = $(this).clone().children().remove().end().text().trim() || $(this).text().trim();
                var $li = $(this);
            return text === 'SENSBLUE ATLAS';
                var $link = $li.find('a, .mw-selflink').first();
        }).first();
                var href = $link.attr('href') || '';
                var isSubpage = href.indexOf(slug + '/') !== -1;


        // 3. Injeta a seta nativa se encontrar o link
                if (isSubpage) {
        if ($mainAtlasLi.length && !$mainAtlasLi.find('.atlas-toggle-btn').length) {
                    $li.addClass('wiki-submenu').attr('data-group', slug);
           
                 }
            $mainAtlasLi.css({
                'display': 'flex',
                'align-items': 'center',
                 'justify-content': 'flex-start'
             });
             });


             $mainAtlasLi.find('a, .mw-selflink, span').css({
             // 2. Procura o item pai (ex: "SENSBLUE MONARCH") na barra lateral
                'display': 'inline',
            var $parentLi = $sidebar.find('li').filter(function () {
                'width': 'auto'
                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);


            var $toggleBtn = $('<span class="atlas-toggle-btn"></span>');
                $toggleBtn.on('click', function (e) {
            $mainAtlasLi.append($toggleBtn);  
                    e.preventDefault();
                    e.stopPropagation();


            $toggleBtn.on('click', function(e) {
                    $sidebar.find('.wiki-submenu[data-group="' + slug + '"]').toggleClass('is-open');
                e.preventDefault();
                    $(this).toggleClass('is-active');
                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
     // GATILHO COMPATÍVEL COM ANÓNIMOS: Executa em múltiplos estágios do carregamento
     $(document).ready(setupAtlasDropdown);
     $(document).ready(setupSidebarDropdowns);
     $(window).on('load', setupAtlasDropdown);
     $(window).on('load', setupSidebarDropdowns);
     mw.hook('wikipage.content').add(setupAtlasDropdown);
     mw.hook('wikipage.content').add(setupSidebarDropdowns);
});
});