Skip to content

Instantly share code, notes, and snippets.

@hakimel
Created June 9, 2022 07:17
Show Gist options
  • Save hakimel/c1612a58de3f2694e7b078eab825782e to your computer and use it in GitHub Desktop.
Save hakimel/c1612a58de3f2694e7b078eab825782e to your computer and use it in GitHub Desktop.
Retrieves the total number of fragments that have been stepped past in a reveal.js presentation.
function getUniqueFragments( fragmentElements ) {
return Array.from( fragmentElements )
.map( ( fragment, i ) => fragment.getAttribute( 'data-fragment-index' ) || i )
.filter( (value, index, array) => array.indexOf(value) === index ).length;
}
function getPastFragmentCount() {
const pastSlides = Array.from( Reveal.getSlidesElement().querySelectorAll( 'section.past' ) );
const fragmentsInPastSlides = pastSlides.reduce( ( total, slide ) => {
return total + getUniqueFragments( slide.querySelectorAll( '.fragment' ) );
}, 0 );
const fragmentsInCurrentSlide = getUniqueFragments( Reveal.getCurrentSlide().querySelectorAll( '.fragment.visible' ) );
return fragmentsInPastSlides + fragmentsInCurrentSlide;
}
getPastFragmentCount();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment