From af61d9d10baee982fe82132acc4cd2dd604a6c61 Mon Sep 17 00:00:00 2001
From: Hakim El Hattab <hakim.elhattab@gmail.com>
Date: Thu, 12 Jun 2014 18:15:32 +0200
Subject: [PATCH] rewrite youtube iframe embeds to force ?enablejsapi=1 (fixes
 #856)

---
 js/reveal.js | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/js/reveal.js b/js/reveal.js
index c311fb0..f98d511 100644
--- a/js/reveal.js
+++ b/js/reveal.js
@@ -1959,6 +1959,8 @@
 		updateSlideNumber();
 		updateSlidesVisibility();
 
+		formatEmbeddedContent();
+
 	}
 
 	/**
@@ -2542,6 +2544,21 @@
 
 	}
 
+	/**
+	 * Enforces origin-specific format rules for embedded content.
+	 */
+	function formatEmbeddedContent() {
+
+		// YouTube frames must include "?enablejsapi=1"
+		toArray( dom.slides.querySelectorAll( 'iframe[src*="youtube.com/embed/"]' ) ).forEach( function( el ) {
+			var src = el.getAttribute( 'src' );
+			if( !/enablejsapi\=1/gi.test( src ) ) {
+				el.setAttribute( 'src', src + ( !/\?/.test( src ) ? '?' : '' ) + 'enablejsapi=1' );
+			}
+		});
+
+	}
+
 	/**
 	 * Start playback of any embedded content inside of
 	 * the targeted slide.
-- 
GitLab