Detector.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 () { try { return !! window.WebGLRenderingContext && !! document.createElement( 'canvas' ).getContext( 'experimental-webgl' ); } catch( e ) { return false; } } )(),
  8. workers: !! window.Worker,
  9. fileapi: window.File && window.FileReader && window.FileList && window.Blob,
  10. getWebGLErrorMessage: function () {
  11. var element = document.createElement( 'div' );
  12. element.id = 'webgl-error-message';
  13. element.style.fontFamily = 'monospace';
  14. element.style.fontSize = '13px';
  15. element.style.fontWeight = 'normal';
  16. element.style.textAlign = 'center';
  17. element.style.background = '#fff';
  18. element.style.color = '#000';
  19. element.style.padding = '1.5em';
  20. element.style.width = '400px';
  21. element.style.margin = '5em auto 0';
  22. if ( ! this.webgl ) {
  23. element.innerHTML = window.WebGLRenderingContext ? [
  24. '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 />',
  25. 'Find out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.'
  26. ].join( '\n' ) : [
  27. 'Your browser does not seem to support <a href="http://khronos.org/webgl/wiki/Getting_a_WebGL_Implementation" style="color:#000">WebGL</a>.<br/>',
  28. 'Find out how to get it <a href="http://get.webgl.org/" style="color:#000">here</a>.'
  29. ].join( '\n' );
  30. }
  31. return element;
  32. },
  33. addGetWebGLMessage: function ( parameters ) {
  34. var parent, id, element;
  35. parameters = parameters || {};
  36. parent = parameters.parent !== undefined ? parameters.parent : document.body;
  37. id = parameters.id !== undefined ? parameters.id : 'oldie';
  38. element = Detector.getWebGLErrorMessage();
  39. element.id = id;
  40. parent.appendChild( element );
  41. }
  42. };