diff --git a/src/serena/resources/dashboard/dashboard.js b/src/serena/resources/dashboard/dashboard.js index 1df0edff..261d4f58 100644 --- a/src/serena/resources/dashboard/dashboard.js +++ b/src/serena/resources/dashboard/dashboard.js @@ -40,6 +40,86 @@ class LogMessage { }; } +class SponsorRotation { + constructor() { + this.platinumIndex = 0; + this.goldIndex = 0; + this.platinumTimer = null; + this.goldTimer = null; + this.platinumInterval = 5000; + this.goldInterval = 5000; + + this.init(); + } + + init() { + this.startPlatinumRotation(); + this.startGoldRotation(); + } + + startPlatinumRotation() { + const self = this; + this.platinumTimer = setInterval(() => { + self.rotatePlatinum('next'); + }, this.platinumInterval); + } + + startGoldRotation() { + const self = this; + this.goldTimer = setInterval(() => { + self.rotateGold('next'); + }, this.goldInterval); + } + + rotatePlatinum(direction) { + const $slides = $('.platinum-sponsor-slide'); + const total = $slides.length; + + if (total === 0) return; + + // Remove active class from current slide + $slides.eq(this.platinumIndex).removeClass('active'); + + // Calculate next index + if (direction === 'next') { + this.platinumIndex = (this.platinumIndex + 1) % total; + } else { + this.platinumIndex = (this.platinumIndex - 1 + total) % total; + } + + // Add active class to new slide + $slides.eq(this.platinumIndex).addClass('active'); + + // Reset timer + clearInterval(this.platinumTimer); + this.startPlatinumRotation(); + } + + rotateGold(direction) { + const $groups = $('.gold-sponsor-slide'); + const total = $groups.length; + + if (total === 0) return; + + // Remove active class from current group + $groups.eq(this.goldIndex).removeClass('active'); + + // Calculate next index + if (direction === 'next') { + this.goldIndex = (this.goldIndex + 1) % total; + } else { + this.goldIndex = (this.goldIndex - 1 + total) % total; + } + + // Add active class to new group + $groups.eq(this.goldIndex).addClass('active'); + + // Reset timer + clearInterval(this.goldTimer); + this.startGoldRotation(); + } +} + class Dashboard { constructor() { let self = this; @@ -244,7 +324,7 @@ class Dashboard { this.initializeTheme(); // Initialize sponsor rotation - this.initializeSponsorRotation(); + this.sponsorRotation = new SponsorRotation(); // Add ESC key handler for closing modals $(document).keydown(function (e) { @@ -1834,114 +1914,4 @@ class Dashboard { // Close menu self.$menuDropdown.hide(); } - - // ===== Sponsor Rotation Methods ===== - - initializeSponsorRotation() { - const self = this; - - // Platinum sponsor rotation - this.platinumCurrentIndex = 0; - this.platinumInterval = null; - - $('#platinum-prev').click(function() { - self.rotatePlatinumSponsor('prev'); - }); - - $('#platinum-next').click(function() { - self.rotatePlatinumSponsor('next'); - }); - - // Start automatic platinum rotation - this.startPlatinumRotation(); - - // Gold sponsor rotation - this.goldCurrentIndex = 0; - this.goldInterval = null; - - $('#gold-prev').click(function() { - self.rotateGoldSponsor('prev'); - }); - - $('#gold-next').click(function() { - self.rotateGoldSponsor('next'); - }); - - // Start automatic gold rotation - this.startGoldRotation(); - } - - rotatePlatinumSponsor(direction) { - const $slides = $('.platinum-sponsor-slide'); - const totalSlides = $slides.length; - - if (totalSlides === 0) return; - - // Remove active class from current slide - $slides.eq(this.platinumCurrentIndex).removeClass('active'); - - // Calculate new index - if (direction === 'next') { - this.platinumCurrentIndex = (this.platinumCurrentIndex + 1) % totalSlides; - } else { - this.platinumCurrentIndex = (this.platinumCurrentIndex - 1 + totalSlides) % totalSlides; - } - - // Add active class to new slide - $slides.eq(this.platinumCurrentIndex).addClass('active'); - - // Reset auto-rotation timer - this.startPlatinumRotation(); - } - - startPlatinumRotation() { - const self = this; - - // Clear existing interval - if (this.platinumInterval) { - clearInterval(this.platinumInterval); - } - - // Start new interval (30 seconds) - this.platinumInterval = setInterval(function() { - self.rotatePlatinumSponsor('next'); - }, 5000); - } - - rotateGoldSponsor(direction) { - const $slides = $('.gold-sponsor-slide'); - const totalSlides = $slides.length; - - if (totalSlides === 0) return; - - // Remove active class from current slide - $slides.eq(this.goldCurrentIndex).removeClass('active'); - - // Calculate new index - if (direction === 'next') { - this.goldCurrentIndex = (this.goldCurrentIndex + 1) % totalSlides; - } else { - this.goldCurrentIndex = (this.goldCurrentIndex - 1 + totalSlides) % totalSlides; - } - - // Add active class to new slide - $slides.eq(this.goldCurrentIndex).addClass('active'); - - // Reset auto-rotation timer - this.startGoldRotation(); - } - - startGoldRotation() { - const self = this; - - // Clear existing interval - if (this.goldInterval) { - clearInterval(this.goldInterval); - } - - // Start new interval (30 seconds) - this.goldInterval = setInterval(function() { - self.rotateGoldSponsor('next'); - }, 5000); - } } diff --git a/src/serena/resources/dashboard/index.html b/src/serena/resources/dashboard/index.html index a8372bff..c1752bd7 100644 --- a/src/serena/resources/dashboard/index.html +++ b/src/serena/resources/dashboard/index.html @@ -345,93 +345,8 @@