MediaWiki:Common.js

From XilePK - Ragnarok Online Server
Revision as of 13:07, 30 April 2025 by Admin (talk | contribs)
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */

$(document).ready(function() {
  // Função para copiar texto e mostrar feedback
  function handleCopy(element) {
    var textToCopy = $(element).attr('data-copy');
    
    // Cria elemento temporário para copiar
    var tempInput = document.createElement('textarea');
    tempInput.value = textToCopy;
    document.body.appendChild(tempInput);
    tempInput.select();
    
    try {
      document.execCommand('copy');
      
      // Adiciona classe de feedback
      $(element).addClass('copied');
      
      // Remove feedback após 1.5 segundos
      setTimeout(function() {
        $(element).removeClass('copied');
      }, 1500);
      
    } catch (err) {
      console.error('Erro ao copiar:', err);
    }
    
    document.body.removeChild(tempInput);
  }

  // Click nos elementos .warp-copy
  $(document).on('click', '.warp-copy', function() {
    handleCopy(this);
  });

  // Click nas imagens dos NPCs
  function initNpcCopy() {
    $('.contents-equipment .tile-top.tile-image a').off('click.npccopy').on('click.npccopy', function(e) {
      e.preventDefault();
      var npcId = $(this).attr('href').replace('#','');
      handleCopy($(this).closest('.contents-equipment').find('.warp-copy')[0]);
    });
  }

  // Inicializa quando o documento está pronto
  initNpcCopy();

  // Reinicia quando novo conteúdo é carregado
  if (typeof mw !== 'undefined' && mw.hook) {
    mw.hook('wikipage.content').add(function() {
      initNpcCopy();
    });
  }

  // Auto-expandir seções com anchor links
  function expandSectionForAnchor(hash) {
    var targetElement = $(hash);
    if (targetElement.length) {
      targetElement.parents('.mw-collapsible.mw-collapsed').removeClass('mw-collapsed')
        .find('.mw-collapsible-content').show();
      setTimeout(function() {
        $('html, body').animate({ scrollTop: targetElement.offset().top - 100 }, 200);
      }, 400);
    }
  }

  // Trata hash na URL inicial
  if (window.location.hash) {
    setTimeout(function() { expandSectionForAnchor(window.location.hash); }, 300);
  }

  // Trata clicks em links âncora
  $(document).on('click', 'a[href^="#"]', function(e) {
    e.preventDefault();
    var hash = $(this).attr('href');
    history.pushState(null, null, hash);
    expandSectionForAnchor(hash);
  });
});