瀏覽代碼

auto play/pause youtube video when entering/leaving slide (#388)

Hakim El Hattab 11 年之前
父節點
當前提交
ed4a8b51c5
共有 2 個文件被更改,包括 17 次插入1 次删除
  1. 16 0
      js/reveal.js
  2. 1 1
      js/reveal.min.js

+ 16 - 0
js/reveal.js

@@ -1430,11 +1430,19 @@ var Reveal = (function(){
 	function startEmbeddedContent( slide ) {
 
 		if( slide ) {
+			// HTML5 media elements
 			toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
 				if( !el.hasAttribute( 'data-ignore' ) ) {
 					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 ) {
 
 		if( slide ) {
+			// HTML5 media elements
 			toArray( slide.querySelectorAll( 'video, audio' ) ).forEach( function( el ) {
 				if( !el.hasAttribute( 'data-ignore' ) ) {
 					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":""}', '*');
+				}
+			});
 		}
 
 	}

File diff suppressed because it is too large
+ 1 - 1
js/reveal.min.js


Some files were not shown because too many files changed in this diff