浏览代码

vimeo support for autoplay/pause

Hakim El Hattab 10 年之前
父节点
当前提交
a7a32f941c
共有 1 个文件被更改,包括 24 次插入1 次删除
  1. 24 1
      js/reveal.js

+ 24 - 1
js/reveal.js

@@ -2545,7 +2545,7 @@
 	}
 
 	/**
-	 * Enforces origin-specific format rules for embedded content.
+	 * Enforces origin-specific format rules for embedded media.
 	 */
 	function formatEmbeddedContent() {
 
@@ -2557,6 +2557,14 @@
 			}
 		});
 
+		// Vimeo frames must include "?api=1"
+		toArray( dom.slides.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
+			var src = el.getAttribute( 'src' );
+			if( !/api\=1/gi.test( src ) ) {
+				el.setAttribute( 'src', src + ( !/\?/.test( src ) ? '?' : '' ) + 'api=1' );
+			}
+		});
+
 	}
 
 	/**
@@ -2584,6 +2592,14 @@
 					el.contentWindow.postMessage( '{"event":"command","func":"playVideo","args":""}', '*' );
 				}
 			});
+
+			// Vimeo embeds
+			toArray( slide.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
+				if( el.hasAttribute( 'data-autoplay' ) ) {
+					console.log(11);
+					el.contentWindow.postMessage( '{"method":"play"}', '*' );
+				}
+			});
 		}
 
 	}
@@ -2613,6 +2629,13 @@
 					el.contentWindow.postMessage( '{"event":"command","func":"pauseVideo","args":""}', '*' );
 				}
 			});
+
+			// Vimeo embeds
+			toArray( slide.querySelectorAll( 'iframe[src*="player.vimeo.com/"]' ) ).forEach( function( el ) {
+				if( !el.hasAttribute( 'data-ignore' ) && typeof el.contentWindow.postMessage === 'function' ) {
+					el.contentWindow.postMessage( '{"method":"pause"}', '*' );
+				}
+			});
 		}
 
 	}