application/static/game.js
// Function that sets up the logic for emitting a socket message when clicking on a button.
Function that sets up the logic for emitting a socket message when clicking on a button.
Function that sets up the logic for emitting a socket message when clicking on a button .
function add_button_event_listeners(socket, roomName) {
    const guessWordSubmitElement = document.getElementById("guessWordSubmit");
    const guessWordInputElement = document.getElementById("guessWordInput");
    guessWordSubmitElement.addEventListener('click', (event) => {
        clearPath();
        const guessWordInputElement = document.getElementById("guessWordInput");
        const guess = guessWordInputElement.value;
        socket.emit('guess', {'room': roomName, 'guess': guess});
        guessWordInputElement.value = "";
        guessWordInputElement.focus();
    });
    guessWordInputElement.addEventListener("keyup", event => {
        if (event.key === "Enter") {
            guessWordSubmitElement.click();
        }
    });
    document.getElementById("new-game-button").addEventListener('click', (event) => {
        confirmAndStartNewGame(socket, roomName);
    });
    guessWordInputElement.focus();
}
function add_button_event_listeners ( socket , roomName ) { const guessWordSubmitElement = document . getElementById ( "guessWordSubmit" ) ; const guessWordInputElement = document . getElementById ( "guessWordInput" ) ; guessWordSubmitElement . addEventListener ( 'click' , ( event ) => { clearPath ( ) ; const guessWordInputElement = document . getElementById ( "guessWordInput" ) ; const guess = guessWordInputElement . value ; socket . emit ( 'guess' , { 'room' : roomName , 'guess' : guess } ) ; guessWordInputElement . value = "" ; guessWordInputElement . focus ( ) ; } ) ; guessWordInputElement . addEventListener ( "keyup" , event => { if ( event . key === "Enter" ) { guessWordSubmitElement . click ( ) ; } } ) ; document . getElementById ( "new-game-button" ) . addEventListener ( 'click' , ( event ) => { confirmAndStartNewGame ( socket , roomName ) ; } ) ; guessWordInputElement . focus ( ) ; }
Function that sets up the logic for emitting a socket message when clicking on a button.
Function that sets up the logic for emitting a socket message when clicking on a button .
// Add event listener to guess buttons and input text box // Add event listener to new game button // Give the input text box default focus once the page loads.