File size: 8,160 Bytes
b7d30d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
class PresentationController {
    constructor() {
        this.currentSlide = 1;
        this.totalSlides = 12;
        this.slides = document.querySelectorAll('.slide');
        this.prevBtn = document.getElementById('prevBtn');
        this.nextBtn = document.getElementById('nextBtn');
        this.currentSlideSpan = document.getElementById('currentSlide');
        this.totalSlidesSpan = document.getElementById('totalSlides');
        this.isTransitioning = false;
        
        this.init();
    }

    init() {
        // Set total slides
        this.totalSlidesSpan.textContent = this.totalSlides;
        
        // Add event listeners
        this.prevBtn.addEventListener('click', () => this.previousSlide());
        this.nextBtn.addEventListener('click', () => this.nextSlide());
        
        // Keyboard navigation
        document.addEventListener('keydown', (e) => this.handleKeyboard(e));
        
        // Initialize first slide
        this.showSlide(1);
        
        // Initialize progress bar
        this.initProgressBar();
        
        console.log('Presentation initialized with', this.totalSlides, 'slides');
    }

    initProgressBar() {
        // Create and add progress bar
        const progressBar = document.createElement('div');
        progressBar.className = 'progress-bar';
        progressBar.innerHTML = '<div class="progress-fill"></div>';
        document.body.insertBefore(progressBar, document.body.firstChild);
        
        this.progressBar = progressBar;
        this.updateProgress();
    }

    showSlide(slideNumber) {
        if (slideNumber < 1 || slideNumber > this.totalSlides || this.isTransitioning) {
            return;
        }

        this.isTransitioning = true;

        // Hide all slides
        this.slides.forEach(slide => {
            slide.classList.remove('active', 'exiting');
            slide.style.opacity = '0';
            slide.style.visibility = 'hidden';
            slide.style.transform = 'translateX(50px)';
        });

        // Update current slide
        this.currentSlide = slideNumber;

        // Show target slide with a small delay to ensure clean transition
        setTimeout(() => {
            const targetSlide = document.querySelector(`[data-slide="${slideNumber}"]`);
            if (targetSlide) {
                targetSlide.style.visibility = 'visible';
                targetSlide.classList.add('active');
                
                // Force a repaint
                targetSlide.offsetHeight;
                
                targetSlide.style.opacity = '1';
                targetSlide.style.transform = 'translateX(0)';
            }

            // Update UI elements
            this.updateButtonStates();
            this.updateSlideCounter();
            this.updateProgress();

            // Allow next transition after animation completes
            setTimeout(() => {
                this.isTransitioning = false;
            }, 450);
        }, 50);
    }

    nextSlide() {
        if (this.currentSlide < this.totalSlides && !this.isTransitioning) {
            this.showSlide(this.currentSlide + 1);
        }
    }

    previousSlide() {
        if (this.currentSlide > 1 && !this.isTransitioning) {
            this.showSlide(this.currentSlide - 1);
        }
    }

    updateButtonStates() {
        // Update previous button
        this.prevBtn.disabled = (this.currentSlide === 1);
        
        // Update next button
        this.nextBtn.disabled = (this.currentSlide === this.totalSlides);
    }

    updateSlideCounter() {
        this.currentSlideSpan.textContent = this.currentSlide;
    }

    updateProgress() {
        if (this.progressBar) {
            const progressFill = this.progressBar.querySelector('.progress-fill');
            const percentage = (this.currentSlide / this.totalSlides) * 100;
            progressFill.style.width = `${percentage}%`;
        }
    }

    handleKeyboard(e) {
        // Prevent default behavior for navigation keys
        if (['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(e.key)) {
            e.preventDefault();
        }

        switch(e.key) {
            case 'ArrowLeft':
                this.previousSlide();
                break;
            case 'ArrowRight':
                this.nextSlide();
                break;
            case 'Home':
                this.showSlide(1);
                break;
            case 'End':
                this.showSlide(this.totalSlides);
                break;
            case 'f':
            case 'F':
                this.toggleFullscreen();
                break;
            case 'Escape':
                this.exitFullscreen();
                break;
        }
    }

    toggleFullscreen() {
        if (!document.fullscreenElement) {
            document.documentElement.requestFullscreen().catch(err => {
                console.log(`Error attempting to enable fullscreen: ${err.message}`);
            });
        } else {
            document.exitFullscreen();
        }
    }

    exitFullscreen() {
        if (document.fullscreenElement) {
            document.exitFullscreen();
        }
    }
}

// Touch/swipe support for mobile
class TouchHandler {
    constructor(controller) {
        this.controller = controller;
        this.touchStartX = 0;
        this.touchEndX = 0;
        this.minSwipeDistance = 50;
        
        this.init();
    }

    init() {
        const slidesContainer = document.getElementById('slidesContainer');
        
        slidesContainer.addEventListener('touchstart', (e) => {
            this.touchStartX = e.changedTouches[0].screenX;
        }, { passive: true });
        
        slidesContainer.addEventListener('touchend', (e) => {
            this.touchEndX = e.changedTouches[0].screenX;
            this.handleSwipe();
        }, { passive: true });
    }

    handleSwipe() {
        const diffX = this.touchStartX - this.touchEndX;
        
        if (Math.abs(diffX) > this.minSwipeDistance) {
            if (diffX > 0) {
                // Swipe left - next slide
                this.controller.nextSlide();
            } else {
                // Swipe right - previous slide
                this.controller.previousSlide();
            }
        }
    }
}

// Simple hover effects without problematic animations
function addHoverEffects() {
    const style = document.createElement('style');
    style.textContent = `
        .tech-card:hover,
        .company-card:hover,
        .use-case-card:hover,
        .challenge-card:hover,
        .trend-item:hover,
        .takeaway-card:hover {
            background: rgba(255, 255, 255, 0.15) !important;
            cursor: pointer;
        }
    `;
    document.head.appendChild(style);
}

// Initialize presentation when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
    // Prevent scrolling and ensure proper viewport
    document.body.style.overflow = 'hidden';
    document.body.style.margin = '0';
    document.body.style.padding = '0';
    document.documentElement.style.overflow = 'hidden';
    
    // Initialize the presentation controller
    const presentation = new PresentationController();
    
    // Add touch support
    new TouchHandler(presentation);
    
    // Add simple hover effects
    addHoverEffects();
    
    // Prevent default scrolling behavior
    document.addEventListener('wheel', (e) => {
        e.preventDefault();
    }, { passive: false });
    
    // Prevent arrow key scrolling
    document.addEventListener('keydown', (e) => {
        if (['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Space'].includes(e.key)) {
            e.preventDefault();
        }
    });
    
    // Handle window resize
    window.addEventListener('resize', () => {
        // Force a repaint to handle responsive changes
        const activeSlide = document.querySelector('.slide.active');
        if (activeSlide) {
            activeSlide.style.height = '100%';
        }
    });
    
    console.log('Presentation ready');
});

// Export controller for debugging
window.PresentationController = PresentationController;