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

De Micropedia
Ir para navegação Ir para pesquisar
(teste de script 03)
(teste 05)
 
(Uma revisão intermediária pelo mesmo usuário não está sendo mostrada)
Linha 34: Linha 34:
 
});
 
});
  
/* Script teste - slideshow trocar de imagem /*
+
// Script teste - slideshow trocar de imagem
mw.loader.using(['jquery'], function () {
+
mw.hook('wikipage.content').add(function () {
  
     function autoPlayGallery() {
+
     document.querySelectorAll('.gallerycarousel').forEach(function (carousel) {
  
         $('.gallerycarousel').each(function () {
+
         if (carousel.dataset.autoplay) return;
            const $gallery = $(this);
+
        carousel.dataset.autoplay = 'true';
  
            if ($gallery.data('autoplay')) return;
+
        const nextBtn = carousel.querySelector('.oo-ui-icon-next');
            $gallery.data('autoplay', true);
 
  
            setInterval(function () {
+
        if (!nextBtn) return;
                // Simula tecla → (ArrowRight)
 
                const e = new KeyboardEvent('keydown', {
 
                    key: 'ArrowRight',
 
                    code: 'ArrowRight',
 
                    keyCode: 39,
 
                    which: 39,
 
                    bubbles: true
 
                });
 
  
                $gallery[0].dispatchEvent(e);
+
        setInterval(function () {
             }, 4000);
+
            // força foco no botão
        });
+
             nextBtn.closest('a')?.focus();
    }
 
  
    mw.hook('wikipage.content').add(function () {
+
            // dispara clique REAL
         autoPlayGallery();
+
            nextBtn.closest('a').dispatchEvent(
 +
                new MouseEvent('click', {
 +
                    bubbles: true,
 +
                    cancelable: true,
 +
                    view: window
 +
                })
 +
            );
 +
         }, 4000); // tempo entre slides
 
     });
 
     });
 
 
});
 
});

Edição atual tal como às 05h09min de 8 de janeiro 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;
    });
});

// Script teste - slideshow trocar de imagem
mw.hook('wikipage.content').add(function () {

    document.querySelectorAll('.gallerycarousel').forEach(function (carousel) {

        if (carousel.dataset.autoplay) return;
        carousel.dataset.autoplay = 'true';

        const nextBtn = carousel.querySelector('.oo-ui-icon-next');

        if (!nextBtn) return;

        setInterval(function () {
            // força foco no botão
            nextBtn.closest('a')?.focus();

            // dispara clique REAL
            nextBtn.closest('a').dispatchEvent(
                new MouseEvent('click', {
                    bubbles: true,
                    cancelable: true,
                    view: window
                })
            );
        }, 4000); // tempo entre slides
    });
});