MediaWiki:Common.js: mudanças entre as edições

De Farmland
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
 
(56 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
const carousel = document.getElementById('carousel');
/* =======================================================
const cards = document.querySelectorAll('.card');
  ARVORE DE HABILIDADE
const nextBtn = document.getElementById('nextBtn');
  ======================================================= */
const prevBtn = document.getElementById('prevBtn');
document.addEventListener('DOMContentLoaded', function () {
    var cards = document.querySelectorAll('.skill-card');
    cards.forEach(function (card) {
        card.addEventListener('click', function () {
            card.style.filter = 'brightness(1.2)';
            setTimeout(function () { card.style.filter = 'brightness(1)'; }, 150);
        });
    });
});


let currentIndex = 2; // Começa com o terceiro card centralizado
const cardWidth = cards[0].offsetWidth + 20; // Largura + Gap


// Função para centralizar o card
/* =======================================================
function updateCarousel() {
  BOTAO VOLTAR AO TOPO
     carousel.scrollTo({
  ======================================================= */
        left: (currentIndex - 1) * cardWidth,
$(function () {
        behavior: 'smooth'
     var $button = $('<button id="back-to-top" title="Voltar ao Topo">↑ Topo</button>');
    });
    $('body').append($button);


     // Atualizar classe active
     $(window).scroll(function () {
    cards.forEach((card, index) => {
        if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
        card.classList.remove('active');
            $button.fadeIn();
         if (index === currentIndex) {
         } else {
             card.classList.add('active');
             $button.fadeOut();
         }
         }
     });
     });
}


// Navegação
    $button.click(function () {
nextBtn.addEventListener('click', () => {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
    if (currentIndex < cards.length - 1) {
         return false;
        currentIndex++;
     });
         updateCarousel();
     }
});
});


prevBtn.addEventListener('click', () => {
 
    if (currentIndex > 0) {
/* =======================================================
         currentIndex--;
  ARVORE DE CLASSES
         updateCarousel();
  ======================================================= */
     }
document.addEventListener('DOMContentLoaded', function () {
    var cells = document.querySelectorAll('.ragnarok-tree td[class^="evo-"]');
 
    cells.forEach(function (cell) {
        var link = cell.querySelector('a');
        if (link) {
            cell.style.cursor = 'pointer';
            cell.addEventListener('click', function () { window.location.href = link.href; });
        }
 
        cell.addEventListener('mouseenter', function () {
            var familyClass = Array.from(this.classList).find(function (c) { return c.startsWith('evo-'); });
            if (!familyClass || familyClass === 'evo-all') return;
 
            var myPos    = this.getAttribute('data-pos');
            var prevEl  = this.closest('table').previousElementSibling;
            var isClass1 = prevEl && prevEl.innerText.includes('Classe 1');
            var isClass2 = prevEl && prevEl.innerText.includes('Classe 2');
 
            if (isClass1) {
                document.querySelectorAll('.' + familyClass).forEach(function (el) {
                    el.classList.add('highlight-active');
                });
            } else if (isClass2) {
                this.classList.add('highlight-active');
                var table3 = document.querySelector('table:nth-of-type(3)');
                if (table3) {
                    table3.querySelectorAll('.' + familyClass).forEach(function (el) {
                        if (el.getAttribute('data-pos') === myPos) el.classList.add('highlight-active');
                    });
                }
            } else {
                this.classList.add('highlight-active');
            }
        });
 
         cell.addEventListener('mouseleave', function () {
            document.querySelectorAll('.highlight-active').forEach(function (el) {
                el.classList.remove('highlight-active');
            });
         });
     });
});
});


// Auto Slide (a cada 3 segundos)
setInterval(() => {
    if (currentIndex < cards.length - 1) {
        currentIndex++;
    } else {
        currentIndex = 0; // Volta ao início
    }
    updateCarousel();
}, 3000);


// Iniciar centralizado
updateCarousel();


<script src="script.js"></script>


document.addEventListener('DOMContentLoaded', function () {
/* =======================================================
   const carousels = document.querySelectorAll('.everlight-carousel');
  CARROSSEL FARMLAND
  ======================================================= */
mw.hook('wikipage.content').add(function () {
 
    var carousel = document.getElementById('farmlandCarousel');
    if (!carousel) return;
 
    var wrapper  = carousel.querySelector('.carousel-wrapper');
    var container = carousel.querySelector('.carousel-container');
    var slides   = carousel.querySelectorAll('.carousel-slide');
    var dotsWrap = carousel.querySelector('.carousel-dots');
    var progBar  = carousel.querySelector('.carousel-progress');
    var nextBtn  = carousel.querySelector('.carousel-arrow.right');
    var prevBtn  = carousel.querySelector('.carousel-arrow.left');
 
    if (!container || slides.length === 0) return;
 
    var DELAY = 3500;
    var total = slides.length;
    var idx  = 1;
    var timer, busy = false;
 
    /* Clones para loop infinito sem flash */
    var firstClone = slides[0].cloneNode(true);
    var lastClone  = slides[total - 1].cloneNode(true);
    firstClone.classList.add('clone');
    lastClone.classList.add('clone');
    container.appendChild(firstClone);
    container.insertBefore(lastClone, slides[0]);


  carousels.forEach(carousel => {
     var allSlides = container.querySelectorAll('.carousel-slide');
    const wrapper = carousel.querySelector('.carousel-wrapper');
     const cards = carousel.querySelectorAll('.card');
    const nextBtn = carousel.querySelector('.right-btn');
    const prevBtn = carousel.querySelector('.left-btn');


     let currentIndex = 0;
     /* Força layout correto (crítico no MediaWiki) */
     const cardWidth = cards[0].offsetWidth + 20;
    container.style.display    = 'flex';
    container.style.transition = 'none';
     allSlides.forEach(function (s) {
        s.style.minWidth  = '100%';
        s.style.flexShrink = '0';
    });
    container.style.transform = 'translateX(-' + (idx * 100) + '%)';


     function updateCarousel() {
     /* Dots */
      wrapper.scrollTo({
    dotsWrap.innerHTML = '';
         left: currentIndex * cardWidth,
    var dots = [];
         behavior: 'smooth'
    for (var i = 0; i < total; i++) {
      });
        var dot = document.createElement('span');
        dot.className = 'dot';
        dotsWrap.appendChild(dot);
         dots.push(dot);
         (function (n) {
            dot.onclick = function () { goTo(n + 1); resetAuto(); };
        })(i);
    }


      cards.forEach((card, index) => {
    function updateDots() {
        card.classList.toggle('active', index === currentIndex);
        var ai = idx - 1;
      });
        if (ai < 0) ai = total - 1;
        if (ai >= total) ai = 0;
        dots.forEach(function (d, i) {
            d.classList.toggle('active', i === ai);
        });
     }
     }


     nextBtn.addEventListener('click', () => {
     function goTo(i, animate) {
      currentIndex = (currentIndex + 1) % cards.length;
        if (busy) return;
      updateCarousel();
        busy = true;
     });
        idx  = i;
        container.style.transition = (animate === false)
            ? 'none'
            : 'transform 0.5s cubic-bezier(.4,0,.2,1)';
        container.style.transform = 'translateX(-' + (idx * 100) + '%)';
        updateDots();
     }


     prevBtn.addEventListener('click', () => {
     container.addEventListener('transitionend', function () {
      currentIndex = (currentIndex - 1 + cards.length) % cards.length;
        if (allSlides[idx] && allSlides[idx].classList.contains('clone')) {
      updateCarousel();
            container.style.transition = 'none';
            idx = (idx === 0) ? total : 1;
            container.style.transform = 'translateX(-' + (idx * 100) + '%)';
            updateDots();
        }
        busy = false;
     });
     });


     setInterval(() => {
     function next() { goTo(idx + 1); resetAuto(); }
      currentIndex = (currentIndex + 1) % cards.length;
     function prev() { goTo(idx - 1); resetAuto(); }
      updateCarousel();
     }, 4000);


     updateCarousel();
     if (nextBtn) nextBtn.onclick = next;
  });
    if (prevBtn) prevBtn.onclick = prev;
});


<script>
    /* Barra de progresso */
const carousel = document.getElementById('carousel');
    function startProg() {
const cards = document.querySelectorAll('.card');
        if (!progBar) return;
const nextBtn = document.getElementById('nextBtn');
        progBar.style.transition = 'none';
const prevBtn = document.getElementById('prevBtn');
        progBar.style.width = '0%';
        setTimeout(function () {
            progBar.style.transition = 'width ' + DELAY + 'ms linear';
            progBar.style.width = '100%';
        }, 30);
    }


let currentIndex = 2;
    function startAuto() {
const cardWidth = cards[0].offsetWidth + 20;
        timer = setInterval(function () { goTo(idx + 1); startProg(); }, DELAY);
        startProg();
    }


function updateCarousel() {
    function stopAuto() {
    carousel.scrollTo({
        clearInterval(timer);
         left: (currentIndex - 1) * cardWidth,
         if (progBar) { progBar.style.transition = 'none'; progBar.style.width = '0%'; }
        behavior: 'smooth'
     }
     });


     cards.forEach((card, index) => {
     function resetAuto() { clearInterval(timer); startAuto(); }
        card.classList.toggle('active', index === currentIndex);
    });
}


nextBtn.addEventListener('click', () => {
    /* Pausa no hover */
     if (currentIndex < cards.length - 1) {
     if (wrapper) {
         currentIndex++;
         wrapper.addEventListener('mouseenter', stopAuto);
         updateCarousel();
         wrapper.addEventListener('mouseleave', startAuto);
     }
     }
});


prevBtn.addEventListener('click', () => {
    /* Swipe mobile */
    if (currentIndex > 0) {
    var startX = 0;
        currentIndex--;
    if (wrapper) {
         updateCarousel();
        wrapper.addEventListener('touchstart', function (e) { startX = e.touches[0].clientX; });
        wrapper.addEventListener('touchend', function (e) {
            var diff = startX - e.changedTouches[0].clientX;
            if (Math.abs(diff) > 40) { diff > 0 ? next() : prev(); }
         });
     }
     }
    updateDots();
    startAuto();
});
});
setInterval(() => {
    currentIndex = (currentIndex + 1) % cards.length;
    updateCarousel();
}, 3000);
updateCarousel();
</script>

Edição atual tal como às 21h15min de 16 de maio de 2026

/* =======================================================
   ARVORE DE HABILIDADE
   ======================================================= */
document.addEventListener('DOMContentLoaded', function () {
    var cards = document.querySelectorAll('.skill-card');
    cards.forEach(function (card) {
        card.addEventListener('click', function () {
            card.style.filter = 'brightness(1.2)';
            setTimeout(function () { card.style.filter = 'brightness(1)'; }, 150);
        });
    });
});


/* =======================================================
   BOTAO VOLTAR AO TOPO
   ======================================================= */
$(function () {
    var $button = $('<button id="back-to-top" title="Voltar ao Topo">↑ Topo</button>');
    $('body').append($button);

    $(window).scroll(function () {
        if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
            $button.fadeIn();
        } else {
            $button.fadeOut();
        }
    });

    $button.click(function () {
        $('html, body').animate({ scrollTop: 0 }, 'slow');
        return false;
    });
});


/* =======================================================
   ARVORE DE CLASSES
   ======================================================= */
document.addEventListener('DOMContentLoaded', function () {
    var cells = document.querySelectorAll('.ragnarok-tree td[class^="evo-"]');

    cells.forEach(function (cell) {
        var link = cell.querySelector('a');
        if (link) {
            cell.style.cursor = 'pointer';
            cell.addEventListener('click', function () { window.location.href = link.href; });
        }

        cell.addEventListener('mouseenter', function () {
            var familyClass = Array.from(this.classList).find(function (c) { return c.startsWith('evo-'); });
            if (!familyClass || familyClass === 'evo-all') return;

            var myPos    = this.getAttribute('data-pos');
            var prevEl   = this.closest('table').previousElementSibling;
            var isClass1 = prevEl && prevEl.innerText.includes('Classe 1');
            var isClass2 = prevEl && prevEl.innerText.includes('Classe 2');

            if (isClass1) {
                document.querySelectorAll('.' + familyClass).forEach(function (el) {
                    el.classList.add('highlight-active');
                });
            } else if (isClass2) {
                this.classList.add('highlight-active');
                var table3 = document.querySelector('table:nth-of-type(3)');
                if (table3) {
                    table3.querySelectorAll('.' + familyClass).forEach(function (el) {
                        if (el.getAttribute('data-pos') === myPos) el.classList.add('highlight-active');
                    });
                }
            } else {
                this.classList.add('highlight-active');
            }
        });

        cell.addEventListener('mouseleave', function () {
            document.querySelectorAll('.highlight-active').forEach(function (el) {
                el.classList.remove('highlight-active');
            });
        });
    });
});




/* =======================================================
   CARROSSEL FARMLAND
   ======================================================= */
mw.hook('wikipage.content').add(function () {

    var carousel = document.getElementById('farmlandCarousel');
    if (!carousel) return;

    var wrapper  = carousel.querySelector('.carousel-wrapper');
    var container = carousel.querySelector('.carousel-container');
    var slides   = carousel.querySelectorAll('.carousel-slide');
    var dotsWrap = carousel.querySelector('.carousel-dots');
    var progBar  = carousel.querySelector('.carousel-progress');
    var nextBtn  = carousel.querySelector('.carousel-arrow.right');
    var prevBtn  = carousel.querySelector('.carousel-arrow.left');

    if (!container || slides.length === 0) return;

    var DELAY = 3500;
    var total = slides.length;
    var idx   = 1;
    var timer, busy = false;

    /* Clones para loop infinito sem flash */
    var firstClone = slides[0].cloneNode(true);
    var lastClone  = slides[total - 1].cloneNode(true);
    firstClone.classList.add('clone');
    lastClone.classList.add('clone');
    container.appendChild(firstClone);
    container.insertBefore(lastClone, slides[0]);

    var allSlides = container.querySelectorAll('.carousel-slide');

    /* Força layout correto (crítico no MediaWiki) */
    container.style.display    = 'flex';
    container.style.transition = 'none';
    allSlides.forEach(function (s) {
        s.style.minWidth   = '100%';
        s.style.flexShrink = '0';
    });
    container.style.transform = 'translateX(-' + (idx * 100) + '%)';

    /* Dots */
    dotsWrap.innerHTML = '';
    var dots = [];
    for (var i = 0; i < total; i++) {
        var dot = document.createElement('span');
        dot.className = 'dot';
        dotsWrap.appendChild(dot);
        dots.push(dot);
        (function (n) {
            dot.onclick = function () { goTo(n + 1); resetAuto(); };
        })(i);
    }

    function updateDots() {
        var ai = idx - 1;
        if (ai < 0) ai = total - 1;
        if (ai >= total) ai = 0;
        dots.forEach(function (d, i) {
            d.classList.toggle('active', i === ai);
        });
    }

    function goTo(i, animate) {
        if (busy) return;
        busy = true;
        idx  = i;
        container.style.transition = (animate === false)
            ? 'none'
            : 'transform 0.5s cubic-bezier(.4,0,.2,1)';
        container.style.transform = 'translateX(-' + (idx * 100) + '%)';
        updateDots();
    }

    container.addEventListener('transitionend', function () {
        if (allSlides[idx] && allSlides[idx].classList.contains('clone')) {
            container.style.transition = 'none';
            idx = (idx === 0) ? total : 1;
            container.style.transform = 'translateX(-' + (idx * 100) + '%)';
            updateDots();
        }
        busy = false;
    });

    function next() { goTo(idx + 1); resetAuto(); }
    function prev() { goTo(idx - 1); resetAuto(); }

    if (nextBtn) nextBtn.onclick = next;
    if (prevBtn) prevBtn.onclick = prev;

    /* Barra de progresso */
    function startProg() {
        if (!progBar) return;
        progBar.style.transition = 'none';
        progBar.style.width = '0%';
        setTimeout(function () {
            progBar.style.transition = 'width ' + DELAY + 'ms linear';
            progBar.style.width = '100%';
        }, 30);
    }

    function startAuto() {
        timer = setInterval(function () { goTo(idx + 1); startProg(); }, DELAY);
        startProg();
    }

    function stopAuto() {
        clearInterval(timer);
        if (progBar) { progBar.style.transition = 'none'; progBar.style.width = '0%'; }
    }

    function resetAuto() { clearInterval(timer); startAuto(); }

    /* Pausa no hover */
    if (wrapper) {
        wrapper.addEventListener('mouseenter', stopAuto);
        wrapper.addEventListener('mouseleave', startAuto);
    }

    /* Swipe mobile */
    var startX = 0;
    if (wrapper) {
        wrapper.addEventListener('touchstart', function (e) { startX = e.touches[0].clientX; });
        wrapper.addEventListener('touchend', function (e) {
            var diff = startX - e.changedTouches[0].clientX;
            if (Math.abs(diff) > 40) { diff > 0 ? next() : prev(); }
        });
    }

    updateDots();
    startAuto();
});