If you run this in a browser with JavaScript enabled you should be able to turn the page into kind of a slideshow thing by running this code:
You can edit the code and change the "24px" and "40rem" to adjust font-size and width of page/slides.
Some new buttons should show up. You can enter slideshow mode and hop between slides with those, or with the q, w and e keys. (Also show/hide the bit that shows the current time with t.)
If you don’t run the JavaScript, you can still read through the page. There will be some repeated headings that would otherwise be on different slides.
Not that much about the slides, but: When I give a talk I want to not use more time than I’m supposed to. I think it’s hard to keep track of time. If I put the time on top of the slides it’s a little easier for me.
How much time is left?
We’ll make an element that stays in a fixed position:
How much time is left?
And we’ll make it show the correct time:
How much time is left?
Since what time it is changes every now and then, we’ll refreshTime frequently. We’re only showing hours and minutes, so refreshing a couple of times each second should be more than enough:
Slides then
Idea is:
Run through the contents of the page and make a list of slides from it.
Make stuff for showing a slide, next/previous stuff, entering and leaving slideshow.
Add slideshow controls to page.
Stuff.
A list of slides and the currently selected slide.
current is the index of the slide we’re showing, or null if we’re showing the full page.
A slide is a list of elements
We’ll just run through the page and add stuff to the current slide. We’ll add a new current slide whenever we run into a heading. (At least H1-H3. I never bother with the other ones.)
This makes it so the first slide is just the bit with date and index-link, before the first heading. Not the best slide I’ve seen, but I’m okay with it.
Showing a slide
We show a slide by replacing everything in the <body> with the elements from the slide-list:
Next and previous slide
slide is also a verb. Like you slide in this or that direction.
Entering
If we’re viewing the full page and want to enter slideshow mode, we can find the first slide that is currently within view:
Leaving
We go back to the full page by putting the content of all the slides in the <body>. And we scroll the previously shown slide into view so that we end up in kind of the right part of the page.
Keyboard shortcuts
q/e for previous/next slide.
w toggles between full page and slideshow.
t turns the element with the time on/off.
Keyboard shortcuts
Buttons
We’ll add some clickable buttons to the start of each slide:
Buttons
Resizing stuff
Slideshows often have larger letters and stuff.
Resizing stuff
Resizing a textarea so the content kind of fits is kind of hacky.
Init
init does the things. Arguments are passed along to sizeElement.
That’s it
That more or less it I guess.
Variations, considerations
I’ve previously done like a <div class="slide"> for each slide. Makes it more straightforward to grab the list of slides with code. But a bit more nested stuff when writing the slides. I think I like this way better, but I dunno.
Variations, considerations
Also I’ve previously used some “container” element instead putting stuff directly into <body>. Makes it so I can put the time-element outside of the container instead of making sure I add it whenever I replace the contents of <body>.
On a similar note: The buttons could be moved to outside of the actual slides. I kind of like having them all over the place so that you have like a button for entering this slide and a button for entering that slide and so on, but...
Variations, considerations
It’s easy to change which elements should start new slides. It’s also possible to have separator-elements between slides instead/as well, like if I want slides with no headings. E.g. I could make it so that <hr> starts a new slide but is not added to the slide content. (Might wanna change the slide data structure to something that can hold on to the separator in addition to the content of the slide, if I want to restore the separators when I’m doing fullPage.)
Variations, considerations
I’m only dealing with elements when I put stuff into slides. If I also had text nodes directly under <body> I’d maybe have to do more stuff.