Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
| Line 1: | Line 1: | ||
| − | /* | + | /* Adição ao seu common.js para corrigir problemas com dimensões de imagens */ |
$(document).ready(function() { | $(document).ready(function() { | ||
| − | // Função | + | // Função para corrigir o dimensionamento de imagens |
| − | + | function fixImageDimensions() { | |
| − | + | console.log("Corrigindo dimensões de imagens..."); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
$('.tile-top.tile-image img').each(function() { | $('.tile-top.tile-image img').each(function() { | ||
var $img = $(this); | var $img = $(this); | ||
| Line 41: | Line 11: | ||
var height = $img.data('height') || $img.attr('height'); | var height = $img.data('height') || $img.attr('height'); | ||
| − | if (width || 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'); | $img.addClass('custom-size'); | ||
| − | + | ||
| − | + | // Definir dimensões diretamente e via variáveis CSS | |
| − | + | $img.css('--custom-width', width + 'px'); | |
| − | if (height) { | + | $img.css('width', width + 'px'); |
| + | |||
| + | if (height && height > 0) { | ||
$img.css('--custom-height', height + 'px'); | $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'); | ||
} | } | ||
} | } | ||
| Line 53: | Line 53: | ||
} | } | ||
| − | // | + | // 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) { | if (typeof mw !== 'undefined' && mw.hook) { | ||
mw.hook('wikipage.content').add(function() { | mw.hook('wikipage.content').add(function() { | ||
| − | console.log("Conteúdo da wiki atualizado"); | + | console.log("Conteúdo da wiki atualizado - aplicando correções de dimensão"); |
| − | + | setTimeout(fixImageDimensions, 300); | |
| − | |||
| − | |||
| − | |||
| − | |||
}); | }); | ||
} | } | ||
}); | }); | ||
Revision as of 17:46, 7 May 2025
/* 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);
});
}
});