From 9d060fd25f30eb602e15cb13cbd48c27dd606291 Mon Sep 17 00:00:00 2001 From: Gwenhael Le Moine Date: Thu, 7 Jul 2011 09:09:07 +0200 Subject: [PATCH] store the dom element where star will be displayed --- star.js/js/star.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/star.js/js/star.js b/star.js/js/star.js index 09ca70a..f300db2 100644 --- a/star.js/js/star.js +++ b/star.js/js/star.js @@ -22,7 +22,8 @@ var css_classes = { "x" : "gift" }; var options = { - starting_level : 0 + starting_level : 0, + dom_place : "" }; var state = { moving : cell.BALL, @@ -136,6 +137,11 @@ function format_infos( state ) { return infos; } +function display_level( state, elt ) { + var starhtml = '
' + format_level( state, false ) + '
'; + $( elt ).html( starhtml ); +} + function load_level( levelset, nb ) { state.level = nb; state.board = levelset[ state.level ]; @@ -144,12 +150,6 @@ function load_level( levelset, nb ) { return state; } -function display_level( state, elt ) { - var starhtml = '
' + format_level( state, false ) + '
'; - $( elt ).html( starhtml ); -} - - function make_a_move( state, where ) { var motion = [ 0, 0 ]; var item_coord = get_pos( state, state.moving ); @@ -195,7 +195,8 @@ function make_a_move( state, where ) { } function start_loop( state, elt ) { - display_level( state, elt ); + options.dom_place = elt; + display_level( state, options.dom_place ); $( document ).keydown( function( e ) { switch( e.keyCode ) { @@ -230,13 +231,13 @@ function start_loop( state, elt ) { if ( won_or_not( state ) ) { if ( state.level < levels.length - 1 ) { - state = load_level( levels, state.level + 1 ); + state = load_level( levels, state.level + 1 ); } else { alert( "You won!" ); } } - display_level( state, elt ); + display_level( state, options.dom_place ); }); }