auto play/pause html5 media when entering/leaving slide (#388)

This commit is contained in:
Hakim El Hattab 2013-04-27 18:27:34 -04:00
parent 18795c161f
commit 32736a791c
2 changed files with 38 additions and 2 deletions

View File

@ -1147,6 +1147,10 @@ var Reveal = (function(){
}
}
// Handle embedded content
stopEmbeddedContent( previousSlide );
startEmbeddedContent( currentSlide );
updateControls();
updateProgress();
@ -1419,6 +1423,38 @@ var Reveal = (function(){
}
/**
* Start playback of any embedded content inside of
* the targeted slide.
*/
function startEmbeddedContent( slide ) {
if( slide ) {
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
if( !el.hasAttribute( 'data-ignore' ) ) {
el.play();
}
} );
}
}
/**
* Stop playback of any embedded content inside of
* the targeted slide.
*/
function stopEmbeddedContent( slide ) {
if( slide ) {
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
if( !el.hasAttribute( 'data-ignore' ) ) {
el.pause();
}
} );
}
}
/**
* Reads the current URL (hash) and navigates accordingly.
*/

4
js/reveal.min.js vendored

File diff suppressed because one or more lines are too long