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