fix inconsistent fragment visibility in looping presentations #3123

This commit is contained in:
hakimel 2022-04-04 15:11:57 +02:00
parent e281b3234e
commit 914b2aea83
5 changed files with 44 additions and 11 deletions

2
dist/reveal.esm.js vendored

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

2
dist/reveal.js vendored

File diff suppressed because one or more lines are too long

2
dist/reveal.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -1571,15 +1571,20 @@ export default function( revealElement, options ) {
slidesLength = slides.length; slidesLength = slides.length;
let printMode = print.isPrintingPDF(); let printMode = print.isPrintingPDF();
let loopedForwards = false;
let loopedBackwards = false;
if( slidesLength ) { if( slidesLength ) {
// Should the index loop? // Should the index loop?
if( config.loop ) { if( config.loop ) {
if( index >= slidesLength ) loopedForwards = true;
index %= slidesLength; index %= slidesLength;
if( index < 0 ) { if( index < 0 ) {
index = slidesLength + index; index = slidesLength + index;
loopedBackwards = true;
} }
} }
@ -1617,10 +1622,7 @@ export default function( revealElement, options ) {
if( config.fragments ) { if( config.fragments ) {
// Show all fragments in prior slides // Show all fragments in prior slides
Util.queryAll( element, '.fragment' ).forEach( fragment => { showFragmentsIn( element );
fragment.classList.add( 'visible' );
fragment.classList.remove( 'current-fragment' );
} );
} }
} }
else if( i > index ) { else if( i > index ) {
@ -1629,9 +1631,17 @@ export default function( revealElement, options ) {
if( config.fragments ) { if( config.fragments ) {
// Hide all fragments in future slides // Hide all fragments in future slides
Util.queryAll( element, '.fragment.visible' ).forEach( fragment => { hideFragmentsIn( element );
fragment.classList.remove( 'visible', 'current-fragment' ); }
} ); }
// 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 );
} }
} }
} }
@ -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 * Optimization method; hide all slides that are far away
* from the present slide. * from the present slide.