Diferencia entre revisiones de «MediaWiki:Common.js»

De Vanaheim Wiki
Ir a la navegación Ir a la búsqueda
Sin resumen de edición
Move language switcher to server hook
 
(No se muestran 3 ediciones intermedias de 2 usuarios)
Línea 1: Línea 1:
$(document).ready(function() {
$( function () {
  if ($('#copy-message').length === 0) {
$( '.copiar-portapapeles' ).on( 'click', function () {
    $('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>');
var textoACopiar = $( this ).data( 'texto-a-copiar' );
  }
var $temp = $( '<textarea>' );


  // Delegación: capturar clicks en .copy-text aunque se creen luego
$( 'body' ).append( $temp );
  $(document).on('click', '.copy-text', function() {
$temp.val( textoACopiar ).select();
    var text = $(this).attr('data-copy');
    if (!text) return;


    if (navigator.clipboard) {
try {
      navigator.clipboard.writeText(text).then(() => {
document.execCommand( 'copy' );
        $('#copy-message').fadeIn(200).delay(1000).fadeOut(200);
mw.notify( '¡Texto copiado al portapapeles!', { type: 'success' } );
      }, () => {
} catch ( e ) {
        alert('Error al copiar');
mw.notify( 'Error al copiar el texto.', { type: 'error' } );
      });
}
    } else {
 
      var $temp = $('<textarea>');
$temp.remove();
      $('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();
	} );
} );