Permalink
Browse files

changing 'create()' to 'element()' to reflect that the element gets c…

…reated implicitly, and the only purpose of this function is to get the element to insert into the page.
  • Loading branch information...
1 parent 867d1db commit 4514ea5e440fee611b2052b06e9a06d670d44e52 @getify committed Aug 22, 2012
Showing with 11 additions and 14 deletions.
  1. +10 −13 canvas.h5ive.js
  2. +1 −1 example-canvas.js
View
23 canvas.h5ive.js
@@ -23,20 +23,17 @@
cOpts.matchDimensions = ("matchDimensions" in cOpts) ? cOpts.matchDimensions : true;
cOpts.type = (cOpts.type == "webgl") ? "experimental-webgl" : "2d";
+ CANVAS = document.createElement("canvas");
+ CANVAS.setAttribute("width",cOpts.width);
+ CANVAS.setAttribute("height",cOpts.height);
+ if (cOpts.matchDimensions) {
+ CANVAS.style.width = cOpts.width + "px";
+ CANVAS.style.height = cOpts.height + "px";
+ }
- function create() {
- if (CANVAS) throw new Error("Canvas element already created.");
-
- CANVAS = document.createElement("canvas");
- CANVAS.setAttribute("width",cOpts.width);
- CANVAS.setAttribute("height",cOpts.height);
- if (cOpts.matchDimensions) {
- CANVAS.style.width = cOpts.width + "px";
- CANVAS.style.height = cOpts.height + "px";
- }
-
- CONTEXT = CANVAS.getContext(cOpts.type);
+ CONTEXT = CANVAS.getContext(cOpts.type);
+ function element() {
return CANVAS;
}
@@ -193,7 +190,7 @@
publicAPI = {
__raw__: CANVAS,
__raw__context__: CONTEXT,
- create: create,
+ element: element,
clear: clear,
setStyles: setStyles,
startPath: startPath,
View
2 example-canvas.js
@@ -4,7 +4,7 @@ var cnv = h5.canvas({
matchDimensions: true // make the CSS dimensions match the attribute dimensions
});
-document.body.appendChild(cnv.create());
+document.body.appendChild(cnv.element());
cnv
.clear()

0 comments on commit 4514ea5

Please sign in to comment.