From a7a32f941cb8c09c85865e5a287be82bc2e14adb Mon Sep 17 00:00:00 2001
From: Hakim El Hattab <hakim.elhattab@gmail.com>
Date: Thu, 12 Jun 2014 18:20:15 +0200
Subject: [PATCH] vimeo support for autoplay/pause

---
 js/reveal.js | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/js/reveal.js b/js/reveal.js
index f98d511..df8c0f6 100644
--- a/js/reveal.js
+++ b/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"}', '*' );
+				}
+			});
 		}
 
 	}
-- 
GitLab