Difference between revisions of "MediaWiki:Common.js"

From XilePK - Ragnarok Online Server
Jump to navigation Jump to search
Line 23: Line 23:
 
   });
 
   });
  
   /* Versão modificada apenas da função que trata as imagens */
+
   /* Versão modificada com solução definitiva para os GIFs */
function initImageCopy() {
+
  function initImageCopy() {
  $('.tile-top.tile-image a').each(function() {
+
    $('.tile-top.tile-image a').each(function() {
    var $link = $(this);
+
      var $link = $(this);
    if (!$link.hasClass('warp-copy')) {
+
      if (!$link.hasClass('warp-copy')) {
      var npcId = $link.attr('href').replace('#','');
+
        var npcId = $link.attr('href').replace('#','');
      $link.addClass('warp-copy')
+
        $link.addClass('warp-copy')
          .attr('data-copy', '@warp ' + npcId)
+
            .attr('data-copy', '@warp ' + npcId)
          .css('cursor', 'pointer');
+
            .css('cursor', 'pointer');
    }
+
      }
  });
+
    });
 
 
  // Solução híbrida para preservar animação dos GIFs em TODOS os casos
 
  $('.tile-top.tile-image img').each(function() {
 
    var $img = $(this);
 
    var width = $img.data('width');
 
    var height = $img.data('height');
 
 
      
 
      
     if (width || height) {
+
     // Solução definitiva para GIFs - sempre usar container
      $img.addClass('custom-size');
+
    $('.tile-top.tile-image img').each(function() {
 
+
       var $img = $(this);
        // Primeiro, verificamos se o GIF é menor que o tamanho desejado
+
       var width = $img.data('width');
       var originalWidth = $img[0].naturalWidth;
+
       var height = $img.data('height');
       var originalHeight = $img[0].naturalHeight;
 
      var needsEnlarge = (width && width > originalWidth) || (height && height > originalHeight);
 
       var needsShrink = (width && width < originalWidth) ||
 
                (height && height < originalHeight) ||
 
                (width && height && (width/originalWidth !== height/originalHeight));
 
 
        
 
        
       if (needsEnlarge) {
+
       if (width || height) {
 +
        // Debug no console
 +
        console.log('Processando imagem:', $img.attr('src'),
 +
                    'Dimensões originais:', $img[0].naturalWidth, 'x', $img[0].naturalHeight,
 +
                    'Novas dimensões:', width, 'x', height);
 
          
 
          
// Para aumentar o tamanho, usamos CSS direto (funciona bem para aumento)
+
        // Sempre criar container, independente do tamanho
        $img.css({
 
          'width': width ? width + 'px' : 'auto',
 
          'height': height ? height + 'px' : 'auto',
 
          'max-width': width ? width + 'px' : '100%',
 
          'max-height': height ? height + 'px' : 'none'
 
        });
 
      }
 
      else if (needsShrink) {
 
        // Para diminuir o tamanho, usamos o container para preservar animação
 
 
         if (!$img.parent().hasClass('gif-container')) {
 
         if (!$img.parent().hasClass('gif-container')) {
 
           $img.wrap('<div class="gif-container"></div>');
 
           $img.wrap('<div class="gif-container"></div>');
 
           var $container = $img.parent('.gif-container');
 
           var $container = $img.parent('.gif-container');
 
            
 
            
           // Aplicar estilos ao container
+
           // Estilos do container
 
           $container.css({
 
           $container.css({
              'display': 'flex',
+
            'display': 'inline-block',
              'justify-content': 'center',
+
            'overflow': 'hidden',
              'align-items': 'center',
+
            'width': width ? width + 'px' : 'auto',
              'overflow': 'hidden',
+
            'height': height ? height + 'px' : 'auto',
              'width': width ? width + 'px' : 'auto',
+
            'line-height': '0',
              'height': height ? height + 'px' : 'auto',
+
            'vertical-align': 'middle'
              'aspect-ratio': originalWidth + '/' + originalHeight // manter proporção original
 
 
           });
 
           });
 
            
 
            
           // O GIF mantém seu tamanho original (preservando a animação)
+
           // Estilos da imagem - mantém tamanho original
          // mas é posicionado dentro do container com object-fit
 
 
           $img.css({
 
           $img.css({
              'object-fit': 'cover',
+
            'width': 'auto',
              'width': '100%',
+
            'height': 'auto',
              'height': '100%',
+
            'max-width': 'none',
              'max-width': 'none',
+
            'max-height': 'none',
              'max-height': 'none',
+
            'object-fit': 'none',
              'image-rendering': 'pixelated' // ajuda em alguns casos
+
            'image-rendering': 'pixelated'
 
           });
 
           });
 
         }
 
         }
 
       }
 
       }
     }
+
     });
  });
+
  }
}
 
  
 
   // Inicializar ao carregar e em atualizações de conteúdo
 
   // Inicializar ao carregar e em atualizações de conteúdo
Line 135: Line 116:
 
        
 
        
 
       var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed');
 
       var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed');
       var directCollapsible = targetElement.closest('.mw-collapsible.mw-collapsed');
+
       var directCollapsible = targetElement.closest('.mw-collapsible.mw
     
 
      if (directCollapsible.length) {
 
        collapsibleSections = collapsibleSections.add(directCollapsible);
 
      }
 
     
 
      console.log("Seções colapsáveis encontradas: " + collapsibleSections.length);
 
     
 
      if (collapsibleSections.length > 0) {
 
        collapsibleSections.each(function() {
 
          var section = $(this);
 
          console.log("Expandindo seção colapsável");
 
         
 
          section.removeClass('mw-collapsed');
 
          var toggleButton = section.find('.mw-collapsible-toggle').first();
 
          if (toggleButton.length) {
 
            console.log("Clicando no botão de expansão");
 
            toggleButton.click();
 
          }
 
         
 
          if (section.hasClass('wikitable')) {
 
            console.log("Expandindo tabela wikitable");
 
            section.find('tr:not(:first-child)').show();
 
          }
 
         
 
          section.find('.mw-collapsible-content').show();
 
        });
 
       
 
        setTimeout(function() {
 
          scrollToTarget(targetElement);
 
        }, 400);
 
      } else {
 
        scrollToTarget(targetElement);
 
      }
 
    } else {
 
      console.log("Elemento alvo não encontrado para hash: " + hash);
 
    }
 
  }
 
 
 
  function scrollToTarget(element) {
 
    console.log("Rolando até o elemento alvo");
 
    $('html, body').animate({
 
      scrollTop: element.offset().top - 100
 
    }, 200);
 
  }
 
 
 
  if (typeof mw !== 'undefined' && mw.hook) {
 
    mw.hook('wikipage.content').add(function() {
 
      console.log("Conteúdo da wiki atualizado");
 
      if (window.location.hash) {
 
        setTimeout(function() {
 
          expandSectionForAnchor(window.location.hash);
 
        }, 300);
 
      }
 
    });
 
  }
 
});
 

Revision as of 13:53, 8 May 2025

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

$(document).ready(function() {
  // Função única para cópia de texto
  $(document).on('click', '.warp-copy', function(e) {
    e.preventDefault();
    var textToCopy = $(this).attr('data-copy');
    
    // Cria elemento temporário para cópia
    var tempInput = document.createElement('textarea');
    tempInput.value = textToCopy;
    document.body.appendChild(tempInput);
    tempInput.select();
    document.execCommand('copy');
    document.body.removeChild(tempInput);
    
    // Adiciona classe para feedback visual
    var $element = $(this);
    $element.addClass('copied');
    setTimeout(function() {
      $element.removeClass('copied');
    }, 2000);
  });

  /* Versão modificada com solução definitiva para os GIFs */
  function initImageCopy() {
    $('.tile-top.tile-image a').each(function() {
      var $link = $(this);
      if (!$link.hasClass('warp-copy')) {
        var npcId = $link.attr('href').replace('#','');
        $link.addClass('warp-copy')
             .attr('data-copy', '@warp ' + npcId)
             .css('cursor', 'pointer');
      }
    });
    
    // Solução definitiva para GIFs - sempre usar container
    $('.tile-top.tile-image img').each(function() {
      var $img = $(this);
      var width = $img.data('width');
      var height = $img.data('height');
      
      if (width || height) {
        // Debug no console
        console.log('Processando imagem:', $img.attr('src'), 
                    'Dimensões originais:', $img[0].naturalWidth, 'x', $img[0].naturalHeight,
                    'Novas dimensões:', width, 'x', height);
        
        // Sempre criar container, independente do tamanho
        if (!$img.parent().hasClass('gif-container')) {
          $img.wrap('<div class="gif-container"></div>');
          var $container = $img.parent('.gif-container');
          
          // Estilos do container
          $container.css({
            'display': 'inline-block',
            'overflow': 'hidden',
            'width': width ? width + 'px' : 'auto',
            'height': height ? height + 'px' : 'auto',
            'line-height': '0',
            'vertical-align': 'middle'
          });
          
          // Estilos da imagem - mantém tamanho original
          $img.css({
            'width': 'auto',
            'height': 'auto',
            'max-width': 'none',
            'max-height': 'none',
            'object-fit': 'none',
            'image-rendering': 'pixelated'
          });
        }
      }
    });
  }

  // Inicializar ao carregar e em atualizações de conteúdo
  initImageCopy();
  if (typeof mw !== 'undefined' && mw.hook) {
    mw.hook('wikipage.content').add(initImageCopy);
  }

  /* Auto-expand sections when clicking anchored links */
  console.log("Inicializando script para expandir seções com links âncora");
  
  // Handle initial page load with hash
  if (window.location.hash) {
    console.log("Página carregada com hash: " + window.location.hash);
    setTimeout(function() {
      expandSectionForAnchor(window.location.hash);
    }, 300);
  }
  
  // Handle clicks on anchor links
  $(document).on('click', 'a[href^="#"]', function(event) {
    var hash = $(this).attr('href');
    console.log("Clique em link âncora: " + hash);
    event.preventDefault();
    
    if (history.pushState) {
      history.pushState(null, null, hash);
    } else {
      location.hash = hash;
    }
    
    expandSectionForAnchor(hash);
  });
  
  function expandSectionForAnchor(hash) {
    console.log("Procurando e expandindo seção para âncora: " + hash);
    var targetElement = $(hash);
    
    if (targetElement.length) {
      console.log("Elemento alvo encontrado");
      
      var collapsibleSections = targetElement.parents('.mw-collapsible.mw-collapsed');
      var directCollapsible = targetElement.closest('.mw-collapsible.mw