PageSourceSearch

https://daniel-lambert.de/wp-content/plugins/heros-slider/assets/js/frontend.js?ver=3.3.2

js daniel-lambert.de collected 2026-09-26 07:37:12 UTC 6,783 bytes, 195 lines download raw bytes

1( function () {
2    'use strict';
3
4    document.addEventListener( 'DOMContentLoaded', function () {
5        var sliders = document.querySelectorAll( '.heros-slider' );
6        sliders.forEach( initSlider );
7        sliders.forEach( equalizeHeight );
8
9        var resizeTimer = null;
10        window.addEventListener( 'resize', function () {
11            window.clearTimeout( resizeTimer );
12            resizeTimer = window.setTimeout( function () {
13                sliders.forEach( equalizeHeight );
14            }, 150 );
15        } );
16
17        // Nach vollständigem Laden (Fonts/Bilder) erneut messen.
18        window.addEventListener( 'load', function () {
19            sliders.forEach( equalizeHeight );
20        } );
21    } );
22
23    /**
24     * Fixe Slider-Höhe garantieren: Höhe = max( konfigurierte Höhe,
25     * höchster Slide-Inhalt ). Dadurch springt die Seite beim
26     * Slide-Wechsel nie und kein Inhalt wird abgeschnitten.
27     */
28    function equalizeHeight( slider ) {
29        var inners = slider.querySelectorAll( '.heros-slide-inner' );
30        if ( ! inners.length ) {
31            return;
32        }
33
34        slider.classList.remove( 'hs-equalized' );
35        slider.style.height = '';
36
37        var base = slider.clientHeight;
38        var max = 0;
39        inners.forEach( function ( inner ) {
40            max = Math.max( max, inner.scrollHeight );
41        } );
42
43        var target = Math.max( base, max );
44        if ( target > 0 && ( target > base || slider.classList.contains( 'hs-mobile-auto' ) ) ) {
45            slider.style.height = target + 'px';
46            slider.classList.add( 'hs-equalized' );
47        }
48    }
49
50    function initSlider( slider ) {
51        var slides = Array.prototype.slice.call( slider.querySelectorAll( '.heros-slide' ) );
52        var dots = Array.prototype.slice.call( slider.querySelectorAll( '.heros-slider-dots button' ) );
53        var prev = slider.querySelector( '.heros-slider-prev' );
54        var next = slider.querySelector( '.heros-slider-next' );
55        var progress = slider.querySelector( '.heros-slider-progress span' );
56        var counter = slider.querySelector( '.heros-slider-counter' );
57        var index = 0;
58        var timer = null;
59        var duration = parseInt( slider.dataset.duration || '650', 10 );
60        var touchStartX = 0;
61        var touchStartY = 0;
62        var touchEndX = 0;
63
64        if ( slides.length <= 1 ) {
65            return;
66        }
67
68        function goTo( nextIndex ) {
69            var oldIndex = index;
70            index = ( nextIndex + slides.length ) % slides.length;
71            if ( oldIndex === index ) {
72                return;
73            }
74            slides.forEach( function ( slide, i ) {
75                slide.classList.remove( 'is-leaving' );
76                if ( i === oldIndex ) {
77                    slide.classList.add( 'is-leaving' );
78                    window.setTimeout( function () {
79                        slide.classList.remove( 'is-leaving' );
80                    }, duration );
81                }
82                slide.classList.toggle( 'is-active', i === index );
83            } );
84            dots.forEach( function ( dot, i ) {
85                dot.classList.toggle( 'is-active', i === index );
86            } );
87            updateCounter();
88            resetProgress();
89            if ( slider.dataset.autoplay === '1' ) {
90                slider.classList.add( 'is-playing' );
91            }
92        }
93
94        function restartAutoplay() {
95            if ( timer ) {
96                window.clearInterval( timer );
97            }
98            resetProgress();
99            if ( slider.dataset.autoplay !== '1' ) {
100                slider.classList.remove( 'is-playing' );
101                return;
102            }
103            slider.classList.add( 'is-playing' );
104            timer = window.setInterval( function () {
105                goTo( index + 1 );
106            }, parseInt( slider.dataset.delay || '5000', 10 ) );
107        }
108
109        function updateCounter() {
110            if ( ! counter ) {
111                return;
112            }
113            counter.textContent = ( index + 1 ) + ' / ' + slides.length;
114        }
115
116        function resetProgress() {
117            if ( ! progress ) {
118                return;
119            }
120            slider.classList.remove( 'is-playing' );
121            progress.style.animation = 'none';
122            progress.offsetHeight;
123            progress.style.animation = '';
124        }
125
126        if ( prev ) {
127            prev.addEventListener( 'click', function () {
128                goTo( index - 1 );
129                restartAutoplay();
130            } );
131        }
132
133        if ( next ) {
134            next.addEventListener( 'click', function () {
135                goTo( index + 1 );
136                restartAutoplay();
137            } );
138        }
139
140        dots.forEach( function ( dot ) {
141            dot.addEventListener( 'click', function () {
142                goTo( parseInt( dot.dataset.slide || '0', 10 ) );
143                restartAutoplay();
144            } );
145        } );
146
147        if ( slider.dataset.swipe === '1' ) {
148            slider.addEventListener( 'touchstart', function ( e ) {
149                if ( ! e.touches || ! e.touches[0] ) {
150                    return;
151                }
152                touchStartX = e.touches[0].clientX;
153                touchStartY = e.touches[0].clientY;
154                touchEndX = touchStartX;
155            }, { passive: true } );
156
157            slider.addEventListener( 'touchmove', function ( e ) {
158                if ( ! e.touches || ! e.touches[0] ) {
159                    return;
160                }
161                touchEndX = e.touches[0].clientX;
162            }, { passive: true } );
163
164            slider.addEventListener( 'touchend', function ( e ) {
165                var deltaX = touchEndX - touchStartX;
166                var changedTouch = e.changedTouches && e.changedTouches[0] ? e.changedTouches[0] : null;
167                var deltaY = changedTouch ? changedTouch.clientY - touchStartY : 0;
168
169                if ( Math.abs( deltaX ) < 44 || Math.abs( deltaX ) < Math.abs( deltaY ) ) {
170                    return;
171                }
172
173                if ( deltaX < 0 ) {
174                    goTo( index + 1 );
175                } else {
176                    goTo( index - 1 );
177                }
178                restartAutoplay();
179            }, { passive: true } );
180        }
181
182        if ( slider.dataset.pauseOnHover === '1' ) {
183            slider.addEventListener( 'mouseenter', function () {
184                if ( timer ) {
185                    window.clearInterval( timer );
186                }
187                slider.classList.remove( 'is-playing' );
188            } );
189            slider.addEventListener( 'mouseleave', restartAutoplay );
190        }
191
192        updateCounter();
193        restartAutoplay();
194    }
195} )();

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.