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

De Farmland
Ir para navegação Ir para pesquisar
Sem resumo de edição
Etiqueta: Reversão manual
Sem resumo de edição
Linha 1: Linha 1:
mw.loader.using('jquery', function () {
/* =======================================================
  const $carousel = $('.carousel-wrapper');
  CARROSSEL UNIFICADO - WIKI EVERLIGHT
  const $items = $('.carousel-item');
  ======================================================= */
  let index = 0;
mw.loader.using(['jquery', 'mediawiki.util'], function () {
    $(function() {
        const $wrapper = $('.carousel-wrapper');
        const $items = $('.carousel-item');
        const $next = $('.right-btn');
        const $prev = $('.left-btn');
       
        if (!$wrapper.length) return; // Só executa se o carrossel existir na página


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


    $items.removeClass('active');
        function updateCarousel() {
    $items.eq(index).addClass('active');
            // Atualiza a classe ativa para o efeito visual de destaque
  }
            $items.removeClass('active').eq(current).addClass('active');


  $('.right-btn').on('click', function () {
            const activeItem = $items.get(current);
    index = (index + 1) % $items.length;
            const scrollPosition =
    update();
                activeItem.offsetLeft -  
  });
                ($wrapper.width() / 2) +
                ($(activeItem).outerWidth() / 2);


  $('.left-btn').on('click', function () {
            $wrapper.stop().animate({
    index = (index - 1 + $items.length) % $items.length;
                scrollLeft: scrollPosition
    update();
            }, 500);
  });
        }


  setInterval(function () {
        // Funções de Navegação
    index = (index + 1) % $items.length;
        function moveNext() {
    update();
            current = (current + 1) % $items.length;
  }, 4000);
            updateCarousel();
        }


  update();
        function movePrev() {
});
            current = (current - 1 + $items.length) % $items.length;
            updateCarousel();
        }


mw.loader.using('jquery', function () {
        // Eventos de Clique
  const wrapper = document.querySelector('.everlight-carousel .carousel-wrapper');
        $next.on('click', function() {
  const items = document.querySelectorAll('.everlight-carousel .carousel-item');
            stopAutoPlay();
  const next = document.querySelector('.right-btn');
            moveNext();
  const prev = document.querySelector('.left-btn');
        });


  let current = 0;
        $prev.on('click', function() {
            stopAutoPlay();
            movePrev();
        });


  function updateCarousel() {
        // Auto-Play (4 segundos)
    items.forEach((item, index) => {
        function startAutoPlay() {
      item.classList.toggle('active', index === current);
            autoPlayTimer = setInterval(moveNext, 4000);
    });
        }


    const activeItem = items[current];
        function stopAutoPlay() {
    const wrapperRect = wrapper.getBoundingClientRect();
            clearInterval(autoPlayTimer);
    const itemRect = activeItem.getBoundingClientRect();
        }


    const scrollPosition =
        // Inicialização
      activeItem.offsetLeft -
        updateCarousel();
      (wrapperRect.width / 2) +
        startAutoPlay();
      (itemRect.width / 2);


    wrapper.scrollTo({
        // Pausa o carrossel se o mouse estiver em cima
      left: scrollPosition,
        $wrapper.hover(stopAutoPlay, startAutoPlay);
      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 03h46min de 17 de janeiro de 2026

/* =======================================================
   CARROSSEL UNIFICADO - WIKI EVERLIGHT
   ======================================================= */
mw.loader.using(['jquery', 'mediawiki.util'], function () {
    $(function() {
        const $wrapper = $('.carousel-wrapper');
        const $items = $('.carousel-item');
        const $next = $('.right-btn');
        const $prev = $('.left-btn');
        
        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() {
            autoPlayTimer = setInterval(moveNext, 4000);
        }

        function stopAutoPlay() {
            clearInterval(autoPlayTimer);
        }

        // Inicialização
        updateCarousel();
        startAutoPlay();

        // Pausa o carrossel se o mouse estiver em cima
        $wrapper.hover(stopAutoPlay, startAutoPlay);
    });
});