Skip to content

Commit

Permalink
Removed graphael.js dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
jsyang committed Apr 4, 2011
1 parent f603a69 commit abd38f5
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions gLayer.js
@@ -0,0 +1,60 @@
/*******************************************************************************
20/04/10 21:41 -- http://jsyang.ca
gLayer -- each is a <CANVAS>-backed object
imgs = array of image filenames to load
fn = callback when done loading imgs
i = array of HTMLImageElements
e = HTMLElement
c = DrawingContext
*******************************************************************************/

function gLayer(imgs,size,fn){

this.w=size[0];
this.h=size[1];

this.i=[];
this.iLoaded=0;

this.callback=fn;

// Check progress of loading event
this.checkProgress=function(obj,n)
{
if(++obj.iLoaded==n) obj.callback(obj);
};


this.e=document.createElement("canvas");
if(size!=undefined)
{
this.e.width=this.w;
this.e.height=this.h;
}
this.c=this.e.getContext('2d');

document.body.appendChild(this.e);

// Clear the canvas for the gLayer
this.clear=function()
{
this.c.clearRect(0,0,this.w,this.h);
};

// Load the images
for(var j in imgs)
{
var a=new Image();
a.src=imgs[j];
this.i.push(a);
a.onerror=function(){ alert("Error in loading "+this.src); };
if(fn!=undefined) a.onload=this.checkProgress(this,imgs.length);
}

// If we didn't have any images, do the callback
if(fn && !imgs.length) fn(this);
}

0 comments on commit abd38f5

Please sign in to comment.