Is there a more efficient way for me to implement the toggleFullscreen()
function? Currently, I am redundantly setting the style rules for each browser, which seems unnecessary.
function toggleFullScreen() {
var elem = document.getElementById("video_container");
var db = document.getElementById("defaultBar");
var ctrl = document.getElementById("controls");
if (!document.fullscreenElement && // using alternative standard method
!document.mozFullScreenElement && !document.webkitFullscreenElement) { // using current working methods
if (document.documentElement.requestFullscreen) {
db.style.background ='red';
ctrl.style.width = '50%';
ctrl.style.left = '25%';
elem.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
db.style.background ='red';
ctrl.style.width = '50%';
ctrl.style.left = '25%';
elem.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
db.style.background ='red';
ctrl.style.width = '50%';
ctrl.style.left = '25%';
elem.webkitRequestFullscreen();
}
} else if (document.exitFullscreen) {
db.style.background ='yellow';
ctrl.style.width = '100%';
ctrl.style.left = '0';
document.exitFullscreen();
}
else if (document.mozCancelFullScreen) {
db.style.background ='yellow';
ctrl.style.width = '100%';
ctrl.style.left = '0';
document.mozCancelFullScreen();
}
else if (document.webkitCancelFullScreen) {
db.style.background ='yellow';
ctrl.style.width = '100%';
ctrl.style.left = '0';
document.webkitCancelFullScreen();
}
}