vanillajs-deck/js/slideLoader.js

36 lines
873 B
JavaScript
Raw Permalink Normal View History

2019-11-24 00:02:31 +00:00
//@ts-check
2019-11-22 19:28:19 +00:00
import { Slide } from "./slide.js"
2019-11-24 00:02:31 +00:00
/**
* Load a single slide
* @param {string} slideName The name of the slide
* @returns {Promise<Slide>} The slide
*/
2019-11-22 19:28:19 +00:00
async function loadSlide(slideName) {
const response = await fetch(`./slides/${slideName}.html`);
const slide = await response.text();
return new Slide(slide);
}
2019-11-24 00:02:31 +00:00
/**
*
* @param {string} start The name of the slide to begin with
* @returns {Promise<Slide[]>} The array of loaded slides
*/
2019-11-22 19:28:19 +00:00
export async function loadSlides(start) {
var next = start;
const slides = [];
const cycle = {};
while (next) {
2019-11-23 00:37:45 +00:00
if (!cycle[next]) {
cycle[next] = true;
const nextSlide = await loadSlide(next);
2019-11-22 19:28:19 +00:00
slides.push(nextSlide);
next = nextSlide.nextSlide;
}
else {
break;
}
2019-11-24 00:02:31 +00:00
}
2019-11-22 19:28:19 +00:00
return slides;
}