Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
(43 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
− | $(document).on('click', '.warp-copy', function() { | + | // Função única para cópia de texto |
+ | $(document).on('click', '.warp-copy', function(e) { | ||
+ | e.preventDefault(); | ||
var textToCopy = $(this).attr('data-copy'); | var textToCopy = $(this).attr('data-copy'); | ||
+ | // Cria elemento temporário para cópia | ||
var tempInput = document.createElement('textarea'); | var tempInput = document.createElement('textarea'); | ||
tempInput.value = textToCopy; | tempInput.value = textToCopy; | ||
Line 12: | Line 15: | ||
document.body.removeChild(tempInput); | document.body.removeChild(tempInput); | ||
− | var | + | // Adiciona classe para feedback visual |
− | $ | + | var $element = $(this); |
− | + | $element.addClass('copied'); | |
setTimeout(function() { | setTimeout(function() { | ||
− | $ | + | $element.removeClass('copied'); |
− | }, | + | }, 2000); |
}); | }); | ||
− | |||
− | / | + | // Adicionar funcionalidade às imagens dos NPCs |
− | $( | + | function initImageCopy() { |
+ | $('.tile-top.tile-image a').each(function() { | ||
+ | var $link = $(this); | ||
+ | if (!$link.hasClass('warp-copy')) { | ||
+ | var npcId = $link.attr('href').replace('#',''); | ||
+ | $link.addClass('warp-copy') | ||
+ | .attr('data-copy', '@warp ' + npcId) | ||
+ | .css('cursor', 'pointer'); | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | // Função corrigida para aplicar larguras e alturas aos containers, não às imagens | ||
+ | function fixNpcContainerWidths() { | ||
+ | $('.contents-equipment.tile-halves').each(function() { | ||
+ | var $container = $(this); | ||
+ | var width = $container.data('width'); | ||
+ | |||
+ | if (width && width > 0) { | ||
+ | $container.css({ | ||
+ | '--container-width': width + 'px' | ||
+ | }); | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | // Aplicar altura aos containers de imagem, não às próprias imagens | ||
+ | $('.tile-top.tile-image').each(function() { | ||
+ | var $imageContainer = $(this); | ||
+ | var height = $imageContainer.css('--image-height'); | ||
+ | |||
+ | if (height && height !== 'auto') { | ||
+ | $imageContainer.css('height', height); | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | // Inicializar funções ao carregar e em atualizações de conteúdo | ||
+ | initImageCopy(); | ||
+ | fixNpcContainerWidths(); | ||
+ | |||
+ | if (typeof mw !== 'undefined' && mw.hook) { | ||
+ | mw.hook('wikipage.content').add(function() { | ||
+ | initImageCopy(); | ||
+ | fixNpcContainerWidths(); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | /* Auto-expand sections when clicking anchored links */ | ||
console.log("Inicializando script para expandir seções com links âncora"); | console.log("Inicializando script para expandir seções com links âncora"); | ||
Line 28: | Line 77: | ||
if (window.location.hash) { | if (window.location.hash) { | ||
console.log("Página carregada com hash: " + window.location.hash); | console.log("Página carregada com hash: " + window.location.hash); | ||
− | |||
setTimeout(function() { | setTimeout(function() { | ||
expandSectionForAnchor(window.location.hash); | expandSectionForAnchor(window.location.hash); | ||
Line 34: | Line 82: | ||
} | } | ||
− | // Handle clicks on anchor links | + | // Handle clicks on anchor links |
$(document).on('click', 'a[href^="#"]', function(event) { | $(document).on('click', 'a[href^="#"]', function(event) { | ||
var hash = $(this).attr('href'); | var hash = $(this).attr('href'); | ||
console.log("Clique em link âncora: " + hash); | console.log("Clique em link âncora: " + hash); | ||
− | |||
event.preventDefault(); | event.preventDefault(); | ||
− | |||
if (history.pushState) { | if (history.pushState) { | ||
history.pushState(null, null, hash); | history.pushState(null, null, hash); | ||
Line 51: | Line 97: | ||
}); | }); | ||
− | |||
function expandSectionForAnchor(hash) { | function expandSectionForAnchor(hash) { | ||
console.log("Procurando e expandindo seção para âncora: " + hash); | console.log("Procurando e expandindo seção para âncora: " + hash); | ||
− | |||
var targetElement = $(hash); | var targetElement = $(hash); | ||
Line 60: | Line 104: | ||
console.log("Elemento alvo encontrado"); | console.log("Elemento alvo encontrado"); | ||
− | |||
− | |||
var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed'); | var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed'); | ||
+ | var directCollapsible = targetElement.closest('.mw-collapsible.mw-collapsed'); | ||
− | |||
− | |||
if (directCollapsible.length) { | if (directCollapsible.length) { | ||
collapsibleSections = collapsibleSections.add(directCollapsible); | collapsibleSections = collapsibleSections.add(directCollapsible); | ||
Line 72: | Line 113: | ||
console.log("Seções colapsáveis encontradas: " + collapsibleSections.length); | console.log("Seções colapsáveis encontradas: " + collapsibleSections.length); | ||
− | |||
if (collapsibleSections.length > 0) { | if (collapsibleSections.length > 0) { | ||
collapsibleSections.each(function() { | collapsibleSections.each(function() { | ||
Line 78: | Line 118: | ||
console.log("Expandindo seção colapsável"); | console.log("Expandindo seção colapsável"); | ||
− | |||
section.removeClass('mw-collapsed'); | section.removeClass('mw-collapsed'); | ||
− | |||
− | |||
var toggleButton = section.find('.mw-collapsible-toggle').first(); | var toggleButton = section.find('.mw-collapsible-toggle').first(); | ||
if (toggleButton.length) { | if (toggleButton.length) { | ||
Line 88: | Line 125: | ||
} | } | ||
− | |||
if (section.hasClass('wikitable')) { | if (section.hasClass('wikitable')) { | ||
console.log("Expandindo tabela wikitable"); | console.log("Expandindo tabela wikitable"); | ||
Line 94: | Line 130: | ||
} | } | ||
− | |||
section.find('.mw-collapsible-content').show(); | section.find('.mw-collapsible-content').show(); | ||
}); | }); | ||
− | |||
setTimeout(function() { | setTimeout(function() { | ||
scrollToTarget(targetElement); | scrollToTarget(targetElement); | ||
}, 400); | }, 400); | ||
} else { | } else { | ||
− | |||
scrollToTarget(targetElement); | scrollToTarget(targetElement); | ||
} | } | ||
Line 111: | Line 144: | ||
} | } | ||
− | |||
function scrollToTarget(element) { | function scrollToTarget(element) { | ||
console.log("Rolando até o elemento alvo"); | console.log("Rolando até o elemento alvo"); | ||
Line 119: | Line 151: | ||
} | } | ||
− | |||
if (typeof mw !== 'undefined' && mw.hook) { | if (typeof mw !== 'undefined' && mw.hook) { | ||
mw.hook('wikipage.content').add(function() { | mw.hook('wikipage.content').add(function() { | ||
Line 132: | Line 163: | ||
}); | }); | ||
− | /* | + | /* Código JavaScript limpo para os NPCs - MANTER APENAS ESTE BLOCO */ |
− | $(function() { | + | $(document).ready(function() { |
− | // | + | // Manipulador de clique direto nos containers NPC |
− | function | + | $(document).on('click', '.contents-equipment.tile-halves', function(e) { |
− | + | // Previne comportamento padrão apenas se não for um link | |
− | // | + | if (!$(e.target).is('a') && !$(e.target).parents('a').length) { |
− | $('. | + | e.preventDefault(); |
− | var | + | } |
− | var | + | |
+ | // Encontra o comando warp dentro do container | ||
+ | var $warpElement = $(this).find('.warp-copy[data-copy^="@warp"]'); | ||
+ | |||
+ | if ($warpElement.length) { | ||
+ | var warpCommand = $warpElement.attr('data-copy'); | ||
+ | |||
+ | // Copia o texto para a área de transferência | ||
+ | var tempInput = document.createElement('textarea'); | ||
+ | tempInput.value = warpCommand; | ||
+ | document.body.appendChild(tempInput); | ||
+ | tempInput.select(); | ||
+ | document.execCommand('copy'); | ||
+ | document.body.removeChild(tempInput); | ||
− | // | + | // Adiciona classe para feedback visual |
− | + | var $container = $(this); | |
+ | $container.addClass('npc-copied'); | ||
− | + | // Remove a classe após 2 segundos | |
− | + | setTimeout(function() { | |
− | + | $container.removeClass('npc-copied'); | |
− | + | }, 2000); | |
− | + | } | |
− | + | }); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | } | ||
− | } | ||
− | |||
− | |||
− | |||
− | // | + | // Inicializa na carga da página e em atualizações |
if (typeof mw !== 'undefined' && mw.hook) { | if (typeof mw !== 'undefined' && mw.hook) { | ||
mw.hook('wikipage.content').add(function() { | mw.hook('wikipage.content').add(function() { | ||
− | + | console.log("Inicializando comportamento de cópia nos NPCs"); | |
}); | }); | ||
} | } | ||
}); | }); |
Latest revision as of 17:01, 9 May 2025
/* Any JavaScript here will be loaded for all users on every page load. */ $(document).ready(function() { // Função única para cópia de texto $(document).on('click', '.warp-copy', function(e) { e.preventDefault(); var textToCopy = $(this).attr('data-copy'); // Cria elemento temporário para cópia var tempInput = document.createElement('textarea'); tempInput.value = textToCopy; document.body.appendChild(tempInput); tempInput.select(); document.execCommand('copy'); document.body.removeChild(tempInput); // Adiciona classe para feedback visual var $element = $(this); $element.addClass('copied'); setTimeout(function() { $element.removeClass('copied'); }, 2000); }); // Adicionar funcionalidade às imagens dos NPCs function initImageCopy() { $('.tile-top.tile-image a').each(function() { var $link = $(this); if (!$link.hasClass('warp-copy')) { var npcId = $link.attr('href').replace('#',''); $link.addClass('warp-copy') .attr('data-copy', '@warp ' + npcId) .css('cursor', 'pointer'); } }); } // Função corrigida para aplicar larguras e alturas aos containers, não às imagens function fixNpcContainerWidths() { $('.contents-equipment.tile-halves').each(function() { var $container = $(this); var width = $container.data('width'); if (width && width > 0) { $container.css({ '--container-width': width + 'px' }); } }); // Aplicar altura aos containers de imagem, não às próprias imagens $('.tile-top.tile-image').each(function() { var $imageContainer = $(this); var height = $imageContainer.css('--image-height'); if (height && height !== 'auto') { $imageContainer.css('height', height); } }); } // Inicializar funções ao carregar e em atualizações de conteúdo initImageCopy(); fixNpcContainerWidths(); if (typeof mw !== 'undefined' && mw.hook) { mw.hook('wikipage.content').add(function() { initImageCopy(); fixNpcContainerWidths(); }); } /* Auto-expand sections when clicking anchored links */ console.log("Inicializando script para expandir seções com links âncora"); // Handle initial page load with hash if (window.location.hash) { console.log("Página carregada com hash: " + window.location.hash); setTimeout(function() { expandSectionForAnchor(window.location.hash); }, 300); } // Handle clicks on anchor links $(document).on('click', 'a[href^="#"]', function(event) { var hash = $(this).attr('href'); console.log("Clique em link âncora: " + hash); event.preventDefault(); if (history.pushState) { history.pushState(null, null, hash); } else { location.hash = hash; } expandSectionForAnchor(hash); }); function expandSectionForAnchor(hash) { console.log("Procurando e expandindo seção para âncora: " + hash); var targetElement = $(hash); if (targetElement.length) { console.log("Elemento alvo encontrado"); var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed'); var directCollapsible = targetElement.closest('.mw-collapsible.mw-collapsed'); if (directCollapsible.length) { collapsibleSections = collapsibleSections.add(directCollapsible); } console.log("Seções colapsáveis encontradas: " + collapsibleSections.length); if (collapsibleSections.length > 0) { collapsibleSections.each(function() { var section = $(this); console.log("Expandindo seção colapsável"); section.removeClass('mw-collapsed'); var toggleButton = section.find('.mw-collapsible-toggle').first(); if (toggleButton.length) { console.log("Clicando no botão de expansão"); toggleButton.click(); } if (section.hasClass('wikitable')) { console.log("Expandindo tabela wikitable"); section.find('tr:not(:first-child)').show(); } section.find('.mw-collapsible-content').show(); }); setTimeout(function() { scrollToTarget(targetElement); }, 400); } else { scrollToTarget(targetElement); } } else { console.log("Elemento alvo não encontrado para hash: " + hash); } } function scrollToTarget(element) { console.log("Rolando até o elemento alvo"); $('html, body').animate({ scrollTop: element.offset().top - 100 }, 200); } if (typeof mw !== 'undefined' && mw.hook) { mw.hook('wikipage.content').add(function() { console.log("Conteúdo da wiki atualizado"); if (window.location.hash) { setTimeout(function() { expandSectionForAnchor(window.location.hash); }, 300); } }); } }); /* Código JavaScript limpo para os NPCs - MANTER APENAS ESTE BLOCO */ $(document).ready(function() { // Manipulador de clique direto nos containers NPC $(document).on('click', '.contents-equipment.tile-halves', function(e) { // Previne comportamento padrão apenas se não for um link if (!$(e.target).is('a') && !$(e.target).parents('a').length) { e.preventDefault(); } // Encontra o comando warp dentro do container var $warpElement = $(this).find('.warp-copy[data-copy^="@warp"]'); if ($warpElement.length) { var warpCommand = $warpElement.attr('data-copy'); // Copia o texto para a área de transferência var tempInput = document.createElement('textarea'); tempInput.value = warpCommand; document.body.appendChild(tempInput); tempInput.select(); document.execCommand('copy'); document.body.removeChild(tempInput); // Adiciona classe para feedback visual var $container = $(this); $container.addClass('npc-copied'); // Remove a classe após 2 segundos setTimeout(function() { $container.removeClass('npc-copied'); }, 2000); } }); // Inicializa na carga da página e em atualizações if (typeof mw !== 'undefined' && mw.hook) { mw.hook('wikipage.content').add(function() { console.log("Inicializando comportamento de cópia nos NPCs"); }); } });