Diferencia entre revisiones de «MediaWiki:Common.js»

De Vanaheim Wiki
Ir a la navegación Ir a la búsqueda
Página creada con «Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página: $(document).ready(function() { // Crear el div del mensaje si no existe if ($('#copy-message').length === 0) { $('body').append('<div id="copy-message" style="position:fixed; bottom:20px; right:20px; background:#4CAF50; color:white; padding:8px 12px; border-radius:4px; display:none; font-weight:bold; z-index:9999;">¡Copiado!</div>'); } $('.copy-…»
 
Move language switcher to server hook
 
(No se muestran 5 ediciones intermedias de 2 usuarios)
Línea 1: Línea 1:
/* Cualquier código JavaScript escrito aquí se cargará para todos los usuarios en cada carga de página */
$( function () {
$( '.copiar-portapapeles' ).on( 'click', function () {
var textoACopiar = $( this ).data( 'texto-a-copiar' );
var $temp = $( '<textarea>' );


$(document).ready(function() {
$( 'body' ).append( $temp );
  // Crear el div del mensaje si no existe
$temp.val( textoACopiar ).select();
  if ($('#copy-message').length === 0) {
    $('body').append('<div id="copy-message" style="position:fixed; bottom:20px; right:20px; background:#4CAF50; color:white; padding:8px 12px; border-radius:4px; display:none; font-weight:bold; z-index:9999;">¡Copiado!</div>');
  }


  $('.copy-text').css('cursor', 'pointer').click(function() {
try {
    var text = $(this).attr('data-copy');
document.execCommand( 'copy' );
    if (!text) return;
mw.notify( '¡Texto copiado al portapapeles!', { type: 'success' } );
} catch ( e ) {
mw.notify( 'Error al copiar el texto.', { type: 'error' } );
}


    if (navigator.clipboard) {
$temp.remove();
      navigator.clipboard.writeText(text).then(() => {
} );
        $('#copy-message').fadeIn(200).delay(1000).fadeOut(200);
} );
      }, () => {
        alert('Error al copiar');
      });
    } else {
      var $temp = $('<textarea>');
      $('body').append($temp);
      $temp.val(text).select();
      document.execCommand('copy');
      $temp.remove();
      $('#copy-message').fadeIn(200).delay(1000).fadeOut(200);
    }
  });
});

Revisión actual - 15:33 19 may 2026

$( function () {
	$( '.copiar-portapapeles' ).on( 'click', function () {
		var textoACopiar = $( this ).data( 'texto-a-copiar' );
		var $temp = $( '<textarea>' );

		$( 'body' ).append( $temp );
		$temp.val( textoACopiar ).select();

		try {
			document.execCommand( 'copy' );
			mw.notify( '¡Texto copiado al portapapeles!', { type: 'success' } );
		} catch ( e ) {
			mw.notify( 'Error al copiar el texto.', { type: 'error' } );
		}

		$temp.remove();
	} );
} );