Commit 8412d646 authored by Mario Botsch's avatar Mario Botsch
Browse files

polish/fix continue feature

parent 040674bc
......@@ -30,7 +30,7 @@ function deckerStart() {
setupVerticalSlides();
}
if (!printMode) {
setTimeout(continueWhereYouLeftOff, 1000);
setTimeout(continueWhereYouLeftOff, 500);
}
}
......@@ -272,20 +272,24 @@ function createElement({ type, id, classes, css, text, parent, onclick=null }) {
}
function continueWhereYouLeftOff() {
// if *-deck.html was opened *without* any hash, i.e., on the title slide,
// if *-deck.html was opened on the title slide,
// and if user has visited this slide decks before,
// then ask user whether to jump to slide where he/she left off
if (localStorage) {
// if user opens HTML with hash...
if (deckHash == "")
{
const slideIndex = JSON.parse(localStorage.getItem(deckPathname));
// ...and previous slide index is stored
// if (slideIndex && slideIndex.h != 0)
// if we are on the first slide
const slideIndex = Reveal.getIndices();
if (slideIndex && slideIndex.h==0 && slideIndex.v==0) {
// ...and previous slide index is stored (and not title slide)
const storedIndex = JSON.parse(localStorage.getItem(deckPathname));
if (storedIndex && storedIndex.h!=0)
{
// ...ask to jump to that slide
const slideNumber = storedIndex.h+1;
// German or non-German?
const lang = document.documentElement.lang;
const german = (lang == "de");
......@@ -296,11 +300,11 @@ function continueWhereYouLeftOff() {
let dialog = createElement({
type: "div",
id: "continue-dialog",
css: "display:flex; justify-content:space-evenly; align-items:center; gap:1em; position:fixed; left:50%; bottom:1em; transform:translate(-50%,0px); padding:1em; border:2px solid #2a9ddf; border-radius: 0.5em; font-size: 1rem;",
css: "display:flex; justify-content:space-evenly; align-items:center; gap:1em; position:fixed; left:50%; bottom:1em; transform:translate(-50%,0px); padding:1em; border:2px solid #2a9ddf; border-radius: 0.5em; font-size: 1rem; z-index:50;",
parent: reveal,
text: german
? "Bei Folie " + slideIndex.h + " weitermachen?"
: "Continue on slide " + slideIndex.h + "?"
? "Bei Folie " + slideNumber + " weitermachen?"
: "Continue on slide " + slideNumber + "?"
});
let hideDialog = () => {
......@@ -313,7 +317,7 @@ function continueWhereYouLeftOff() {
parent: dialog,
css: "font:inherit;",
text: german ? "Ja" : "Yes",
onclick: () => { Reveal.slide(slideIndex.h, slideIndex.v); hideDialog(); }
onclick: () => { Reveal.slide(storedIndex.h, storedIndex.v); hideDialog(); }
});
let no = createElement({
......@@ -325,7 +329,8 @@ function continueWhereYouLeftOff() {
onclick: hideDialog
});
// setTimeout(hideDialog, 5000);
// hide dialog after 5sec or on slide change
setTimeout(hideDialog, 5000);
Reveal.addEventListener("slidechanged", hideDialog);
}
}
......@@ -333,7 +338,7 @@ function continueWhereYouLeftOff() {
// add hook to store current slide's index
window.addEventListener("beforeunload", () => {
const slideIndex = Reveal.getIndices();
if (slideIndex) {
if (slideIndex && slideIndex.h != 0) {
localStorage.setItem(deckPathname, JSON.stringify(slideIndex));
}
});
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment