public/index.js
// update UI the list of games:
update UI the list of games.
update UI the list of games .
function addGame(jqList, game) {
    var gameColor = 'deep-purple lighten-5';
    var gameName = 'Room ' + game.room;
    var readyCount = 0;
    for (var i = 0; i < game.players.length; i++) {
        if (game.players[i].ready)
            readyCount++;
    }
    if (readyCount >= 2) {
        gameColor = 'purple darken-2 white-text';
    }
    else if (game.players.length > 0) {
        gameColor = 'yellow lighten-2';
    }
    var jqGame = $('<div></div>').addClass('card-panel ' + gameColor).css({ 'position': 'relative' }).html(gameName);
    if (game.players.length > 0) {
        jqGame.append($('<div></div>').addClass('caro-user-stat right').html(game.players.length + ((game.players.length > 1) ? ' users' : ' user')+((readyCount>=2) ? '<br/>Playing...' : '')));
    }
    var jqGameWrapper = $('<div></div>').addClass('waves-effect waves-light col s12 m6 l4 caro-game-item-wrapper').css({ 'padding': 0 }).data({ 'id': game.id }).click(function (event) {
        var game_id = $(this).data('id');
        location.href = '/game/' + game_id;
    }).append(jqGame);
    jqList.append(jqGameWrapper);
}
function addGame ( jqList , game ) { var gameColor = 'deep-purple lighten-5' ; var gameName = 'Room ' + game . room ; var readyCount = 0 ; for ( var i = 0 ; i < game . players . length ; i ++ ) { if ( game . players [ i ] . ready ) readyCount ++ ; } if ( readyCount >= 2 ) { gameColor = 'purple darken-2 white-text' ; } else if ( game . players . length > 0 ) { gameColor = 'yellow lighten-2' ; } var jqGame = $ ( '<div></div>' ) . addClass ( 'card-panel ' + gameColor ) . css ( { 'position' : 'relative' } ) . html ( gameName ) ; if ( game . players . length > 0 ) { jqGame . append ( $ ( '<div></div>' ) . addClass ( 'caro-user-stat right' ) . html ( game . players . length + ( ( game . players . length > 1 ) ? ' users' : ' user' ) + ( ( readyCount >= 2 ) ? '<br/>Playing...' : '' ) ) ) ; } var jqGameWrapper = $ ( '<div></div>' ) . addClass ( 'waves-effect waves-light col s12 m6 l4 caro-game-item-wrapper' ) . css ( { 'padding' : 0 } ) . data ( { 'id' : game . id } ) . click ( function ( event ) { var game_id = $ ( this ) . data ( 'id' ) ; location . href = '/game/' + game_id ; } ) . append ( jqGame ) ; jqList . append ( jqGameWrapper ) ; }
update UI the list of games:
update UI the list of games :