From 68aa4c884924cb5df271540259b8cfb39befc2af Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Wed, 13 Jul 2011 20:18:39 +0200 Subject: [PATCH] if html skeleton hasn't been pushed in the DOM it's rather difficult to operate on #facepalm --- star.js/js/star.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/star.js/js/star.js b/star.js/js/star.js index 7acf888..c2cc31c 100644 --- a/star.js/js/star.js +++ b/star.js/js/star.js @@ -193,7 +193,7 @@ function make_a_move( state, where ) { return state; } -function start_loop( state, elt ) { +function start_loop( state, elt, board_infos ) { options.dom_place = elt; display_level( state, options.dom_place ); @@ -204,8 +204,8 @@ function start_loop( state, elt ) { var movingpos = get_pos( state, state.moving ); var notmovingpos = get_pos( state, ( state.moving != cell.BALL ) ? cell.BALL : cell.CUBE ); var click = {}; - click.x = e.pageX - board_infos.position.left; - click.y = e.pageY - board_infos.position.top; + click.x = e.pageX - board_infos.offset.left; + click.y = e.pageY - board_infos.offset.top; if ( ( 0 <= click.x && click.x < board_infos.dimensions.width ) && ( 0 <= click.y && click.y < board_infos.dimensions.height ) ) { @@ -297,10 +297,13 @@ function initialize_a_star( elt ) { starhtml += ''; starhtml += ''; - board_infos.position = $(elt + "#starboard").offset(); + $( elt ).html( starhtml ); + + var board_infos = {}; + board_infos.offset = $(elt + " #starboard").offset(); board_infos.dimensions = {}; - board_infos.dimensions.width = $(elt + "#starboard").width(); - board_infos.dimensions.height = $(elt + "#starboard").height(); + board_infos.dimensions.width = $(elt + " #starboard").width(); + board_infos.dimensions.height = $(elt + " #starboard").height(); board_infos.cell_dimensions = {}; board_infos.cell_dimensions.width = board_infos.dimensions.width / LEVEL_WIDTH; board_infos.cell_dimensions.height = board_infos.dimensions.height / LEVEL_HEIGHT; @@ -319,11 +322,10 @@ function initialize_a_star( elt ) { sprites.void.src = "themes/HP48/tex_empty.png"; sprites.gift = new Image(); sprites.gift.src = "themes/HP48/tex_gift.png"; - $( elt ).html( starhtml ); state = load_level( levels, 0 ); // display_level( state, options.dom_place ); display_on_canvas( state, "starboard" ); - start_loop( state, elt ); + start_loop( state, elt, board_infos ); }