|
66 | 66 | } |
67 | 67 |
|
68 | 68 | // setup indexes for shuffling |
69 | | -let indexes = new Array(); |
| 69 | +const indexes = new Array(); // numbers indexing the list of images, used for shuffling |
| 70 | +let index = 0; //current position in "indexes" array |
70 | 71 | for(let i = 0; i < images.length; i++) { |
71 | 72 | images[i] = "images/" + images[i]; |
72 | 73 | indexes.push(i); |
|
78 | 79 | let imageContainer = document.getElementById("imageContainer"); |
79 | 80 | imageContainer.appendChild(botImage); |
80 | 81 | imageContainer.appendChild(topImage); |
| 82 | +topImage.id = "topImage"; |
| 83 | +botImage.id = "botImage"; |
| 84 | + |
| 85 | +// setup captions |
| 86 | +const captionDelimiter = "--"; |
| 87 | +const captions = new Array(); |
| 88 | +let caption; |
81 | 89 | if(captionEnabled) { |
82 | | - const caption = document.createElement("div"); |
| 90 | + caption = document.createElement("div"); |
83 | 91 | caption.id = "caption"; |
84 | 92 | imageContainer.appendChild(caption); |
85 | 93 | } |
86 | | -topImage.id = "topImage"; |
87 | | -botImage.id = "botImage"; |
88 | 94 |
|
89 | 95 | let fadeDuration = slideDuration * 0.25; |
90 | 96 | let slideshowFunc; |
91 | | -let index = 0; |
92 | 97 | let fadeInTop = true; // bool for deciding if top image fades in or out |
93 | 98 | let isSlideshowPaused = false; |
94 | 99 | let isSlideshowVisible = true; |
|
116 | 121 | getNextSlide(); |
117 | 122 | } |
118 | 123 |
|
| 124 | +function generateCaptions() { |
| 125 | + captions.length = 0; |
| 126 | + images.forEach((fileName) => { |
| 127 | + let text = fileName.replace(/^.*[\\/]/, ''); |
| 128 | + text = text.substr(0, text.lastIndexOf('.')) || text; |
| 129 | + text = text.substr(0, text.lastIndexOf(captionDelimiter)) || text; |
| 130 | + captions.push(text); |
| 131 | + }); |
| 132 | +} |
| 133 | + |
| 134 | +function setCaption(text) { |
| 135 | + caption.innerText = text; |
| 136 | +} |
| 137 | + |
119 | 138 | function getNextSlide() { |
120 | 139 | index = index === images.length - 1 ? 0 : index + 1; |
121 | 140 | if (index === 0 && mode === 0) { |
|
157 | 176 | } |
158 | 177 | ); |
159 | 178 | if(captionEnabled) { |
160 | | - setImageCaption(imageSrc); |
| 179 | + setCaption(captions[indexes[index]]); |
161 | 180 | } |
162 | 181 |
|
163 | 182 | fadeInTop = !fadeInTop; |
|
183 | 202 | start(); |
184 | 203 | } |
185 | 204 |
|
186 | | -function setImageCaption(imageSrc) { |
187 | | - let filename = imageSrc.replace(/^.*[\\/]/, ''); |
188 | | - filename = filename.substr(0, filename.lastIndexOf('.')) || filename; |
189 | | - caption.innerText = filename; |
190 | | -} |
191 | | - |
192 | 205 | // called once when the browser source loads or is restarted via hotkey |
193 | 206 | function start() { |
194 | 207 | topImage.style.opacity = "0.0"; |
|
204 | 217 |
|
205 | 218 | botImage.src = images[indexes[index]]; |
206 | 219 | if(captionEnabled) { |
207 | | - setImageCaption(images[indexes[index]]); |
| 220 | + generateCaptions(); |
| 221 | + setCaption(captions[indexes[index]]); |
208 | 222 | } |
209 | 223 | $("#botImage").animate( |
210 | 224 | { opacity: 1.0 }, |
|
0 commit comments