MediaWiki:Common.js

From XilePK - Ragnarok Online Server
Revision as of 17:46, 7 May 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.
/* Adição ao seu common.js para corrigir problemas com dimensões de imagens */

$(document).ready(function() {
  // Função para corrigir o dimensionamento de imagens
  function fixImageDimensions() {
    console.log("Corrigindo dimensões de imagens...");
    
    $('.tile-top.tile-image img').each(function() {
      var $img = $(this);
      var width = $img.data('width') || $img.attr('width');
      var height = $img.data('height') || $img.attr('height');
      
      console.log("Processando imagem: " + $img.attr('src') + " - Dimensões: " + width + "x" + height);
      
      // Detectar valores zero ou problemáticos
      if (width === '0' || height === '0' || width === 0 || height === 0) {
        console.log("Detectada dimensão zero, corrigindo...");
        
        // Remover atributos de dimensão para permitir o tamanho natural
        $img.removeAttr('width');
        $img.removeAttr('height');
        $img.css({
          'width': 'auto',
          'height': 'auto',
          'max-width': '100%'
        });
        
        // Remover classes e estilos de dimensionamento customizado
        $img.removeClass('custom-size');
        $img.css('--custom-width', '');
        $img.css('--custom-height', '');
      } 
      // Para dimensões válidas, garantir que são aplicadas corretamente
      else if (width && width > 0) {
        console.log("Aplicando dimensão customizada: " + width + "x" + height);
        
        $img.addClass('custom-size');
        
        // Definir dimensões diretamente e via variáveis CSS
        $img.css('--custom-width', width + 'px');
        $img.css('width', width + 'px');
        
        if (height && height > 0) {
          $img.css('--custom-height', height + 'px');
          $img.css('height', height + 'px');
        } else {
          // Se apenas largura foi definida, manter proporção
          $img.css('--custom-height', 'auto');
          $img.css('height', 'auto');
        }
      }
    });
  }

  // Executa a função de correção após um breve atraso para garantir que as imagens foram inicializadas
  setTimeout(fixImageDimensions, 300);
  
  // Também executa quando o conteúdo da wiki é atualizado
  if (typeof mw !== 'undefined' && mw.hook) {
    mw.hook('wikipage.content').add(function() {
      console.log("Conteúdo da wiki atualizado - aplicando correções de dimensão");
      setTimeout(fixImageDimensions, 300);
    });
  }
});