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

De Farmland
Ir para navegação Ir para pesquisar
Sem resumo de edição
Etiqueta: Revertido
Sem resumo de edição
 
(33 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
/* =======================================================
/* =======================================================
   CARROSSEL UNIFICADO - WIKI EVERLIGHT
   ARVORE DE HABILIDADE
   ======================================================= */
   ======================================================= */
mw.loader.using(['jquery', 'mediawiki.util'], function () {
document.addEventListener('DOMContentLoaded', function () {
     $(function() {
     var cards = document.querySelectorAll('.skill-card');
        const $wrapper = $('.carousel-wrapper');
    cards.forEach(function (card) {
        const $items = $('.carousel-item');
        card.addEventListener('click', function () {
        const $next = $('.right-btn');
             card.style.filter = 'brightness(1.2)';
        const $prev = $('.left-btn');
             setTimeout(function () { card.style.filter = 'brightness(1)'; }, 150);
       
        if (!$wrapper.length) return; // Só executa se o carrossel existir na página
 
        let current = 0;
        let autoPlayTimer;
 
        function updateCarousel() {
            // Atualiza a classe ativa para o efeito visual de destaque
            $items.removeClass('active').eq(current).addClass('active');
 
             const activeItem = $items.get(current);
            const scrollPosition =  
                activeItem.offsetLeft -
                ($wrapper.width() / 2) +
                ($(activeItem).outerWidth() / 2);
 
             $wrapper.stop().animate({
                scrollLeft: scrollPosition
            }, 500);
        }
 
        // Funções de Navegação
        function moveNext() {
            current = (current + 1) % $items.length;
            updateCarousel();
        }
 
        function movePrev() {
            current = (current - 1 + $items.length) % $items.length;
            updateCarousel();
        }
 
        // Eventos de Clique
        $next.on('click', function() {
            stopAutoPlay();
            moveNext();
         });
         });
    });
});


        $prev.on('click', function() {
            stopAutoPlay();
            movePrev();
        });


        // Auto-Play (4 segundos)
/* =======================================================
        function startAutoPlay() {
  BOTAO VOLTAR AO TOPO
            autoPlayTimer = setInterval(moveNext, 4000);
  ======================================================= */
        }
$(function () {
    var $button = $('<button id="back-to-top" title="Voltar ao Topo">↑ Topo</button>');
    $('body').append($button);


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


        // Inicialização
    $button.click(function () {
        updateCarousel();
         $('html, body').animate({ scrollTop: 0 }, 'slow');
         startAutoPlay();
        return false;
 
        // Pausa o carrossel se o mouse estiver em cima
        $wrapper.hover(stopAutoPlay, startAutoPlay);
     });
     });
});
});
Linha 71: Linha 36:


/* =======================================================
/* =======================================================
   ARVORE HABILIDADE - WIKI EVERLIGHT
   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; });
        }


document.addEventListener('DOMContentLoaded', () => {
        cell.addEventListener('mouseenter', function () {
    const cards = document.querySelectorAll('.skill-card');
            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');
            }
        });


    cards.forEach(card => {
         cell.addEventListener('mouseleave', function () {
         card.addEventListener('click', () => {
             document.querySelectorAll('.highlight-active').forEach(function (el) {
             const skillName = card.querySelector('.skill-name').innerText;
                 el.classList.remove('highlight-active');
            console.log(`Habilidade clicada: ${skillName}`);
             });
           
            // Exemplo de efeito visual simples
            card.style.filter = "brightness(1.2)";
            setTimeout(() => {
                 card.style.filter = "brightness(1)";
             }, 150);
         });
         });
     });
     });
});
});


document.querySelectorAll('.carousel-track').forEach(track => {
  track.addEventListener('mouseenter', () => {
    track.querySelectorAll('.carousel-item').forEach(item => {
      item.style.animationPlayState = 'paused';
    });
  });
  track.addEventListener('mouseleave', () => {
    track.querySelectorAll('.carousel-item').forEach(item => {
      item.style.animationPlayState = 'running';
    });
  });
});






/* =======================================================
  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 */
// FUNCIONALIDADE DOS BOTÕES
    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]);


document.addEventListener('DOMContentLoaded', function() {
     var allSlides = container.querySelectorAll('.carousel-slide');
  const guideItems = document.querySelectorAll('.hr-guide-item');
  const filterButtons = document.querySelectorAll('.filter-btn');
  const searchInput = document.querySelector('.search-input');
  const searchClear = document.querySelector('.search-clear');
  const controlButtons = {
    shuffle: document.getElementById('shuffleGuides'),
    expand: document.getElementById('expandAll'),
     collapse: document.getElementById('collapseAll'),
    popular: document.getElementById('showPopular'),
    icons: document.getElementById('toggleIcons')
  };
  const pageButtons = document.querySelectorAll('.page-btn, .page-number');


  // 1. FILTRAGEM
    /* Força layout correto (crítico no MediaWiki) */
  filterButtons.forEach(button => {
    container.style.display    = 'flex';
     button.addEventListener('click', function() {
    container.style.transition = 'none';
      // Remove active de todos
     allSlides.forEach(function (s) {
      filterButtons.forEach(btn => btn.classList.remove('active'));
        s.style.minWidth  = '100%';
      // Adiciona active no clicado
        s.style.flexShrink = '0';
      this.classList.add('active');
     
      const filter = this.dataset.filter;
      filterGuides(filter);
     });
     });
  });
    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 filterGuides(filter) {
    function goTo(i, animate) {
    guideItems.forEach(item => {
        if (busy) return;
      const category = item.dataset.category;
         busy = true;
      const isPopular = item.dataset.popular === 'true';
         idx  = i;
      const isUpdated = item.dataset.updated === 'true';
         container.style.transition = (animate === false)
     
            ? 'none'
      let shouldShow = true;
            : 'transform 0.5s cubic-bezier(.4,0,.2,1)';
     
         container.style.transform = 'translateX(-' + (idx * 100) + '%)';
      switch(filter) {
         updateDots();
         case 'all':
     }
          shouldShow = true;
          break;
         case 'progression':
          shouldShow = category === 'progression';
          break;
         case 'systems':
          shouldShow = category === 'systems';
          break;
        case 'economy':
          shouldShow = category === 'economy';
          break;
        case 'content':
          shouldShow = category === 'content';
          break;
        case 'popular':
          shouldShow = isPopular;
          break;
        case 'updated':
          shouldShow = isUpdated;
          break;
      }
     
      if (shouldShow) {
        item.classList.remove('hidden');
         setTimeout(() => {
          item.classList.add('highlighted');
          setTimeout(() => item.classList.remove('highlighted'), 300);
         }, 100);
      } else {
        item.classList.add('hidden');
      }
     });
  }


  // 2. BUSCA EM TEMPO REAL
    container.addEventListener('transitionend', function () {
  searchInput.addEventListener('input', function() {
        if (allSlides[idx] && allSlides[idx].classList.contains('clone')) {
    const term = this.value.toLowerCase().trim();
            container.style.transition = 'none';
   
            idx = (idx === 0) ? total : 1;
    guideItems.forEach(item => {
            container.style.transform = 'translateX(-' + (idx * 100) + '%)';
      const link = item.querySelector('.guide-link');
            updateDots();
      const text = link.textContent.toLowerCase();
     
      if (term === '' || text.includes(term)) {
        item.classList.remove('hidden');
        if (term !== '') {
          item.classList.add('highlighted');
        } else {
          item.classList.remove('highlighted');
         }
         }
      } else {
         busy = false;
         item.classList.add('hidden');
        item.classList.remove('highlighted');
      }
     });
     });
  });


  searchClear.addEventListener('click', function() {
    function next() { goTo(idx + 1); resetAuto(); }
    searchInput.value = '';
     function prev() { goTo(idx - 1); resetAuto(); }
     searchInput.dispatchEvent(new Event('input'));
  });


  // 3. EMBARALHAR GUIAS
    if (nextBtn) nextBtn.onclick = next;
  controlButtons.shuffle.addEventListener('click', function() {
     if (prevBtn) prevBtn.onclick = prev;
    const grid = document.querySelector('.hr-guides-grid');
 
     const items = Array.from(guideItems);
     /* Barra de progresso */
   
     function startProg() {
     // Embaralha array
        if (!progBar) return;
     for (let i = items.length - 1; i > 0; i--) {
        progBar.style.transition = 'none';
      const j = Math.floor(Math.random() * (i + 1));
        progBar.style.width = '0%';
      [items[i], items[j]] = [items[j], items[i]];
        setTimeout(function () {
            progBar.style.transition = 'width ' + DELAY + 'ms linear';
            progBar.style.width = '100%';
        }, 30);
     }
     }
   
    // Remove e readiciona em ordem embaralhada
    items.forEach(item => {
      grid.appendChild(item);
      item.classList.add('highlighted');
      setTimeout(() => item.classList.remove('highlighted'), 500);
    });
   
    // Efeito visual
    this.classList.add('shuffling');
    setTimeout(() => this.classList.remove('shuffling'), 1000);
  });


  // 4. MOSTRAR POPULARES
    function startAuto() {
  controlButtons.popular.addEventListener('click', function() {
        timer = setInterval(function () { goTo(idx + 1); startProg(); }, DELAY);
    filterButtons.forEach(btn => btn.classList.remove('active'));
        startProg();
    document.querySelector('[data-filter="popular"]').classList.add('active');
    }
    filterGuides('popular');
  });


  // 5. TOGGLE ÍCONES
    function stopAuto() {
  controlButtons.icons.addEventListener('click', function() {
        clearInterval(timer);
    const icons = document.querySelectorAll('.hr-icon');
        if (progBar) { progBar.style.transition = 'none'; progBar.style.width = '0%'; }
    const areHidden = icons[0].style.opacity === '0';
     }
   
    icons.forEach(icon => {
      icon.style.opacity = areHidden ? '1' : '0';
      icon.style.transform = areHidden ? 'scale(1)' : 'scale(0)';
    });
   
     this.querySelector('.control-icon').textContent = areHidden ? '👁️' : '👁️‍🗨️';
  });


  // 6. PAGINAÇÃO (exemplo básico)
     function resetAuto() { clearInterval(timer); startAuto(); }
  pageButtons.forEach(button => {
     button.addEventListener('click', function() {
      if (this.classList.contains('active') || this.disabled) return;
     
      // Atualiza página ativa
      document.querySelectorAll('.page-number.active').forEach(el => {
        el.classList.remove('active');
      });
     
      if (this.classList.contains('page-number')) {
        this.classList.add('active');
      }
     
      // Aqui você implementaria a lógica de paginação real
      // Por enquanto apenas efeito visual
      guideItems.forEach(item => {
        item.classList.add('hidden');
        setTimeout(() => item.classList.remove('hidden'), 300);
      });
    });
  });


  // 7. CONTADOR DINÂMICO
    /* Pausa no hover */
  function updateGuideCount() {
    if (wrapper) {
    const visibleGuides = Array.from(guideItems).filter(item =>
        wrapper.addEventListener('mouseenter', stopAuto);
      !item.classList.contains('hidden')
        wrapper.addEventListener('mouseleave', startAuto);
    ).length;
    }
   
    document.querySelector('.stat-count').textContent = visibleGuides;
  }


  // Atualiza contador em todas as interações
    /* Swipe mobile */
  const observer = new MutationObserver(updateGuideCount);
    var startX = 0;
  guideItems.forEach(item => {
    if (wrapper) {
    observer.observe(item, {  
        wrapper.addEventListener('touchstart', function (e) { startX = e.touches[0].clientX; });
      attributes: true,
        wrapper.addEventListener('touchend', function (e) {
      attributeFilter: ['class']  
            var diff = startX - e.changedTouches[0].clientX;
    });
            if (Math.abs(diff) > 40) { diff > 0 ? next() : prev(); }
  });
        });
    }


  // Inicialização
    updateDots();
  updateGuideCount();
    startAuto();
});
});

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