Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -1,67 +1,40 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
const
|
| 5 |
-
const slideImage = document.getElementById("slide-image");
|
| 6 |
-
const contentArea = document.getElementById("content-area");
|
| 7 |
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
const videoIcon = document.getElementById("video-icon");
|
| 11 |
-
|
| 12 |
-
const prevBtn = document.getElementById("prev-btn");
|
| 13 |
-
const nextBtn = document.getElementById("next-btn");
|
| 14 |
|
| 15 |
-
// Fetch
|
| 16 |
-
async function
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
}
|
| 21 |
|
| 22 |
function loadSlide(index) {
|
| 23 |
-
|
| 24 |
-
slideTitle.textContent = slide.id.replace("_", " ");
|
| 25 |
-
slideImage.src = slide.image;
|
| 26 |
|
| 27 |
-
const
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
const existingVideo = document.getElementById("slide-video");
|
| 31 |
-
if (existingVideo) existingVideo.remove();
|
| 32 |
}
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
const textOverlay = document.createElement("div");
|
| 37 |
-
textOverlay.id = "slide-text";
|
| 38 |
-
textOverlay.textContent = slide.text;
|
| 39 |
-
contentArea.appendChild(textOverlay);
|
| 40 |
-
});
|
| 41 |
-
|
| 42 |
-
imageIcon.addEventListener("click", () => {
|
| 43 |
-
loadSlide(currentIndex);
|
| 44 |
-
});
|
| 45 |
-
|
| 46 |
-
videoIcon.addEventListener("click", () => {
|
| 47 |
-
const slide = data.slides[currentIndex];
|
| 48 |
-
const videoEmbed = document.createElement("iframe");
|
| 49 |
-
videoEmbed.id = "slide-video";
|
| 50 |
-
videoEmbed.src = slide.video;
|
| 51 |
-
videoEmbed.frameBorder = "0";
|
| 52 |
-
videoEmbed.allow = "autoplay; encrypted-media";
|
| 53 |
-
contentArea.appendChild(videoEmbed);
|
| 54 |
-
});
|
| 55 |
-
|
| 56 |
-
prevBtn.addEventListener("click", () => {
|
| 57 |
-
currentIndex = (currentIndex - 1 + data.slides.length) % data.slides.length;
|
| 58 |
loadSlide(currentIndex);
|
| 59 |
});
|
| 60 |
|
| 61 |
-
nextBtn.addEventListener(
|
| 62 |
-
currentIndex = (currentIndex + 1) % data.
|
| 63 |
loadSlide(currentIndex);
|
| 64 |
});
|
| 65 |
|
| 66 |
-
//
|
| 67 |
-
|
|
|
|
| 1 |
+
const slideTitle = document.getElementById('slide-title');
|
| 2 |
+
const slideImage = document.getElementById('slide-image');
|
| 3 |
+
const prevBtn = document.getElementById('prev-btn');
|
| 4 |
+
const nextBtn = document.getElementById('next-btn');
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
let data = [];
|
| 7 |
+
let currentIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
// Fetch slide configuration
|
| 10 |
+
async function fetchSlideConfig() {
|
| 11 |
+
try {
|
| 12 |
+
const response = await fetch('slide_config.json');
|
| 13 |
+
const jsonData = await response.json();
|
| 14 |
+
data = jsonData.slides;
|
| 15 |
+
loadSlide(currentIndex);
|
| 16 |
+
} catch (error) {
|
| 17 |
+
console.error('Error loading slide configuration:', error);
|
| 18 |
+
}
|
| 19 |
}
|
| 20 |
|
| 21 |
function loadSlide(index) {
|
| 22 |
+
if (data.length === 0) return;
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
const slide = data[index];
|
| 25 |
+
slideTitle.textContent = slide.id.replace('_', ' ');
|
| 26 |
+
slideImage.src = slide.image;
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
| 29 |
+
prevBtn.addEventListener('click', () => {
|
| 30 |
+
currentIndex = (currentIndex - 1 + data.length) % data.length;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
loadSlide(currentIndex);
|
| 32 |
});
|
| 33 |
|
| 34 |
+
nextBtn.addEventListener('click', () => {
|
| 35 |
+
currentIndex = (currentIndex + 1) % data.length;
|
| 36 |
loadSlide(currentIndex);
|
| 37 |
});
|
| 38 |
|
| 39 |
+
// Initialize
|
| 40 |
+
fetchSlideConfig();
|