pinafore/routes/_utils/fullscreen.js

24 lines
949 B
JavaScript
Raw Normal View History

2018-01-21 00:37:40 +01:00
export const isFullscreen = () => !!(document.fullscreenElement ||
document.webkitFullscreenElement ||
2018-02-09 07:29:29 +01:00
document.mozFullScreenElement)
2018-01-21 00:37:40 +01:00
export const attachFullscreenListener = (listener) => {
if ('onfullscreenchange' in document) {
2018-02-09 07:29:29 +01:00
document.addEventListener('fullscreenchange', listener)
2018-01-21 00:37:40 +01:00
} else if ('onwebkitfullscreenchange' in document) {
2018-02-09 07:29:29 +01:00
document.addEventListener('webkitfullscreenchange', listener)
2018-01-21 00:37:40 +01:00
} else if ('onmozfullscreenchange' in document) {
2018-02-09 07:29:29 +01:00
document.addEventListener('mozfullscreenchange', listener)
2018-01-21 00:37:40 +01:00
}
2018-02-09 07:29:29 +01:00
}
2018-01-21 00:37:40 +01:00
export const detachFullscreenListener = (listener) => {
if ('onfullscreenchange' in document) {
2018-02-09 07:29:29 +01:00
document.removeEventListener('fullscreenchange', listener)
2018-01-21 00:37:40 +01:00
} else if ('onwebkitfullscreenchange' in document) {
2018-02-09 07:29:29 +01:00
document.removeEventListener('webkitfullscreenchange', listener)
2018-01-21 00:37:40 +01:00
} else if ('onmozfullscreenchange' in document) {
2018-02-09 07:29:29 +01:00
document.removeEventListener('mozfullscreenchange', listener)
2018-01-21 00:37:40 +01:00
}
2018-02-09 07:29:29 +01:00
}