MediaWiki:SlideShowPools.js
From Illustrations in German Translations of Mark Twain's Works
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
const slideshows = {
A: { images: [], index: 0 },
B: { images: [], index: 0 }
};
const pools = {
1: ['test1.png', 'test2.png'],
2: ['test3.png', 'test4.png'],
3: ['test5.png', 'test6.png'],
4: ['test7.png'],
5: ['test8.png', 'test9.png', 'test10.png'],
6: ['test11.png'],
7: ['test12.png', 'test13.png']
};
function selectPool(target, poolNumber) {
if (!pools[poolNumber]) {
slideshows[target].images = [];
slideshows[target].index = 0;
updateSlide(target);
return;
}
slideshows[target].images = pools[poolNumber];
slideshows[target].index = 0;
updateSlide(target);
}
function updateSlide(target) {
const img = document.getElementById('slide' + target);
const slideshow = slideshows[target];
const url = slideshow.images[slideshow.index];
if (url) {
img.src = url;
img.title = url;
} else {
img.src = '';
img.title = '';
}
}
function nextSlide(target) {
const slideshow = slideshows[target];
if (slideshow.images.length === 0) return;
slideshow.index = (slideshow.index + 1) % slideshow.images.length;
updateSlide(target);
}
function prevSlide(target) {
const slideshow = slideshows[target];
if (slideshow.images.length === 0) return;
slideshow.index = (slideshow.index - 1 + slideshow.images.length) % slideshow.images.length;
updateSlide(target);
}