PageSourceSearch

https://swaminarayan.in/modules/mod_jmg_amazing_page_header/assets/js/mod_jmg_amazing_page_header_slider.js

js swaminarayan.in collected 2026-10-02 10:09:51 UTC 3,420 bytes, 111 lines download raw bytes

1(function () {
2    'use strict';
3
4    function initSlider(slider) {
5        var slides = slider.querySelectorAll('.mod_jmg_amazing_page_header_slide');
6        var dots = slider.querySelectorAll('.mod_jmg_amazing_page_header_slider_dot');
7        var prev = slider.querySelector('.mod_jmg_amazing_page_header_slider_prev');
8        var next = slider.querySelector('.mod_jmg_amazing_page_header_slider_next');
9        var current = 0;
10        var timer = null;
11        var autoplay = slider.getAttribute('data-autoplay') === '1';
12        var interval = parseInt(slider.getAttribute('data-interval') || '5000', 10);
13
14        if (slides.length <= 1) {
15            return;
16        }
17
18        function show(index) {
19            current = (index + slides.length) % slides.length;
20
21            slides.forEach(function (slide, slideIndex) {
22                slide.classList.toggle('is-active', slideIndex === current);
23            });
24
25            dots.forEach(function (dot, dotIndex) {
26                dot.classList.toggle('is-active', dotIndex === current);
27                dot.setAttribute('aria-selected', dotIndex === current ? 'true' : 'false');
28            });
29        }
30
31        function restartAutoplay() {
32            if (!autoplay) {
33                return;
34            }
35
36            window.clearInterval(timer);
37            timer = window.setInterval(function () {
38                show(current + 1);
39            }, Math.max(interval, 1000));
40        }
41
42        if (prev) {
43            prev.addEventListener('click', function () {
44                show(current - 1);
45                restartAutoplay();
46            });
47        }
48
49        if (next) {
50            next.addEventListener('click', function () {
51                show(current + 1);
52                restartAutoplay();
53            });
54        }
55
56        dots.forEach(function (dot, dotIndex) {
57            dot.addEventListener('click', function () {
58                show(dotIndex);
59                restartAutoplay();
60            });
61        });
62
63        var touchStartX = 0;
64
65        slider.addEventListener('touchstart', function (event) {
66            if (!event.changedTouches || !event.changedTouches.length) {
67                return;
68            }
69
70            touchStartX = event.changedTouches[0].screenX;
71        }, { passive: true });
72
73        slider.addEventListener('touchend', function (event) {
74            if (!event.changedTouches || !event.changedTouches.length) {
75                return;
76            }
77
78            var touchEndX = event.changedTouches[0].screenX;
79            var distance = touchEndX - touchStartX;
80
81            if (Math.abs(distance) > 50) {
82                show(distance > 0 ? current - 1 : current + 1);
83                restartAutoplay();
84            }
85        }, { passive: true });
86
87        slider.addEventListener('keydown', function (event) {
88            if (event.key === 'ArrowLeft') {
89                show(current - 1);
90                restartAutoplay();
91            }
92
93            if (event.key === 'ArrowRight') {
94                show(current + 1);
95                restartAutoplay();
96            }
97        });
98
99        restartAutoplay();
100    }
101
102    function init() {
103        document.querySelectorAll('.mod_jmg_amazing_page_header_slider').forEach(initSlider);
104    }
105
106    if (document.readyState === 'loading') {
107        document.addEventListener('DOMContentLoaded', init);
108    } else {
109        init();
110    }
111}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.