Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
− | /* | + | /* Função melhorada para a funcionalidade de cópia */ |
+ | function initImageCopy() { | ||
+ | // Adiciona a funcionalidade warp-copy para links de imagem | ||
+ | $('.tile-top.tile-image a').each(function() { | ||
+ | var $link = $(this); | ||
+ | if (!$link.hasClass('warp-copy')) { | ||
+ | var href = $link.attr('href') || ''; | ||
+ | var npcId = href.replace('#',''); | ||
+ | if (npcId) { | ||
+ | $link.addClass('warp-copy') | ||
+ | .attr('data-copy', '@warp ' + npcId) | ||
+ | .css('cursor', 'pointer'); | ||
+ | |||
+ | // Adiciona eventos de click específicos para garantir o feedback visual | ||
+ | $link.off('click').on('click', function(e) { | ||
+ | e.preventDefault(); | ||
+ | e.stopPropagation(); | ||
+ | |||
+ | 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'); | ||
+ | console.log("Texto copiado da imagem: " + textToCopy); | ||
+ | |||
+ | // Remove a classe após 2 segundos | ||
+ | setTimeout(function() { | ||
+ | $element.removeClass('copied'); | ||
+ | }, 2000); | ||
+ | |||
+ | return false; | ||
+ | }); | ||
+ | } | ||
+ | } | ||
+ | }); | ||
+ | } | ||
+ | // Remova o evento de click genérico para .warp-copy e use eventos específicos | ||
$(document).ready(function() { | $(document).ready(function() { | ||
− | // Função | + | // Função para texto |
− | $(document).on('click', '.warp-copy', function(e) { | + | $(document).on('click', '.warp-copy:not(.tile-top.tile-image a)', function(e) { |
e.preventDefault(); | e.preventDefault(); | ||
var textToCopy = $(this).attr('data-copy'); | var textToCopy = $(this).attr('data-copy'); | ||
Line 18: | Line 62: | ||
var $element = $(this); | var $element = $(this); | ||
$element.addClass('copied'); | $element.addClass('copied'); | ||
+ | console.log("Texto copiado do texto: " + textToCopy); | ||
+ | |||
setTimeout(function() { | setTimeout(function() { | ||
$element.removeClass('copied'); | $element.removeClass('copied'); | ||
}, 2000); | }, 2000); | ||
}); | }); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | // | + | // Inicializa a funcionalidade para imagens |
− | + | setTimeout(function() { | |
− | + | initImageCopy(); | |
− | + | }, 300); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | // Reinicializa ao atualizar conteúdo wiki | ||
if (typeof mw !== 'undefined' && mw.hook) { | if (typeof mw !== 'undefined' && mw.hook) { | ||
mw.hook('wikipage.content').add(function() { | mw.hook('wikipage.content').add(function() { | ||
− | + | setTimeout(function() { | |
− | + | initImageCopy(); | |
− | + | }, 300); | |
− | |||
− | |||
− | |||
}); | }); | ||
} | } | ||
}); | }); |
Revision as of 15:57, 9 May 2025
/* Função melhorada para a funcionalidade de cópia */ function initImageCopy() { // Adiciona a funcionalidade warp-copy para links de imagem $('.tile-top.tile-image a').each(function() { var $link = $(this); if (!$link.hasClass('warp-copy')) { var href = $link.attr('href') || ''; var npcId = href.replace('#',''); if (npcId) { $link.addClass('warp-copy') .attr('data-copy', '@warp ' + npcId) .css('cursor', 'pointer'); // Adiciona eventos de click específicos para garantir o feedback visual $link.off('click').on('click', function(e) { e.preventDefault(); e.stopPropagation(); 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'); console.log("Texto copiado da imagem: " + textToCopy); // Remove a classe após 2 segundos setTimeout(function() { $element.removeClass('copied'); }, 2000); return false; }); } } }); } // Remova o evento de click genérico para .warp-copy e use eventos específicos $(document).ready(function() { // Função para texto $(document).on('click', '.warp-copy:not(.tile-top.tile-image a)', 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'); console.log("Texto copiado do texto: " + textToCopy); setTimeout(function() { $element.removeClass('copied'); }, 2000); }); // Inicializa a funcionalidade para imagens setTimeout(function() { initImageCopy(); }, 300); // Reinicializa ao atualizar conteúdo wiki if (typeof mw !== 'undefined' && mw.hook) { mw.hook('wikipage.content').add(function() { setTimeout(function() { initImageCopy(); }, 300); }); } });