Skip to content

Instantly share code, notes, and snippets.

@190n
Forked from 140bytes/LICENSE.txt
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 190n/ba2a1259ded422e3cefb to your computer and use it in GitHub Desktop.
Save 190n/ba2a1259ded422e3cefb to your computer and use it in GitHub Desktop.

canvasSupport

HTML5 2D Canvas support in 54 bytes. Evaluates to:

  • 0 if there isn't any Canvas support
  • 0.5 if there's basic support, but no text (text got added later)
  • 1 if there's full support (yay!)
// canvas support:
// 0 = no support
// 0.5 = basic support, but no text
// 1 = full support
// CanvasRenderingContext2D = context object
// TextMetrics = text measurement object
!!this.CanvasRenderingContext2D / 2 + !!this.TextMetrics / 2
!!this.CanvasRenderingContext2D/2+!!this.TextMetrics/2
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
{
"name": "canvasSupport",
"description": "Information about what parts of the 2D HTML5 Canvas this browser supports.",
"keywords": [
"html5",
"canvas-2d",
"support"
]
}
<!DOCTYPE html>
<title>canvasSupport</title>
<h1>HTML5 Canvas Support</h1>
<div id="result">Loading.../div>
<script>
var support = !!this.CanvasRenderingContext2D/2+!!this.TextMetrics/2;
document.getElementById('result').innerHTML = support ? (support - 0.5 ? 'Yay! Your browser has full support!' : 'You have basic support, but no Text API') : 'Boooo! You don\'t have any support!';
</script>
@atk
Copy link

atk commented Jun 2, 2014

Use "this" instead of "window" to save some more bytes.

@190n
Copy link
Author

190n commented Jun 2, 2014

Thanks, @atk!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment