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. */
  
// Função simples para copiar texto
+
$(document).ready(function() {
function copyToClipboard(text) {
+
  $(document).on('click', '.warp-copy', function() {
  var temp = document.createElement('textarea');
+
    var textToCopy = $(this).attr('data-copy');
  temp.value = text;
+
   
  document.body.appendChild(temp);
+
    var tempInput = document.createElement('textarea');
  temp.select();
+
    tempInput.value = textToCopy;
  document.execCommand('copy');
+
    document.body.appendChild(tempInput);
  document.body.removeChild(temp);
+
    tempInput.select();
}
+
    document.execCommand('copy');
 
+
    document.body.removeChild(tempInput);
// Adiciona evento de clique para elementos com a classe warp-copy
+
   
$(document).on('click', '.warp-copy', function() {
+
    var originalColor = $(this).css('color');
  copyToClipboard($(this).data('copy'));
+
    $(this).css('color', 'green');
 
+
    var self = this;
  // Feedback visual
+
    setTimeout(function() {
  var origColor = $(this).css('color');
+
      $(self).css('color', originalColor);
  $(this).css('color', 'green');
+
    }, 500);
  var self = this;
+
  });
  setTimeout(function() {
 
    $(self).css('color', origColor);
 
  }, 500);
 
 
});
 
});

Revision as of 12:16, 11 April 2025

/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
  $(document).on('click', '.warp-copy', function() {
    var textToCopy = $(this).attr('data-copy');
    
    var tempInput = document.createElement('textarea');
    tempInput.value = textToCopy;
    document.body.appendChild(tempInput);
    tempInput.select();
    document.execCommand('copy');
    document.body.removeChild(tempInput);
    
    var originalColor = $(this).css('color');
    $(this).css('color', 'green');
    var self = this;
    setTimeout(function() {
      $(self).css('color', originalColor);
    }, 500);
  });
});