Skip to content

Commit

Permalink
add support for node-canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltask committed Jan 31, 2012
1 parent c55aa4d commit b4b397d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 12 deletions.
4 changes: 4 additions & 0 deletions .gitignore
@@ -0,0 +1,4 @@
.DS_Store
._*
Thumbs.db
node_modules
24 changes: 24 additions & 0 deletions package.json
@@ -0,0 +1,24 @@
{
"name": "qcanver",
"description": "Canvas API wrapper and some useful functions.",
"version": "0.0.1",
"author": "daisun",
"maintainers": [{
"name": "Seiya Konno",
"email": "nulltask@gmail.com"
}],
"keywords": ["isomorphic", "canvas", "wrapper"],
"dependencies": {
"canvas": "0.x"
},
"repository": "git@github.com:nulltask/qcanver.git",
"devDependencies": {
"mocha": "*",
"express": "2.x",
"jade": "0.x"
},
"engines": {
"node": ">= 0.6.0 && < 0.7.0"
},
"main": "./qcanver.js"
}
39 changes: 27 additions & 12 deletions qcanver.js
@@ -1,4 +1,4 @@
(function (window) {
(function (global) {
var qCanver = (function (undefined) {
var slice = Array.prototype.slice,
toString = Object.prototype.toString,
Expand Down Expand Up @@ -39,7 +39,7 @@ var qCanver = (function (undefined) {
qCanver = (function (_QCanver) {
var cache = {},
qCanver = function(id, noCache) {
var canvas = document.getElementById(id);
var canvas = Object.prototype.toString.call(id) === '[object String]' ? document.getElementById(id) : id;
if (canvas && canvas.getContext) {
if (!noCache) {
if (cache[id]) {
Expand All @@ -54,15 +54,20 @@ var qCanver = (function (undefined) {

qCanver.Version = "0.0.1";
qCanver.create = function (id, width, height) {
var canvas = document.createElement("canvas");
canvas.setAttribute("id", id);
if (qCanver.type(width) === "number") {
canvas.setAttribute("width", width);
}
if (qCanver.type(height) === "number") {
canvas.setAttribute("height", height);
var canvas;
if (qCanver.isWindow(global)) {
canvas = document.createElement("canvas");
canvas.setAttribute("id", id);
if (qCanver.type(width) === "number") {
canvas.setAttribute("width", width);
}
if (qCanver.type(height) === "number") {
canvas.setAttribute("height", height);
}
} else {
var Canvas = require('canvas');
canvas = new Canvas(width, height);
}

return new _QCanver(id, canvas);
};
qCanver.extend = function (/*(name, f) | obj*/) {
Expand Down Expand Up @@ -602,10 +607,20 @@ var qCanver = (function (undefined) {
}

return this;
},
isWindow: function(obj) {
return obj != null && obj == obj.window;
}
});
})(qCanver);

if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
exports = module.exports = qCanver;
}
exports.qCanver = qCanver;
} else {
global['qCanver'] = qCanver;
}

window.qCanver = qCanver;
})(window);
})(this);

0 comments on commit b4b397d

Please sign in to comment.