Detector.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /**
  2. * @author alteredq / http://alteredqualia.com/
  3. * @author mr.doob / http://mrdoob.com/
  4. */
  5. var Detector = {
  6. canvas: !! window.CanvasRenderingContext2D,
  7. webgl: ( function () {
  8. try {
  9. var canvas = document.createElement( 'canvas' ); return !! ( window.WebGLRenderingContext && ( canvas.getContext( 'webgl' ) || canvas.getContext( 'experimental-webgl' ) ) );
  10. } catch ( e ) {
  11. return false;
  12. }
  13. } )(),
  14. workers: !! window.Worker,
  15. fileapi: window.File && window.FileReader && window.FileList && window.Blob,
  16. getWebGLErrorMessage: function () {
  17. var element = document.createElement( 'div' );
  18. element.id = 'webgl-error-message';
  19. element.style.fontFamily = 'monospace';
  20. element.style.fontSize = '13px';
  21. element.style.fontWeight = 'normal';
  22. element.style.textAlign = 'center';
  23. element.style.background = '#fff';
  24. element.style.color = '#000';
  25. element.style.padding = '1.5em';
  26. element.style.width = '400px';
  27. element.style.margin = '5em auto 0';
  28. if ( ! this.webgl ) {
  29. element.innerHTML = window.WebGLRenderingContext ? [
  30. 'Your graphics card does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">WebGL</a>.<br />',
  31. 'Find out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.'
  32. ].join( '\n' ) : [
  33. 'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">WebGL</a>.<br/>',
  34. 'Find out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.'
  35. ].join( '\n' );
  36. }
  37. return element;
  38. },
  39. addGetWebGLMessage: function ( parameters ) {
  40. var parent, id, element;
  41. parameters = parameters || {};
  42. parent = parameters.parent !== undefined ? parameters.parent : document.body;
  43. id = parameters.id !== undefined ? parameters.id : 'oldie';
  44. element = Detector.getWebGLErrorMessage();
  45. element.id = id;
  46. parent.appendChild( element );
  47. }
  48. };
  49. // browserify support
  50. if ( typeof module === 'object' ) {
  51. module.exports = Detector;
  52. }