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

De Micropedia
Ir para navegação Ir para pesquisar
(teste atualização)
(ajuste)
 
(9 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 34: Linha 34:
 
});
 
});
  
/* ═══════════════════════════════════════════
+
 
  MICROPÉDIA BRASIL — Common.js
+
 
  Melhorias de UX progressivas
 
  ═══════════════════════════════════════════ */
 
  
 
jQuery(document).ready(function ($) {
 
jQuery(document).ready(function ($) {
  
     /* ── 1. TICKER SUAVE
+
     /* Sai imediatamente se não for a Página principal */
      O letreiro usa marquee nativo, mas vamos garantir
+
     if (!$('body').hasClass('page-Página_principal')) return;
      que ele tenha a classe e o estilo corretos ── */
+
 
     $('marquee').each(function () {
+
    /* ── 1. CARDS: aplica border-collapse separate via JS
        $(this).closest('div, p')
+
      (fallback para navegadores que ignoram em <table>) ── */
            .addClass('LetreiroModern')
+
    $('table.mph-card').css({
            .css({ 'border-radius': '6px', 'overflow': 'hidden' });
+
        'border-radius':   '10px',
 +
        'border-collapse': 'separate',
 +
        'overflow':       'hidden'
 
     });
 
     });
  
     /* ── 2. CARDS — adiciona border-radius via JS
+
     /* ── 2. BOTÃO VOLTAR AO TOPO
       como fallback para navegadores que ignoram
+
       Reutiliza o #botaoTopo que o wiki já cria,
       border-radius em <table> ── */
+
       ou cria um novo caso não exista ── */
     $('table.MainPageBG.mph-card, table.mph-card').each(function () {
+
     var $topo = $('#botaoTopo');
         $(this).css({
+
    if ($topo.length === 0) {
             'border-radius': '10px',
+
         $topo = $('<div id="botaoTopo">⬆ Topo</div>').css({
             'overflow': 'hidden',
+
             position:    'fixed',
             'border-collapse': 'separate'
+
            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. SMOOTH SCROLL para links internos ── */
+
     /* ── 3. LINKS EXTERNOS nos cards: nova aba ── */
     $('a[href^="#"]').on('click', function (e) {
+
     $('.mph-card a[href^="http"]')
         var target = $(this.getAttribute('href'));
+
        .not('a[href*="micropedia.com.br"]')
        if (target.length) {
+
         .not('a[href*="' + window.location.hostname + '"]')
            e.preventDefault();
+
        .attr({ target: '_blank', rel: 'noopener noreferrer' });
            $('html, body').animate({ scrollTop: target.offset().top - 20 }, 350);
+
 
        }
+
    /* ── 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)');
 
     });
 
     });
  
     /* ── 4. LINKS EXTERNOS — abre em nova aba ── */
+
     /* ── 5. OCULTAR o título "Página principal" (redundante com o logo) ── */
     $('a[href^="http"]').not('a[href*="' + window.location.hostname + '"]').each(function () {
+
     $('#firstHeading').hide();
        $(this).attr('target', '_blank').attr('rel', 'noopener noreferrer');
+
 
     });
+
});
 +
 
 +
/* ── 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;
  
     /* ── 5. DESTAQUE NA BUSCA
+
     form.addEventListener('submit', function (e) {
      Sublinha o termo buscado nas páginas de resultado ── */
 
    var urlParams = new URLSearchParams(window.location.search);
 
    var searchTerm = urlParams.get('search');
 
    if (searchTerm && $('.searchresult, #mw-content-text').length) {
 
        /* highlight leve, sem quebrar links */
 
        var regex = new RegExp('(' + searchTerm.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') + ')', 'gi');
 
        $('#mw-content-text p, .searchresult').each(function () {
 
            if ($(this).find('a, input, button').length === 0) {
 
                $(this).html(
 
                    $(this).html().replace(
 
                        regex,
 
                        '<mark style="background:#ffdd75;color:#3a2e00;border-radius:3px;padding:0 2px;">$1</mark>'
 
                    )
 
                );
 
            }
 
        });
 
    }
 
  
    /* ── 6. BOTÃO "VOLTAR AO TOPO" ── */
+
         const answer = prompt("Digite o resultado de 2 + 2 para confirmar:");
    if ($('body').height() > 800) {
 
         var $btn = $('<button id="back-to-top" title="Voltar ao topo">▲</button>').css({
 
            position:  'fixed',
 
            bottom:    '20px',
 
            right:      '20px',
 
            background: '#9bbeab',
 
            color:      '#1a3a28',
 
            border:    '1px solid #82a895',
 
            borderRadius: '50%',
 
            width:      '36px',
 
            height:    '36px',
 
            fontSize:  '14px',
 
            fontWeight: 'bold',
 
            cursor:    'pointer',
 
            display:    'none',
 
            zIndex:    999,
 
            lineHeight: '34px',
 
            textAlign:  'center',
 
            boxShadow:  '0 2px 6px rgba(0,0,0,0.18)'
 
        });
 
        $('body').append($btn);
 
  
         $(window).on('scroll', function () {
+
         if (answer !== "4") {
             $btn.toggle($(this).scrollTop() > 300);
+
             alert("Erro na verificação.");
        });
+
             e.preventDefault();
        $btn.on('click', function () {
+
         }
             $('html, body').animate({ scrollTop: 0 }, 350);
 
         });
 
    }
 
  
    /* ── 7. EFEITO HOVER nas imagens dos artigos ── */
 
    $('#mw-content-text img, .thumbimage').css({
 
        'border-radius': '6px',
 
        'transition':    'transform 0.2s ease, box-shadow 0.2s ease'
 
    }).on('mouseenter', function () {
 
        $(this).css({ 'transform': 'scale(1.02)', 'box-shadow': '0 4px 12px rgba(0,0,0,0.15)' });
 
    }).on('mouseleave', function () {
 
        $(this).css({ 'transform': 'scale(1)', 'box-shadow': 'none' });
 
 
     });
 
     });
  
 
});
 
});

Edição atual tal como às 02h28min de 14 de abril 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();
        }

    });

});