Created
June 9, 2022 07:17
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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