From 32736a791c3e56298e3359d58d9a5561eaa82a47 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sat, 27 Apr 2013 18:27:34 -0400 Subject: auto play/pause html5 media when entering/leaving slide (#388) --- js/reveal.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'js/reveal.js') diff --git a/js/reveal.js b/js/reveal.js index c2f3722..d321dde 100644 --- a/js/reveal.js +++ b/js/reveal.js @@ -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. */ -- cgit v1.2.3