MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary Tag: Reverted |
No edit summary |
||
| (20 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. */ | ||
/* Widget de Tradução GTranslate */ | |||
$(document).ready(function() { | |||
if ($('#p-navigation').length) { | |||
if (!$('.gtranslate_wrapper').length) { | |||
$('#p-navigation').prepend('<div class="gtranslate_wrapper"></div>'); | |||
} | |||
window.gtranslateSettings = { | |||
"default_language": "en", | |||
"languages": ["en", "pt", "es", "fr", "de", "it", "nl", "pl", "ja"], | |||
"wrapper_selector": ".gtranslate_wrapper" | |||
}; | |||
$.getScript('https://cdn.gtranslate.net/widgets/latest/dropdown.js'); | |||
} | |||
}); | |||
// Buy now novo separador | |||
$(document).ready(function () { | |||
$('.button-buy-now a').attr('target', '_blank').attr('rel', 'noopener noreferrer'); | |||
}); | |||
// 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 25: | Line 49: | ||
function setupSidebarDropdowns() { | 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'); | var $sidebar = $('.vector-main-menu, #mw-panel'); | ||
if (!$sidebar.length) return; | if (!$sidebar.length) return; | ||
| Line 31: | Line 56: | ||
var slug = sectionName.replace(/ /g, '_'); | var slug = sectionName.replace(/ /g, '_'); | ||
// 1. | // 1. Identifica as subpáginas desta secção pelo URL (funciona para qualquer subpágina, incluindo novas) | ||
$sidebar.find('li').each(function () { | $sidebar.find('li').each(function () { | ||
var $li = $(this); | var $li = $(this); | ||
| Line 43: | Line 68: | ||
}); | }); | ||
// 2. | // 2. Procura o item pai (ex: "SENSBLUE MONARCH") na barra lateral | ||
var $parentLi = $sidebar.find('li').filter(function () { | var $parentLi = $sidebar.find('li').filter(function () { | ||
var text = $(this).clone().children().remove().end().text().trim() || $(this).text().trim(); | var text = $(this).clone().children().remove().end().text().trim() || $(this).text().trim(); | ||
| Line 49: | Line 74: | ||
}).first(); | }).first(); | ||
// 3. Injeta o | // 3. Injeta a seta nativa se encontrar o link e ainda não a tiver | ||
if ($parentLi.length && !$parentLi.find('.wiki-toggle-btn').length) { | if ($parentLi.length && !$parentLi.find('.wiki-toggle-btn').length) { | ||
$parentLi.css({ | $parentLi.css({ | ||
'display': 'flex', | 'display': 'flex', | ||
| Line 56: | Line 82: | ||
'justify-content': 'flex-start' | 'justify-content': 'flex-start' | ||
}); | }); | ||
$parentLi.find('a, .mw-selflink, span').css({ | $parentLi.find('a, .mw-selflink, span').css({ | ||
'display': 'inline', | 'display': 'inline', | ||
| Line 67: | Line 94: | ||
e.preventDefault(); | e.preventDefault(); | ||
e.stopPropagation(); | e.stopPropagation(); | ||
$sidebar.find('.wiki-submenu[data-group="' + slug + '"]').toggleClass('is-open'); | $sidebar.find('.wiki-submenu[data-group="' + slug + '"]').toggleClass('is-open'); | ||
$(this).toggleClass('is-active'); | $(this).toggleClass('is-active'); | ||
| Line 74: | Line 102: | ||
} | } | ||
// GATILHO COMPATÍVEL COM ANÓNIMOS: Executa em múltiplos estágios do carregamento | |||
$(document).ready(setupSidebarDropdowns); | $(document).ready(setupSidebarDropdowns); | ||
$(window).on('load', setupSidebarDropdowns); | $(window).on('load', setupSidebarDropdowns); | ||
mw.hook('wikipage.content').add(setupSidebarDropdowns); | mw.hook('wikipage.content').add(setupSidebarDropdowns); | ||
}); | }); | ||