Spaces:
Running
Running
Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let data; // Placeholder for slide configuration
|
| 2 |
+
let currentIndex = 0;
|
| 3 |
+
|
| 4 |
+
const slideTitle = document.getElementById("slide-title");
|
| 5 |
+
const slideImage = document.getElementById("slide-image");
|
| 6 |
+
const contentArea = document.getElementById("content-area");
|
| 7 |
+
|
| 8 |
+
const textIcon = document.getElementById("text-icon");
|
| 9 |
+
const imageIcon = document.getElementById("image-icon");
|
| 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 configuration from the JSON file
|
| 16 |
+
async function loadConfig() {
|
| 17 |
+
const response = await fetch('slide_config.json');
|
| 18 |
+
data = await response.json();
|
| 19 |
+
loadSlide(currentIndex);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
function loadSlide(index) {
|
| 23 |
+
const slide = data.slides[index];
|
| 24 |
+
slideTitle.textContent = slide.id.replace("_", " ");
|
| 25 |
+
slideImage.src = slide.image;
|
| 26 |
+
|
| 27 |
+
const existingText = document.getElementById("slide-text");
|
| 28 |
+
if (existingText) existingText.remove();
|
| 29 |
+
|
| 30 |
+
const existingVideo = document.getElementById("slide-video");
|
| 31 |
+
if (existingVideo) existingVideo.remove();
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
textIcon.addEventListener("click", () => {
|
| 35 |
+
const slide = data.slides[currentIndex];
|
| 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("click", () => {
|
| 62 |
+
currentIndex = (currentIndex + 1) % data.slides.length;
|
| 63 |
+
loadSlide(currentIndex);
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
// Load configuration and initialize the app
|
| 67 |
+
loadConfig();
|