MediaWiki

SlideShowPools.js: Difference between revisions

From Illustrations in German Translations of Mark Twain's Works

Created page with "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; upda..."
 
No edit summary
Line 11: Line 11:
   5: ['test8.png', 'test9.png', 'test10.png'],
   5: ['test8.png', 'test9.png', 'test10.png'],
   6: ['test11.png'],
   6: ['test11.png'],
   7: ['test12.png', 'test13.png']
   8: ['test12.png', 'test13.png']
};
};



Revision as of 21:19, 22 July 2025

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'],
  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);
}