Mudanças entre as edições de "MediaWiki:Common.js"

De Micropedia
Ir para navegação Ir para pesquisar
(ajuste)
(ajuste teste)
Linha 1: Linha 1:
/* =========================================================
+
/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */
Micropédia — Common.js otimizado
 
========================================================= */
 
  
jQuery(document).ready(function ($) {
 
  
/* =====================================================
+
/* =====================================================1. BOTÃO "VOLTAR AO TOPO" ===================================================== */
1. BOTÃO "VOLTAR AO TOPO" (único e otimizado)
+
$(function() {
===================================================== */
+
    // Cria o botão scroll-to-top button
let $topo = $('#botaoTopo');
+
    var $botaoTopo = $('<div id="botaoTopo">⬆️ Topo</div>').css({
 
+
        display: "none",
if ($topo.length === 0) {
+
        position: "fixed",
$topo = $('<div id="botaoTopo">Topo</div>').css({
+
        bottom: "85px", // <-- distância do roda pé (~85px)
position: 'fixed',
+
        right: "20px",
bottom: '20px',
+
        padding: "10px 15px",
right: '20px',
+
        background: "#9bbeab",
padding: '8px 14px',
+
        color: "#000",
background: '#9bbeab',
+
        "border-radius": "8px",
color: '#1a3a28',
+
        cursor: "pointer",
borderRadius: '8px',
+
        "box-shadow": "0 2px 6px rgba(0,0,0,0.3)",
cursor: 'pointer',
+
        "font-weight": "bold",
boxShadow: '0 2px 6px rgba(0,0,0,0.25)',
+
        "z-index": "9999"
fontWeight: 'bold',
+
    }).appendTo("body");
fontSize: '13px',
 
zIndex: 9999,
 
display: 'none'
 
});
 
$('body').append($topo);
 
}
 
  
$(window).on('scroll.mph', function () {
+
    // Mostrar/esconder com base no scroll
$topo.toggle($(this).scrollTop() > 400);
+
    $(window).scroll(function() {
});
+
        if ($(this).scrollTop() > $(document).height() / 2) {
 +
            $botaoTopo.fadeIn();
 +
        } else {
 +
            $botaoTopo.fadeOut();
 +
        }
 +
    });
  
$topo.on('click', function () {
+
    // Ação ao clicar
$('html, body').animate({ scrollTop: 0 }, 300);
+
    $botaoTopo.click(function() {
 +
        $("html, body").animate({scrollTop: 0}, 500);
 +
        return false;
 +
    });
 
});
 
});
  
 +
/* =========================================================2. ANTI-SPAM (CAPTCHA SIMPLES)========================================================= */
  
    /* =====================================================
+
mw.hook('wikipage.editform').add(function () {
      2. APLICAÇÕES VISUAIS (APENAS NA PÁGINA PRINCIPAL)
+
  const form = document.getElementById('editform');
      ===================================================== */
 
if (mw.config.get("wgPageName") !== "Página_principal") return;
 
 
 
/* Cards com borda arredondada correta */
 
$('table.mph-card').css({
 
borderRadius: '10px',
 
borderCollapse: 'separate',
 
overflow: 'hidden'
 
});
 
  
/* Links externos abrem em nova aba */
+
  if (!form) return;
$('.mph-card a[href^="http"]')
 
.not('a[href*="' + window.location.hostname + '"]')
 
.attr({ target: '_blank', rel: 'noopener noreferrer' });
 
 
 
/* Hover suave nas imagens */
 
$('.mph-card li img').css({
 
verticalAlign: 'middle',
 
transition: 'transform 0.15s ease'
 
}).on('mouseenter', function () {
 
$(this).css('transform', 'scale(1.06)');
 
}).on('mouseleave', function () {
 
$(this).css('transform', 'scale(1)');
 
});
 
  
/* Oculta título redundante */
+
  const answer = prompt("Digite 7 + 3 para confirmar:");
$('#firstHeading').hide();
 
  
 +
  if (answer !== "10") {
 +
    alert("Erro na verificação.");
 +
    form.addEventListener('submit', e => e.preventDefault());
 +
  }
 
});
 
});
  
  
/* =========================================================
+
/* =====================================================3. APLICAÇÕES VISUAIS (APENAS NA PÁGINA PRINCIPAL)===================================================== */
  3. ANTI-SPAM (CAPTCHA SIMPLES)
 
  ========================================================= */
 
  
mw.hook('wikipage.editform').add(function () {
+
jQuery(document).ready(function ($) {
  
/* Não aplicar para administradores */
+
    /* Sai imediatamente se não for a Página principal */
if (mw.config.get("wgUserGroups").includes("sysop")) return;
+
    if (!$('body').hasClass('page-Página_principal')) return;
  
const form = document.getElementById('editform');
+
    /* ── 1. CARDS: aplica border-collapse separate via JS
if (!form) return;
+
      (fallback para navegadores que ignoram em <table>) ── */
 +
    $('table.mph-card').css({
 +
        'border-radius':  '10px',
 +
        'border-collapse': 'separate',
 +
        'overflow':        'hidden'
 +
    });
  
form.addEventListener('submit', function (e) {
+
   
 +
    /* ── 3. LINKS EXTERNOS nos cards: nova aba ── */
 +
    $('.mph-card a[href^="http"]')
 +
        .not('a[href*="micropedia.com.br"]')
 +
        .not('a[href*="' + window.location.hostname + '"]')
 +
        .attr({ target: '_blank', rel: 'noopener noreferrer' });
  
const answer = prompt("Verificação rápida: quanto é 7 + 3?");
+
    /* ── 4. HOVER suave nas imagens dos Acontecimentos Recentes ── */
 +
    $('.mph-card li img').css({
 +
        'vertical-align': 'middle',
 +
        'transition':    'transform 0.15s ease'
 +
    }).on('mouseenter', function () {
 +
        $(this).css('transform', 'scale(1.06)');
 +
    }).on('mouseleave', function () {
 +
        $(this).css('transform', 'scale(1)');
 +
    });
  
if (answer !== "10") {
+
    /* ── 5. OCULTAR o título "Página principal" (redundante com o logo) ── */
alert("Resposta incorreta. Tente novamente.");
+
    $('#firstHeading').hide();
e.preventDefault();
 
}
 
  
});
 
 
});
 
});

Edição das 01h06min de 14 de abril de 2026

/* Códigos JavaScript aqui colocados serão carregados por todos aqueles que acessarem alguma página deste wiki */


/* =====================================================1. BOTÃO "VOLTAR AO TOPO" ===================================================== */
$(function() {
    // Cria o botão scroll-to-top button
    var $botaoTopo = $('<div id="botaoTopo">⬆️ Topo</div>').css({
        display: "none",
        position: "fixed",
        bottom: "85px", // <-- distância do roda pé (~85px)
        right: "20px",
        padding: "10px 15px",
        background: "#9bbeab",
        color: "#000",
        "border-radius": "8px",
        cursor: "pointer",
        "box-shadow": "0 2px 6px rgba(0,0,0,0.3)",
        "font-weight": "bold",
        "z-index": "9999"
    }).appendTo("body");

    // Mostrar/esconder com base no scroll
    $(window).scroll(function() {
        if ($(this).scrollTop() > $(document).height() / 2) {
            $botaoTopo.fadeIn();
        } else {
            $botaoTopo.fadeOut();
        }
    });

    // Ação ao clicar
    $botaoTopo.click(function() {
        $("html, body").animate({scrollTop: 0}, 500);
        return false;
    });
});

/* =========================================================2. ANTI-SPAM (CAPTCHA SIMPLES)========================================================= */

mw.hook('wikipage.editform').add(function () {
  const form = document.getElementById('editform');

  if (!form) return;

  const answer = prompt("Digite 7 + 3 para confirmar:");

  if (answer !== "10") {
    alert("Erro na verificação.");
    form.addEventListener('submit', e => e.preventDefault());
  }
});


/* =====================================================3. APLICAÇÕES VISUAIS (APENAS NA PÁGINA PRINCIPAL)===================================================== */

jQuery(document).ready(function ($) {

    /* Sai imediatamente se não for a Página principal */
    if (!$('body').hasClass('page-Página_principal')) return;

    /* ── 1. CARDS: aplica border-collapse separate via JS
       (fallback para navegadores que ignoram em <table>) ── */
    $('table.mph-card').css({
        'border-radius':   '10px',
        'border-collapse': 'separate',
        'overflow':        'hidden'
    });

    
    /* ── 3. LINKS EXTERNOS nos cards: nova aba ── */
    $('.mph-card a[href^="http"]')
        .not('a[href*="micropedia.com.br"]')
        .not('a[href*="' + window.location.hostname + '"]')
        .attr({ target: '_blank', rel: 'noopener noreferrer' });

    /* ── 4. HOVER suave nas imagens dos Acontecimentos Recentes ── */
    $('.mph-card li img').css({
        'vertical-align': 'middle',
        'transition':     'transform 0.15s ease'
    }).on('mouseenter', function () {
        $(this).css('transform', 'scale(1.06)');
    }).on('mouseleave', function () {
        $(this).css('transform', 'scale(1)');
    });

    /* ── 5. OCULTAR o título "Página principal" (redundante com o logo) ── */
    $('#firstHeading').hide();

});