Skip to content

Commit

Permalink
Change way to extract current slide number, fix page numbers in Revea…
Browse files Browse the repository at this point in the history
…l's PDF export
  • Loading branch information
iamgio committed Sep 5, 2024
1 parent ccd2f8e commit f42de8b
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions core/src/main/resources/render/script/slides.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,11 @@ document.addEventListener('DOMContentLoaded', function () {
slideBackgrounds.forEach(slideBackground => {
slideBackground.appendChild(pageMargin.cloneNode(true));
});
});

updateTotalSlideNumberElements()
updateCurrentSlideNumberElements(event.indexh);
updateSlideNumberElements();
});
});

Reveal.addEventListener('slidechanged', event => updateCurrentSlideNumberElements(event.indexh));

// Used to check if a property was injected (see below).
const undef = 'undefined';

Expand All @@ -116,18 +113,23 @@ document.addEventListener('DOMContentLoaded', function () {
});
});

function updateTotalSlideNumberElements() {
// Sets the current and total slide number to the elements with the classes .current-page-number and .total-page-number
function updateSlideNumberElements() {
const slides = document.querySelectorAll('.reveal .slides > :is(section, div)');

// Inject the total amount of slides into .total-page-number elements.
const amount = document.querySelectorAll('.reveal .slides > section').length;
document.querySelectorAll('.total-page-number').forEach(total => {
total.innerText = amount;
total.innerText = slides.length;
});
}

function updateCurrentSlideNumberElements(index) {
// Inject the current slide number into .current-page-number elements every time.
// Inject the current slide number into .current-page-number elements.
// This approach allows for a static evaluation of the number, without relying on Reveal's dynamic events.
document.querySelectorAll('.current-page-number').forEach(current => {
current.innerText = index + 1;
// The page counter can be either in a slide or a background.
const container = current.closest('.reveal > :is(.slides, .backgrounds)');
const ownSlide = current.closest('.reveal > :is(.slides, .backgrounds) > :is(section, div)');

current.innerText = Array.from(container.children).indexOf(ownSlide) + 1;
});
}

Expand Down

0 comments on commit f42de8b

Please sign in to comment.