Riorganizzato slide e ottimizzato il loro caricamento

This commit is contained in:
s03529 2025-04-03 14:23:52 +02:00
parent 908c02775a
commit 78bbc1db41
8 changed files with 30 additions and 13 deletions

View File

@ -1,20 +1,38 @@
var counter = 0; var counter = -1;
var slides = [];
async function reloadSlide() { async function loadSlides() {
const req = await fetch(`./slide/${counter}.html`) var slidei = 1;
if(req.status != 200) return false; var sectioni = 1;
container.innerHTML = await req.text();
return true; sectionloop: while(true) {
slidei = 1;
slideloop: while(true) {
const req = await fetch(`./slide/${sectioni}/${slidei}.html`);
if(req.status != 200) {
if(slidei == 1) break sectionloop;
break slideloop;
}
slides.push(await req.text());
slidei++;
}
sectioni++;
}
nextSlide();
} }
async function nextSlide() { loadSlides();
counter++;
if(!await reloadSlide()) counter--; function nextSlide() {
if(counter >= slides.length - 1) return;
container.innerHTML = slides[++counter];
} }
async function previousSlide() { function previousSlide() {
counter--; if(counter <= 0) return;
if(!await reloadSlide()) counter++;
container.innerHTML = slides[--counter];
} }
document.body.addEventListener('click', nextSlide); document.body.addEventListener('click', nextSlide);
@ -34,4 +52,3 @@ document.addEventListener(
false, false,
); );
nextSlide();