I have a video player with custom controls
<div>
<video poster="image.jpg" autoplay>
<source src="video.mp4" id="vidM" type="video/mp4"></source>
</video>
<div id="media-controls">
<button type="button" id="play-pause" class="paused" >PLAY</button>
<button type="button" id="rewind10" >REWIND 10 SECONDS</button>
<button type="button" id="loop" >LOOP</button>
<input id="seekslider" type="range" min="0" max="100" value="0">
<span id="curtimetext">00:00</span> / <span id="durtimetext">00:00</span>
<button id="fullscreenbtn" >FS</button>
<button id="popoutbtn" >POPOUT</button>
<div id="fullVolume">
<button id="mutebtn" >MUTE</button>
<div id="volumeContainer"><input id="volumeslider" type="range" min="0" max="100" value="100" step="1" class="vertical" orient="vertical"></div>
</div>
</div>
</div>
and here are the custom controls for JUST the fullscreen Button:
var fullscreenbtn;
fullscreenbtn = document.getElementById("fullscreenbtn");
fullscreenbtn.addEventListener("click",toggleFullScreen,false);
function toggleFullScreen(){
if ( document.fullscreenElement || document.webkitFullscreenElement || document.mozFullScreenElement || document.msFullscreenElement) {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
fullscreenbtn.setAttribute("class", "");
} else{
if ( document.fullscreenEnabled || document.webkitFullscreenEnabled || document.mozFullScreenEnabled || document.msFullscreenEnabled){
if (player.requestFullscreen) {
player.requestFullscreen();
} else if (player.webkitRequestFullscreen) {
player.webkitRequestFullscreen();
} else if (player.mozRequestFullScreen) {
player.mozRequestFullScreen();
} else if (player.msRequestFullscreen) {
player.msRequestFullscreen();
}
fullscreenbtn.setAttribute("class", "fullscreen");
}
}
}
Now here's my problem: When the user CLICKS the fullscreen button to toggle it on or off, the display of the button works just fine (I have some styles attached to the class "fullscreen"). But when a user clicks the ESCAPE button on their keyboard, the function toggles to disable fullscreen mode, but does NOT remove the 'fullscreen' class.
What do I need to add to my function to allow the toggle to still execute