auto play/pause youtube video when entering/leaving slide (#388)
This commit is contained in:
parent
32736a791c
commit
ed4a8b51c5
16
js/reveal.js
16
js/reveal.js
@ -1430,11 +1430,19 @@ var Reveal = (function(){
|
|||||||
function startEmbeddedContent( slide ) {
|
function startEmbeddedContent( slide ) {
|
||||||
|
|
||||||
if( slide ) {
|
if( slide ) {
|
||||||
|
// HTML5 media elements
|
||||||
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
|
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
|
||||||
if( !el.hasAttribute( 'data-ignore' ) ) {
|
if( !el.hasAttribute( 'data-ignore' ) ) {
|
||||||
el.play();
|
el.play();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// YouTube embeds
|
||||||
|
toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
|
||||||
|
if( !el.hasAttribute( 'data-ignore' ) ) {
|
||||||
|
el.contentWindow.postMessage('{"event":"command","func":"playVideo","args":""}', '*');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1446,11 +1454,19 @@ var Reveal = (function(){
|
|||||||
function stopEmbeddedContent( slide ) {
|
function stopEmbeddedContent( slide ) {
|
||||||
|
|
||||||
if( slide ) {
|
if( slide ) {
|
||||||
|
// HTML5 media elements
|
||||||
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
|
toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
|
||||||
if( !el.hasAttribute( 'data-ignore' ) ) {
|
if( !el.hasAttribute( 'data-ignore' ) ) {
|
||||||
el.pause();
|
el.pause();
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
// YouTube embeds
|
||||||
|
toArray( slide.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
|
||||||
|
if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
|
||||||
|
el.contentWindow.postMessage('{"event":"command","func":"pauseVideo","args":""}', '*');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
4
js/reveal.min.js
vendored
4
js/reveal.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user