Skip to content

Instantly share code, notes, and snippets.

@shapeshifta78
Last active September 25, 2023 14:09
Show Gist options
  • Save shapeshifta78/268007012e2f0687884ba2c2323121a7 to your computer and use it in GitHub Desktop.
Save shapeshifta78/268007012e2f0687884ba2c2323121a7 to your computer and use it in GitHub Desktop.
/**
* @module fullscreen helper
* @description detection and handling of fullscreen capabilities
* @returns {Object}
*/
export default {
/**
* Returns vendor prefixed fullscreenchange event
* @returns String
*/
change: function () {
return 'mozfullscreenchange webkitfullscreenchange MSFullscreenChange fullscreenchange';
},
/**
* Returns fullscreen element to detect fullscreen state
* @returns (Node|null)
*/
element: function () {
return document.fullscreenElement ||
document.mozFullScreenElement ||
document.webkitFullscreenElement ||
document.msFullscreenElement;
},
/**
* Returns boolean if page is in landscape mode
* @returns {Boolean}
*/
isInLandscapeMode: function() {
return window.orientation === 90 || window.orientation === -90;
},
/**
* requestFullscreen crossbrowser for element
* @param element
*/
request: function (element) {
if (!element) {
throw 'no element defined to request fullscreen';
}
if (element.requestFullscreen) {
element.requestFullscreen();
} else if (element.mozRequestFullScreen) {
element.mozRequestFullScreen();
} else if (element.webkitRequestFullscreen) {
element.webkitRequestFullscreen();
} else if (element.msRequestFullscreen) {
element.msRequestFullscreen();
}
},
/**
* exitFullscreen crossbrowser for element
*/
exit: function () {
if (document.exitFullscreen) {
document.exitFullscreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitExitFullscreen) {
document.webkitExitFullscreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment