HTML5 Guidelines for Web Developers

(coco) #1
9.3 Example: Battleships! 243

var txt = ''+msg.from.nick+'';
txt += 'wants to play a game with you.';
txt += 'Accept?';
frm.sender.previousSibling.innerHTML = txt;
frm.sender.value = msg.from.id;
frm.sendernick.value = msg.from.nick;
frm.style.display = 'inline';
}
};


Figure 9.4 The dialog box inviting you to a new game


So the ID and nickname of the person who sends the invite are contained in the
form inviteConfirm, and the message window can be displayed. When the other
player clicks on Yes or No, the appropriate response is sent back to the inviter via
the server and once again lands in the onmessage callback:


else if (msg.request == 'confirm') {
if (msg.choice == true) {
wsMessage({
task : 'setPlaying',
client : msg.from.id
});
prepareGame(msg.from.id,msg.from.nick);
document.forms.loggedin.style.display = 'none';
}
else {
show('nothanks');
window.setTimeout(function() {
hide('nothanks');
document.forms.users.style.display = 'inline';
}, 2000);
}
}

Free download pdf