From d76fa8abfe91b6640690e19c9e6bb2b955520432 Mon Sep 17 00:00:00 2001 From: Steve Heffernan Date: Thu, 10 Jun 2010 16:55:56 -0700 Subject: [PATCH] Added esc key for fullscreen mode. --- demo.html | 6 ++++++ video.js | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/demo.html b/demo.html index 3fbb2f2d7..f195b3ca8 100644 --- a/demo.html +++ b/demo.html @@ -25,8 +25,14 @@ VideoJS.setup(); } + document.addEventListener("keydown", function(e){ + // alert(e.keyCode); + }, false); + + + diff --git a/video.js b/video.js index 78b1c0274..eadd1aba0 100644 --- a/video.js +++ b/video.js @@ -104,6 +104,14 @@ var VideoJS = Class.extend({ // Have to add the mouseout to the controller too or it may not hide. // For some reason the same isn't needed for mouseover this.controls.addEventListener("mouseout", this.onVideoMouseOut.context(this), false); + + // Create listener for esc key while in full screen mode + // Creating it here to add context + this.escKeyListener = function(event){ + if (event.keyCode == 27) { + this.fullscreenOff(); + } + }.context(this); // Support older browsers that used autobuffer if (this.video.preload) this.video.autobuffer = true; @@ -490,6 +498,9 @@ var VideoJS = Class.extend({ // Storing original doc overflow value to return to when fullscreen is off this.docOrigOverflow = document.documentElement.style.overflow; + // Add listener for esc key to exit fullscreen + document.addEventListener("keydown", this.escKeyListener, false); + // Hide any scroll bars document.documentElement.style.overflow = 'hidden'; @@ -505,6 +516,8 @@ var VideoJS = Class.extend({ fullscreenOff: function(){ this.videoIsFullScreen = false; + document.removeEventListener("keydown", this.escKeyListener, false); + // Unhide scroll bars. document.documentElement.style.overflow = this.docOrigOverflow;