MediaWiki

SlideShowPools.js: Difference between revisions

From Illustrations in German Translations of Mark Twain's Works

No edit summary
No edit summary
 
Line 5: Line 5:


const pools = {
const pools = {
   1: ['Hf_1885_kmb_ch002_ill1.jpg', 'Hf_1885_kmb_ch002_ill1_cropped.jpg'], // TOM Kemble
   1: ['https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png', 'https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png'], // TOM Kemble
   2: ['test3.png', 'test4.png'],
   2: ['test3.png', 'test4.png'],
   3: ['test5.png', 'test6.png'],
   3: ['test5.png', 'test6.png'],

Latest revision as of 21:23, 22 July 2025

const slideshows = {
  A: { images: [], index: 0 },
  B: { images: [], index: 0 }
};

const pools = {
  1: ['https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png', 'https://illus.twainframe.org/images/d/d2/GalleryPlaceholder.png'], // TOM Kemble
  2: ['test3.png', 'test4.png'],
  3: ['test5.png', 'test6.png'],
  4: ['test7.png'],
  5: ['test8.png', 'test9.png', 'test10.png'],
  6: ['test11.png'],
  8: ['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);
}