Difference between revisions of "MediaWiki:Common.js"

From XilePK - Ragnarok Online Server
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. */
  
<script>
+
// Adicione este código ao MediaWiki:Common.js
document.addEventListener('DOMContentLoaded', function() {
+
$(document).ready(function() {
   var copyButtons = document.querySelectorAll('.copy-button');
+
   $('.copy-button').on('click', function() {
 
+
    var textToCopy = $(this).attr('data-clipboard-text');
  copyButtons.forEach(function(button) {
+
   
    button.addEventListener('click', function() {
+
    // Método alternativo que funciona em mais navegadores
      var textToCopy = this.getAttribute('data-clipboard-text');
+
    var tempInput = document.createElement('textarea');
     
+
    tempInput.value = textToCopy;
      navigator.clipboard.writeText(textToCopy).then(function() {
+
    document.body.appendChild(tempInput);
        // Opcional: feedback visual de sucesso
+
    tempInput.select();
        var originalColor = button.style.color;
+
    document.execCommand('copy');
        button.style.color = 'green';
+
    document.body.removeChild(tempInput);
        setTimeout(function() {
+
   
          button.style.color = originalColor;
+
    // Feedback visual
        }, 500);
+
    var $this = $(this);
       }).catch(function(err) {
+
    var originalColor = $this.css('color');
        console.error('Erro ao copiar: ', err);
+
    $this.css('color', 'green');
      });
+
    setTimeout(function() {
     });
+
       $this.css('color', originalColor);
 +
    }, 500);
 +
      
 +
    return false; // Previne comportamento padrão
 
   });
 
   });
 
});
 
});
</script>
 

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
  });
});