Created
February 18, 2010 19:31
-
-
Save miketaylr/307963 to your computer and use it in GitHub Desktop.
This file contains 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
var _canvas = (function(){ | |
var cv = document.createElement('canvas'), | |
c = cv.getContext('2d'); | |
cv.setAttribute('height', 1); | |
cv.setAttribute('width', 1); | |
var canvas = {}, methods = {}, attributes = {}; | |
//stolen from Modernizr 1.2dev : http://github.com/Modernizr/Modernizr/blob/master/modernizr.js#L248 | |
canvas['WebGL'] = (function(){ | |
var g = document.createElement("canvas"), | |
contexts = ["webgl", "experimental-webgl", "moz-webgl", "o-webgl", "webkit-3d", "3d"]; | |
for (var b = -1; ++b < contexts.length; ) { | |
try { | |
if (elem.getContext(contexts[b])) return true; | |
} catch(e){ /* NOM NOM NOM */ } | |
} | |
return false; | |
})(); | |
canvas['2dContext'] = {}; | |
canvas['toDataURL'] = typeof cv['toDataURL'] == 'function'; | |
canvas['2dContext'].methods = (function(meth) { | |
for (var i = 0,len=meth.length;i<len;i++) { | |
methods[meth[i]] = typeof c[meth[i]] == 'function'; | |
} | |
return methods; | |
})('scale rotate translate transform setTransform createLinearGradient createRadialGradient createPattern clearRect fillRect strokeRect beginPath moveTo closePath lineTo quadraticCurveTo bezierCurveTo arcTo arc rect fill stroke clip isPointInPath drawFocusRing fillText strokeText measureText drawImage createImageData getImageData'.split(' ')); | |
canvas['2dContext'].attributes = (function(attr) { | |
for (var i = 0, len=attr.length;i<len;i++) { | |
attributes[attr[i]] = !!(attr[i] in c); | |
}; | |
return attributes; | |
})('strokeStyle fillStyle lineWidth lineCap lineJoin miterLimit shadowColor shadowOffsetX shadowOffsetY shadowBlur font textAlign textBaseline'.split(' ')); | |
return canvas; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment