Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
(Created page with "→Any JavaScript here will be loaded for all users on every page load.: <script> document.addEventListener('DOMContentLoaded', function() { var copyButtons = document.qu...") |
|||
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. */ | ||
− | + | // Adicione este código ao MediaWiki:Common.js | |
− | document. | + | $(document).ready(function() { |
− | + | $('.copy-button').on('click', function() { | |
− | + | var textToCopy = $(this).attr('data-clipboard-text'); | |
− | + | ||
− | + | // Método alternativo que funciona em mais navegadores | |
− | + | var tempInput = document.createElement('textarea'); | |
− | + | tempInput.value = textToCopy; | |
− | + | document.body.appendChild(tempInput); | |
− | + | tempInput.select(); | |
− | + | document.execCommand('copy'); | |
− | + | document.body.removeChild(tempInput); | |
− | + | ||
− | + | // Feedback visual | |
− | + | var $this = $(this); | |
− | + | var originalColor = $this.css('color'); | |
− | + | $this.css('color', 'green'); | |
− | + | setTimeout(function() { | |
− | + | $this.css('color', originalColor); | |
+ | }, 500); | ||
+ | |||
+ | return false; // Previne comportamento padrão | ||
}); | }); | ||
}); | }); | ||
− |
Revision as of 15:40, 10 April 2025
/* Any JavaScript here will be loaded for all users on every page load. */ // Adicione este código ao MediaWiki:Common.js $(document).ready(function() { $('.copy-button').on('click', function() { var textToCopy = $(this).attr('data-clipboard-text'); // Método alternativo que funciona em mais navegadores var tempInput = document.createElement('textarea'); tempInput.value = textToCopy; document.body.appendChild(tempInput); tempInput.select(); document.execCommand('copy'); document.body.removeChild(tempInput); // Feedback visual var $this = $(this); var originalColor = $this.css('color'); $this.css('color', 'green'); setTimeout(function() { $this.css('color', originalColor); }, 500); return false; // Previne comportamento padrão }); });