Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
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. */ | ||
− | // | + | // Versão sem jQuery, para máxima compatibilidade |
− | + | mw.hook('wikipage.content').add(function($content) { | |
− | + | var copyButtons = document.querySelectorAll('.copy-button'); | |
− | + | ||
− | + | for (var i = 0; i < copyButtons.length; i++) { | |
− | + | copyButtons[i].addEventListener('click', function(e) { | |
− | + | e.preventDefault(); | |
− | + | var textToCopy = this.getAttribute('data-clipboard-text'); | |
− | + | ||
− | + | var tempInput = document.createElement('textarea'); | |
− | + | tempInput.style.position = 'absolute'; | |
− | + | tempInput.style.left = '-9999px'; | |
− | + | tempInput.value = textToCopy; | |
− | + | document.body.appendChild(tempInput); | |
− | + | tempInput.select(); | |
− | + | document.execCommand('copy'); | |
− | + | document.body.removeChild(tempInput); | |
− | + | ||
− | + | // Feedback visual | |
− | + | var originalColor = this.style.color; | |
− | + | this.style.color = 'green'; | |
− | + | var self = this; | |
− | } | + | setTimeout(function() { |
+ | self.style.color = originalColor; | ||
+ | }, 500); | ||
+ | }); | ||
+ | } | ||
}); | }); |
Revision as of 15:41, 10 April 2025
/* Any JavaScript here will be loaded for all users on every page load. */ // Versão sem jQuery, para máxima compatibilidade mw.hook('wikipage.content').add(function($content) { var copyButtons = document.querySelectorAll('.copy-button'); for (var i = 0; i < copyButtons.length; i++) { copyButtons[i].addEventListener('click', function(e) { e.preventDefault(); var textToCopy = this.getAttribute('data-clipboard-text'); var tempInput = document.createElement('textarea'); tempInput.style.position = 'absolute'; tempInput.style.left = '-9999px'; tempInput.value = textToCopy; document.body.appendChild(tempInput); tempInput.select(); document.execCommand('copy'); document.body.removeChild(tempInput); // Feedback visual var originalColor = this.style.color; this.style.color = 'green'; var self = this; setTimeout(function() { self.style.color = originalColor; }, 500); }); } });