aqua
unread,Sep 13, 2011, 5:50:50 AM9/13/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jasmine
Hello all,
i got a new project in which i have to use the html5 canvas element to
draw some stuff in the browser.
now i decided to use the jasmine framework to write some good code,
but im stuck in setting up the tests.
it would be nice if i get some hints in the correct direction, because
im new to javascript and the html DOM
concepts.
so i have a simple html file:
..<body><canvas id="screen"></canvas>...
then i have a js file, which uses some functions from this canvas
object:
var DOM_canvas = document.getElementById( "screen" );
_this.Screen = new cScreen( DOM_canvas );
...
function cScreen( canvas )
{
var _this = this;
_this.support = false;
var canvas = canvas;
var ctx = null;
var ctxType = null;
var init = function()
{
if ( !canvas.getContext ) { return false; } //
_this.support = true;
ctx = canvas.getContext( '2d' );
ctxtype = "2d";
_this.drawTrash("a lot!");
}
...
}
now my problem is: i cant initialize the object without the <canvas>
element in the document. i can append or create the canvas element,
but while initialization, it will draw some trash on my jasmine test
output. so i need to "fake" this DOM element, and append some
functions to it, which i can call.
but when i fake it, i cant capture some events, for example a
mouseclick or keypress event.
how can i do this? i would be very happy about a few pointers in the
right direction, so i can gain the knowledge to do it =)
how is generally the best way to handle DOM elements, which have their
own methods?
thx a lot! :)
ps: i searched one hour, but i didnt find an answer which solves my
prob.