-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
135 lines (110 loc) · 4.58 KB
/
Copy pathscript.js
File metadata and controls
135 lines (110 loc) · 4.58 KB
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
document.addEventListener('DOMContentLoaded', () => {
// Initialize Lucide Icons
lucide.createIcons();
const slides = document.querySelectorAll('.slide');
const totalSlides = slides.length;
let currentSlideIndex = 0;
const btnNext = document.getElementById('btn-next');
const btnPrev = document.getElementById('btn-prev');
const btnMosaic = document.getElementById('btn-mosaic');
const progressBar = document.getElementById('progress-bar');
const slideCounter = document.getElementById('slide-counter');
const mosaicOverlay = document.getElementById('mosaic-overlay');
const container = document.getElementById('presentation-container');
// Update Progress
function updateProgress() {
const progress = ((currentSlideIndex + 1) / totalSlides) * 100;
progressBar.style.width = `${progress}%`;
slideCounter.innerText = `${currentSlideIndex + 1} / ${totalSlides}`;
// Update Mosaic Tiles
document.querySelectorAll('.mosaic-tile').forEach((tile, idx) => {
if (idx === currentSlideIndex) tile.classList.add('active');
else tile.classList.remove('active');
});
}
// Go to slide
function goToSlide(index) {
if (index < 0 || index >= totalSlides) return;
// Remove active class from current
slides[currentSlideIndex].classList.remove('active');
// Add active class to new
currentSlideIndex = index;
slides[currentSlideIndex].classList.add('active');
// Add animation class
const content = slides[currentSlideIndex].querySelector('.slide-content, .content-grid');
if (content) {
content.classList.remove('animate-in');
void content.offsetWidth; // Trigger reflow
content.classList.add('animate-in');
}
updateProgress();
// Hide mosaic if open
mosaicOverlay.classList.remove('show');
}
// Initialize Mosaic Overlay
function initMosaic() {
mosaicOverlay.innerHTML = '';
slides.forEach((slide, index) => {
const title = slide.querySelector('h1').innerText;
const tag = slide.querySelector('.tag').innerText;
const tile = document.createElement('div');
tile.className = 'mosaic-tile';
if (index === currentSlideIndex) tile.classList.add('active');
tile.innerHTML = `
<div>
<div style="font-size: 0.6rem; opacity: 0.7; margin-bottom: 5px;">${tag}</div>
<div>${title}</div>
</div>
`;
tile.addEventListener('click', () => {
goToSlide(index);
});
mosaicOverlay.appendChild(tile);
});
}
initMosaic();
// Event Listeners
btnNext.addEventListener('click', () => {
if (currentSlideIndex < totalSlides - 1) goToSlide(currentSlideIndex + 1);
});
btnPrev.addEventListener('click', () => {
if (currentSlideIndex > 0) goToSlide(currentSlideIndex - 1);
});
btnMosaic.addEventListener('click', () => {
mosaicOverlay.classList.toggle('show');
});
// Keyboard controls
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight' || e.key === ' ') {
if (currentSlideIndex < totalSlides - 1) goToSlide(currentSlideIndex + 1);
} else if (e.key === 'ArrowLeft') {
if (currentSlideIndex > 0) goToSlide(currentSlideIndex - 1);
} else if (e.key === 'm' || e.key === 'M') {
mosaicOverlay.classList.toggle('show');
} else if (e.key === 'Escape') {
mosaicOverlay.classList.remove('show');
}
});
// Handle touch/swipe (basic)
let touchstartX = 0;
let touchendX = 0;
function handleGesture() {
if (touchendX < touchstartX - 50) {
if (currentSlideIndex < totalSlides - 1) goToSlide(currentSlideIndex + 1);
}
if (touchendX > touchstartX + 50) {
if (currentSlideIndex > 0) goToSlide(currentSlideIndex - 1);
}
}
container.addEventListener('touchstart', e => {
touchstartX = e.changedTouches[0].screenX;
});
container.addEventListener('touchend', e => {
touchendX = e.changedTouches[0].screenX;
handleGesture();
});
// Init first slide animation
updateProgress();
const firstContent = slides[0].querySelector('.content-grid');
if (firstContent) firstContent.classList.add('animate-in');
});