Skip to content

Instantly share code, notes, and snippets.

@nlacasse
Created February 22, 2012 01:43
Show Gist options
  • Save nlacasse/1880528 to your computer and use it in GitHub Desktop.
Save nlacasse/1880528 to your computer and use it in GitHub Desktop.
Initial form of the chat to write your nick
// ## The Initial Overlay Form
//
// The overlay form will be the first thing a person sees when running this
// example, it will ask for the name they will want to use for the chat
// session. After submitting the name a `join` message will be sent and the
// the overlay will be hidden.
$('.overlay form').submit(function(event){
event.stopPropagation();
event.preventDefault();
var form = this
, nick = $(form).find('input[name="nick"]').val() || 'Anonymous'
, message
;
// keep track of who you are for later, this will allow us to check if the
// person chatting is mentioned in another person's message.
currentUser = nick;
message = {
type: 'system',
body: 'joined',
author: nick
};
spire.publish('spire.io chat example', message, function (err) {
if (err) throw err;
// Hide the overlay with the initial form.
$('.overlay').hide();
// Focus the input in the footer for a smoother User Experience.
$('footer form input').focus();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment