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
Etiquetas: Reversão manual Revertido
Linha 28: Linha 28:


   update();
   update();
});
mw.loader.using('jquery', function () {
  const wrapper = document.querySelector('.everlight-carousel .carousel-wrapper');
  const items = document.querySelectorAll('.everlight-carousel .carousel-item');
  const next = document.querySelector('.right-btn');
  const prev = document.querySelector('.left-btn');
  let current = 0;
  function updateCarousel() {
    items.forEach((item, index) => {
      item.classList.toggle('active', index === current);
    });
    const activeItem = items[current];
    const wrapperRect = wrapper.getBoundingClientRect();
    const itemRect = activeItem.getBoundingClientRect();
    const scrollPosition =
      activeItem.offsetLeft -
      (wrapperRect.width / 2) +
      (itemRect.width / 2);
    wrapper.scrollTo({
      left: scrollPosition,
      behavior: 'smooth'
    });
  }
  next.onclick = () => {
    if (current < items.length - 1) {
      current++;
      updateCarousel();
    }
  };
  prev.onclick = () => {
    if (current > 0) {
      current--;
      updateCarousel();
    }
  };
  // Centraliza o primeiro ao carregar
  updateCarousel();
});
});

Edição das 22h15min de 16 de janeiro de 2026

mw.loader.using('jquery', function () {
  const $carousel = $('.carousel-wrapper');
  const $items = $('.carousel-item');
  let index = 0;

  function update() {
    const itemWidth = $items.outerWidth(true);
    $carousel.scrollLeft(index * itemWidth);

    $items.removeClass('active');
    $items.eq(index).addClass('active');
  }

  $('.right-btn').on('click', function () {
    index = (index + 1) % $items.length;
    update();
  });

  $('.left-btn').on('click', function () {
    index = (index - 1 + $items.length) % $items.length;
    update();
  });

  setInterval(function () {
    index = (index + 1) % $items.length;
    update();
  }, 4000);

  update();
});