Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Makes presenter mode more robust.
Browse files Browse the repository at this point in the history
On long presentations the state gets lost.
At least when interactively changing presentation, which causes a reload.
  • Loading branch information
schnatterer committed Nov 29, 2019
1 parent c02fb95 commit 43c8de6
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,14 @@
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
let presenterMode = false;
Reveal.initialize({
history: true,
// Use the default (h.v), because the printed version will always have this anyway
slideNumber: 'true',
// Support for presenters - press comma to toggle presenterMode mode, i.e. ⬅/➡️ keys map to
// prev/next slide, instead of left/right
keyboard: {
188: function() {
if (!presenterMode) {
Reveal.addKeyBinding( { keyCode: 39 }, 'next');
Reveal.addKeyBinding( { keyCode: 37 }, 'prev');
} else {
Reveal.removeKeyBinding( 37 );
Reveal.removeKeyBinding( 39 );
}
presenterMode=!presenterMode;
console.log(`Switched to presenter mode: ${presenterMode}`);
}
188: () => setPresenterMode(true)
},
dependencies: [
{ src: 'plugin/markdown/marked.js' },
Expand All @@ -67,6 +56,25 @@
{ src: 'plugin/highlight/highlight.js', async: true }
]
});

setPresenterMode(false);

function setPresenterMode(toggle) {
const storage = localStorage;
const storageKey = 'presenterMode';
if (toggle) {
storage.setItem(storageKey, JSON.stringify(!JSON.parse(storage.getItem(storageKey))));
}
const presenterMode = JSON.parse(storage.getItem(storageKey));
if (presenterMode) {
Reveal.addKeyBinding({keyCode: 39}, 'next');
Reveal.addKeyBinding({keyCode: 37}, 'prev');
} else {
Reveal.removeKeyBinding(37);
Reveal.removeKeyBinding(39);
}
console.log(`Set presenter mode: ${storage.getItem(storageKey)}`);
}
</script>
</body>
</html>

0 comments on commit 43c8de6

Please sign in to comment.