# ai-builder/2.7.2/assets/js/carousel-frontend.js

AI Builder – Generate pages, blocks, images &amp; translate with AI, version 2.7.2. 76 lines.

- Page: https://pluginprobe.com/plugins/ai-builder/2.7.2/code/assets/js/carousel-frontend.js
- Raw: https://pluginprobe.com/plugins/ai-builder/2.7.2/raw/assets/js/carousel-frontend.js
- Modified: 2025-09-17T14:22:50+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/ai-builder/2.7.2/code/assets/js/carousel-frontend.js#L10-L20`.

```javascript
(function () {
  function initCarousel(root) {
    var track = root.querySelector(".aibui-carousel-track");
    if (!track) return;
    var slides = root.querySelectorAll(".aibui-carousel-slide");
    var dots = root.querySelectorAll(".aibui-carousel-dot");
    var prev = root.querySelector(".aibui-carousel-prev");
    var next = root.querySelector(".aibui-carousel-next");
    var idx = 0;
    var autoplay = root.getAttribute("data-autoplay") === "1";
    var delay = parseInt(root.getAttribute("data-delay") || "4", 10) * 1000;
    function getViewportWidth() {
      var holder = root.querySelector(".aibui-carousel-preview") || root;
      return holder.clientWidth || holder.offsetWidth || 0;
    }
    function update() {
      var w = getViewportWidth();
      track.style.transform = "translateX(" + -idx * w + "px)";
      dots.forEach(function (d, i) {
        d.classList.toggle("is-active", i === idx);
      });
    }
    function go(n) {
      idx = (n + slides.length) % slides.length;
      update();
    }
    if (prev)
      prev.addEventListener("click", function () {
        go(idx - 1);
      });
    if (next)
      next.addEventListener("click", function () {
        go(idx + 1);
      });
    var timer;
    function start() {
      if (autoplay && slides.length > 1) {
        stop();
        timer = setInterval(function () {
          go(idx + 1);
        }, delay);
      }
    }
    function stop() {
      if (timer) {
        clearInterval(timer);
        timer = null;
      }
    }
    root.addEventListener("mouseenter", stop);
    root.addEventListener("mouseleave", start);
    dots.forEach(function (d, i) {
      d.addEventListener("click", function () {
        go(i);
      });
    });
    update();
    start();
    // keep alignment on resize
    window.addEventListener("resize", update);
  }
  function boot() {
    var roots = document.querySelectorAll(
      ".wp-block-ai-builder-aibui-carousel"
    );
    for (var i = 0; i < roots.length; i++) {
      initCarousel(roots[i]);
    }
  }
  if (document.readyState === "loading") {
    document.addEventListener("DOMContentLoaded", boot);
  } else {
    boot();
  }
})();

```
