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

De Micropedia
Ir para navegação Ir para pesquisar
(ajuste)
(teste 01)
 
(5 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
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
+
 
−
========================================================= */
+
$(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;
 +
    });
 +
});
 +
 
 +
 
 +
 
  
 
jQuery(document).ready(function ($) {
 
jQuery(document).ready(function ($) {
  
−
/* =====================================================
+
    /* Sai imediatamente se não for a Página principal */
−
1. BOTÃO "VOLTAR AO TOPO" (único e otimizado)
+
    if (!$('body').hasClass('page-Página_principal')) return;
−
===================================================== */
 
−
let $topo = $('#botaoTopo');
 
  
−
if ($topo.length === 0) {
+
    /* ── 1. CARDS: aplica border-collapse separate via JS
−
$topo = $('<div id="botaoTopo">⬆ Topo</div>').css({
+
      (fallback para navegadores que ignoram em <table>) ── */
−
position: 'fixed',
+
    $('table.mph-card').css({
−
bottom: '20px',
+
        'border-radius':  '10px',
−
right: '20px',
+
        'border-collapse': 'separate',
−
padding: '8px 14px',
+
        'overflow':        'hidden'
−
background: '#9bbeab',
+
    });
−
color: '#1a3a28',
+
 
−
borderRadius: '8px',
+
    /* ── 2. BOTÃO VOLTAR AO TOPO
−
cursor: 'pointer',
+
      Reutiliza o #botaoTopo que o wiki já cria,
−
boxShadow: '0 2px 6px rgba(0,0,0,0.25)',
+
      ou cria um novo caso não exista ── */
−
fontWeight: 'bold',
+
    var $topo = $('#botaoTopo');
−
fontSize: '13px',
+
    if ($topo.length === 0) {
−
zIndex: 9999,
+
        $topo = $('<div id="botaoTopo">⬆ Topo</div>').css({
−
display: 'none'
+
            position:     'fixed',
−
});
+
            bottom:       '20px',
−
$('body').append($topo);
+
            right:       '20px',
−
}
+
            padding:     '8px 14px',
 +
            background:   '#9bbeab',
 +
            color:       '#1a3a28',
 +
            borderRadius: '8px',
 +
            cursor:       'pointer',
 +
            boxShadow:   '0 2px 6px rgba(0,0,0,0.25)',
 +
            fontWeight:   'bold',
 +
            fontSize:     '13px',
 +
            zIndex:       9999,
 +
            display:     'none'
 +
        });
 +
        $('body').append($topo);
 +
    }
  
−
$(window).on('scroll.mph', function () {
+
    $(window).on('scroll.mph', function () {
−
$topo.toggle($(this).scrollTop() > 400);
+
        $topo.toggle($(this).scrollTop() > 400);
−
});
+
    });
 +
    $topo.on('click', function () {
 +
        $('html, body').animate({ scrollTop: 0 }, 300);
 +
    });
  
−
$topo.on('click', function () {
+
    /* ── 3. LINKS EXTERNOS nos cards: nova aba ── */
−
$('html, body').animate({ scrollTop: 0 }, 300);
+
    $('.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) ── */
−
      2. APLICAÇÕES VISUAIS (APENAS NA PÁGINA PRINCIPAL)
+
    $('#firstHeading').hide();
−
      ===================================================== */
 
−
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 */
+
/* ── anti bot teste ── */
−
$('.mph-card a[href^="http"]')
+
$(function () {
−
.not('a[href*="' + window.location.hostname + '"]')
 
−
.attr({ target: '_blank', rel: 'noopener noreferrer' });
 
  
−
/* Hover suave nas imagens */
+
    // Só roda se estiver em página de edição
−
$('.mph-card li img').css({
+
    if (mw.config.get("wgAction") !== "edit") return;
−
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 form = document.getElementById('editform');
−
$('#firstHeading').hide();
+
    if (!form) return;
  
−
});
+
    form.addEventListener('submit', function (e) {
  
 +
        const answer = prompt("Digite o resultado de 2 + 2 para confirmar:");
  
−
/* =========================================================
+
        if (answer !== "4") {
−
  3. ANTI-SPAM (CAPTCHA SIMPLES)
+
            alert("Erro na verificação.");
−
  ========================================================= */
+
            e.preventDefault();
 +
        }
  
−
mw.hook('wikipage.editform').add(function () {
+
    });
  
−
/* Não aplicar para administradores */
+
});
−
if (mw.config.get("wgUserGroups").includes("sysop")) return;
 
  
−
const form = document.getElementById('editform');
+
/* ── move os dois selos pro título ── */
−
if (!form) return;
+
$(function () {
 +
  var $heading = $('#firstHeading');
 +
  if (!$heading.length) return;
  
−
form.addEventListener('submit', function (e) {
+
  var $badges = $('.selos-badges');
 +
  var $ga = $('#good-star');
  
−
const answer = prompt("Verificação rápida: quanto é 7 + 3?");
+
  if (!$badges.length && !$ga.length) return;
  
−
if (answer !== "10") {
+
  // Agrupa os dois tipos de selo num único wrapper, pra virar 1 item flex só
−
alert("Resposta incorreta. Tente novamente.");
+
  var $wrapper = $('<span class="firstHeading-selos"></span>');
−
e.preventDefault();
+
  if ($badges.length) $wrapper.append($badges);
−
}
+
  if ($ga.length) $wrapper.append($ga);
  
−
});
+
  $heading.append($wrapper);
 
});
 
});

Edição atual tal como às 03h26min de 3 de setembro de 2026

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

$(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;
    });
});




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'
    });

    /* ── 2. BOTÃO VOLTAR AO TOPO
       Reutiliza o #botaoTopo que o wiki já cria,
       ou cria um novo caso não exista ── */
    var $topo = $('#botaoTopo');
    if ($topo.length === 0) {
        $topo = $('<div id="botaoTopo">⬆ Topo</div>').css({
            position:     'fixed',
            bottom:       '20px',
            right:        '20px',
            padding:      '8px 14px',
            background:   '#9bbeab',
            color:        '#1a3a28',
            borderRadius: '8px',
            cursor:       'pointer',
            boxShadow:    '0 2px 6px rgba(0,0,0,0.25)',
            fontWeight:   'bold',
            fontSize:     '13px',
            zIndex:       9999,
            display:      'none'
        });
        $('body').append($topo);
    }

    $(window).on('scroll.mph', function () {
        $topo.toggle($(this).scrollTop() > 400);
    });
    $topo.on('click', function () {
        $('html, body').animate({ scrollTop: 0 }, 300);
    });

    /* ── 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();

});

/* ── anti bot teste ── */
$(function () {

    // Só roda se estiver em página de edição
    if (mw.config.get("wgAction") !== "edit") return;

    const form = document.getElementById('editform');
    if (!form) return;

    form.addEventListener('submit', function (e) {

        const answer = prompt("Digite o resultado de 2 + 2 para confirmar:");

        if (answer !== "4") {
            alert("Erro na verificação.");
            e.preventDefault();
        }

    });

});

/* ── move os dois selos pro título ── */
$(function () {
  var $heading = $('#firstHeading');
  if (!$heading.length) return;

  var $badges = $('.selos-badges');
  var $ga = $('#good-star');

  if (!$badges.length && !$ga.length) return;

  // Agrupa os dois tipos de selo num único wrapper, pra virar 1 item flex só
  var $wrapper = $('<span class="firstHeading-selos"></span>');
  if ($badges.length) $wrapper.append($badges);
  if ($ga.length) $wrapper.append($ga);

  $heading.append($wrapper);
});