eaglelandsonce commited on
Commit
94a1dfa
1 Parent(s): 0bf7c14

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +26 -53
script.js CHANGED
@@ -1,67 +1,40 @@
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();
 
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();