@@ -62,10 +62,19 @@ const carouselId = `carousel-${Math.random().toString(36).substr(2, 9)}`;
6262
6363<script >
6464 class ImageCarousel {
65- constructor(element) {
65+ element: HTMLElement;
66+ currentIndex: number;
67+ interval: number;
68+ autoplay: boolean;
69+ isPlaying: boolean;
70+ timer: NodeJS.Timeout | null;
71+ slides: NodeListOf<Element>;
72+ dots: NodeListOf<Element>;
73+
74+ constructor(element: HTMLElement) {
6675 this.element = element;
6776 this.currentIndex = 0;
68- this.interval = parseInt(element.dataset.interval) * 1000 || 2000;
77+ this.interval = parseInt(element.dataset.interval || '2' ) * 1000 || 2000;
6978 this.autoplay = element.dataset.autoplay !== 'false'; // Default to true unless explicitly false
7079 this.isPlaying = false;
7180 this.timer = null;
@@ -84,7 +93,7 @@ const carouselId = `carousel-${Math.random().toString(36).substr(2, 9)}`;
8493
8594 init() {
8695 // Add event listeners for dots
87- this.dots.forEach((dot, index) => {
96+ this.dots.forEach((dot: Element , index: number ) => {
8897 dot.addEventListener('click', () => this.goToSlide(index));
8998 });
9099
@@ -101,7 +110,7 @@ const carouselId = `carousel-${Math.random().toString(36).substr(2, 9)}`;
101110 }
102111 }
103112
104- goToSlide(index) {
113+ goToSlide(index: number ) {
105114 // Remove active class from current slide and dot
106115 this.slides[this.currentIndex]?.classList.remove('active');
107116 this.dots[this.currentIndex]?.classList.remove('active');
@@ -158,9 +167,9 @@ const carouselId = `carousel-${Math.random().toString(36).substr(2, 9)}`;
158167 const carousels = document.querySelectorAll('.image-carousel:not(.single-image):not([data-initialized])');
159168 console.log('Found carousels to initialize:', carousels.length);
160169
161- carousels.forEach(carousel => {
170+ carousels.forEach(( carousel: Element) => {
162171 carousel.setAttribute('data-initialized', 'true');
163- new ImageCarousel(carousel);
172+ new ImageCarousel(carousel as HTMLElement );
164173 });
165174 }
166175
0 commit comments