Created
September 16, 2016 10:54
-
-
Save peterver/b38ceb36b3e18f734469d20484cb95f0 to your computer and use it in GitHub Desktop.
Detector of browser functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Detect canvas support | |
const DETECTOR = Object.freeze({ | |
CANVAS : (function () { | |
if (window.CanvasRenderingContext2D) { | |
return 'canvas'; | |
} | |
return false; | |
})(), | |
CLASSLIST : (function () { | |
return ('classList' in document.createElement('a')); | |
})(), | |
FULLSCREEN : (function () { | |
if (document.fullscreenEnabled) { | |
return 'fullscreenEnabled'; | |
} | |
if (document.webkitFullscreenEnabled) { | |
return 'webkitFullscreenEnabled'; | |
} | |
if (document.mozFullScreenEnabled) { | |
return 'mozFullScreenEnabled'; | |
} | |
if (document.msFullscreenEnabled) { | |
return 'msFullscreenEnabled'; | |
} | |
return false; | |
})(), | |
PIXELRATIO : (function () { | |
return window.devicePixelRatio || 1; | |
})(), | |
POINTERLOCK : (function () { | |
let canvas = document.createElement('canvas'); | |
if (canvas && canvas.requestPointerLock) { | |
return 'requestPointerLock'; | |
} | |
if (canvas && canvas.mozRequestPointerLock) { | |
return 'mozRequestPointerLock'; | |
} | |
return false; | |
})(), | |
WEBGL : (function () { | |
let canvas = document.createElement('canvas'); | |
if (canvas && canvas.getContext('webgl')) { | |
return 'webgl'; | |
} | |
if (canvas && canvas.getContext('experimental-webgl')) { | |
return 'experimental-webgl'; | |
} | |
return false; | |
})(), | |
}); | |
export default DETECTOR; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment