Jump to content

MediaWiki:Common.js: Difference between revisions

From EthernalRO Wiki
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 1: Line 1:
// Copiar /navi mapa,x,y pro clipboard
/* Script para copiar navegação */
function naviCopy(map, x, y) {
$(function() {
     const text = "/navi " + map + "," + x + "," + y;
     // Usa 'body' para garantir que funcione mesmo em elementos carregados dinamicamente
 
     $('body').on('click', '.navi-link', function(e) {
    // tenta API Clipboard
         e.preventDefault();
     if (navigator.clipboard && window.isSecureContext) {
        var $this = $(this);
         navigator.clipboard.writeText(text).then(function() {
        var map = $this.data('map');
            mw.notify("Copiado: " + text);
        var x = $this.data('x');
         });
         var y = $this.data('y');
    } else {
       
         // fallback
         // Remove espaços extras caso existam
         const ta = document.createElement("textarea");
         if(map) map = map.trim();
         ta.value = text;
          
         document.body.appendChild(ta);
        var command = '/navi ' + map + ' ' + x + '/' + y;
         ta.select();
       
        // Cria elemento invisível para copiar
        var $temp = $("<input>");
         $("body").append($temp);
         $temp.val(command).select();
         document.execCommand("copy");
         document.execCommand("copy");
         document.body.removeChild(ta);
         $temp.remove();
         mw.notify("Copiado: " + text);
       
     }
        // Feedback visual
}
        var $msg = $this.find('.navi-msg');
         $msg.show().fadeOut(2000);
     });
});

Latest revision as of 23:09, 26 January 2026

/* Script para copiar navegação */
$(function() {
    // Usa 'body' para garantir que funcione mesmo em elementos carregados dinamicamente
    $('body').on('click', '.navi-link', function(e) {
        e.preventDefault();
        var $this = $(this);
        var map = $this.data('map');
        var x = $this.data('x');
        var y = $this.data('y');
        
        // Remove espaços extras caso existam
        if(map) map = map.trim();
        
        var command = '/navi ' + map + ' ' + x + '/' + y;
        
        // Cria elemento invisível para copiar
        var $temp = $("<input>");
        $("body").append($temp);
        $temp.val(command).select();
        document.execCommand("copy");
        $temp.remove();
        
        // Feedback visual
        var $msg = $this.find('.navi-msg');
        $msg.show().fadeOut(2000);
    });
});