Skip to content

Instantly share code, notes, and snippets.

@getify
Created September 6, 2010 20:57
Show Gist options
  • Save getify/567511 to your computer and use it in GitHub Desktop.
Save getify/567511 to your computer and use it in GitHub Desktop.
// shorten/alias long canvas method names
// adapted from: http://marijn.haverbeke.nl/js1k.html
var Canv = document.body.children.c,
Gr = Canv.getContext("2d"),
prop
;
for (prop in Gr) {
Gr[ prop[0] + (prop[3]||"") + (prop[6]||"") ] = Gr[prop];
}
/*
arc => a
arcTo => aT
beginPath => bia
bezierCurveTo => biC
clearRect => cae
clearShadow => cah
createImageData => caI
createLinearGradient => caL
createPattern => caP
createRadialGradient => caR
clip => cp
closePath => csa
canvas => cv
drawImage => dwa ********
drawImageFromRect => dwa ********
fill => fl
fillRect => flc
fillText => flx
fillStyle => fly
font => ft
globalAlpha => gbA
globalCompositeOperation => gbC
getImageData => gIg
isPointInPath => iot
lineTo => le
lineWidth => led
lineJoin => lei
lineCap => lep
moveTo => me
miterLimit => mei
measureText => mse
putImageData => pIg
quadraticCurveTo => qdt
rotate => ra
rect => rt
restore => rte
setAlpha => sAh
setCompositeOperation => sCp
shadowBlur => sdB
shadowColor => sdC
shadowOffsetY => sdO ********
shadowOffsetX => sdO ********
save => se
setFillColor => sFl
scale => sl
setLineWidth => sLe ********
setLineCap => sLe ********
setLineJoin => sLe ********
setMiterLimit => sMe
stroke => so
strokeRect => soR
strokeStyle => soS
strokeText => soT
setShadow => sSd
setStrokeColor => sSo
setTransform => sTn
translate => tna
transform => tno
textAlign => tti
textBaseline => tts
*/
@getify
Copy link
Author

getify commented Sep 8, 2010

clearly this particular hashing algorithm, with collisions, is not acceptable. but maybe one similar to it would be good enough to not create collisions, and therefore be useful in the task.

@marijnh
Copy link

marijnh commented Sep 9, 2010

I'd say this is also useless for minifiers. Browser-specific extensions can easily cause conflicts and break this. Gimmicky contests seem to be the only real use ;)

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