Skip to content

Commit

Permalink
fix inconsistent fragment visibility in looping presentations hakimel…
Browse files Browse the repository at this point in the history
  • Loading branch information
hakimel committed Apr 4, 2022
1 parent e281b32 commit 914b2ae
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/reveal.esm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.esm.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/reveal.js.map

Large diffs are not rendered by default.

47 changes: 40 additions & 7 deletions js/reveal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1571,15 +1571,20 @@ export default function( revealElement, options ) {
slidesLength = slides.length;

let printMode = print.isPrintingPDF();
let loopedForwards = false;
let loopedBackwards = false;

if( slidesLength ) {

// Should the index loop?
if( config.loop ) {
if( index >= slidesLength ) loopedForwards = true;

index %= slidesLength;

if( index < 0 ) {
index = slidesLength + index;
loopedBackwards = true;
}
}

Expand Down Expand Up @@ -1617,10 +1622,7 @@ export default function( revealElement, options ) {

if( config.fragments ) {
// Show all fragments in prior slides
Util.queryAll( element, '.fragment' ).forEach( fragment => {
fragment.classList.add( 'visible' );
fragment.classList.remove( 'current-fragment' );
} );
showFragmentsIn( element );
}
}
else if( i > index ) {
Expand All @@ -1629,9 +1631,17 @@ export default function( revealElement, options ) {

if( config.fragments ) {
// Hide all fragments in future slides
Util.queryAll( element, '.fragment.visible' ).forEach( fragment => {
fragment.classList.remove( 'visible', 'current-fragment' );
} );
hideFragmentsIn( element );
}
}
// Update the visibility of fragments when a presentation loops
// in either direction
else if( i === index && config.fragments ) {
if( loopedForwards ) {
hideFragmentsIn( element );
}
else if( loopedBackwards ) {
showFragmentsIn( element );
}
}
}
Expand Down Expand Up @@ -1671,6 +1681,29 @@ export default function( revealElement, options ) {

}

/**
* Shows all fragment elements within the given contaienr.
*/
function showFragmentsIn( container ) {

Util.queryAll( container, '.fragment' ).forEach( fragment => {
fragment.classList.add( 'visible' );
fragment.classList.remove( 'current-fragment' );
} );

}

/**
* Hides all fragment elements within the given contaienr.
*/
function hideFragmentsIn( container ) {

Util.queryAll( container, '.fragment.visible' ).forEach( fragment => {
fragment.classList.remove( 'visible', 'current-fragment' );
} );

}

/**
* Optimization method; hide all slides that are far away
* from the present slide.
Expand Down

0 comments on commit 914b2ae

Please sign in to comment.