Difference between revisions of "MediaWiki:Common.js"

From XilePK - Ragnarok Online Server
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. */
  
// Adicione este código ao MediaWiki:Common.js
+
// Versão sem jQuery, para máxima compatibilidade
$(document).ready(function() {
+
mw.hook('wikipage.content').add(function($content) {
   $('.copy-button').on('click', function() {
+
   var copyButtons = document.querySelectorAll('.copy-button');
    var textToCopy = $(this).attr('data-clipboard-text');
+
 
   
+
  for (var i = 0; i < copyButtons.length; i++) {
    // Método alternativo que funciona em mais navegadores
+
    copyButtons[i].addEventListener('click', function(e) {
    var tempInput = document.createElement('textarea');
+
      e.preventDefault();
    tempInput.value = textToCopy;
+
      var textToCopy = this.getAttribute('data-clipboard-text');
    document.body.appendChild(tempInput);
+
     
    tempInput.select();
+
      var tempInput = document.createElement('textarea');
    document.execCommand('copy');
+
      tempInput.style.position = 'absolute';
    document.body.removeChild(tempInput);
+
      tempInput.style.left = '-9999px';
   
+
      tempInput.value = textToCopy;
    // Feedback visual
+
      document.body.appendChild(tempInput);
    var $this = $(this);
+
      tempInput.select();
    var originalColor = $this.css('color');
+
      document.execCommand('copy');
    $this.css('color', 'green');
+
      document.body.removeChild(tempInput);
    setTimeout(function() {
+
     
      $this.css('color', originalColor);
+
      // Feedback visual
    }, 500);
+
      var originalColor = this.style.color;
      
+
      this.style.color = 'green';
    return false; // Previne comportamento padrão
+
      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);
    });
  }
});