semaphore/routes/_utils/fullscreen.js

24 lines
949 B
JavaScript
Raw Normal View History

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