Skip to content

Instantly share code, notes, and snippets.

@nlacasse
Created February 22, 2012 01:44
Show Gist options
  • Select an option

  • Save nlacasse/1880533 to your computer and use it in GitHub Desktop.

Select an option

Save nlacasse/1880533 to your computer and use it in GitHub Desktop.
Form to write your messages
// The footer form is what handles the actual messages going to everyone in
// the room. Anything a person types and submits into the form will be
// displayed to everyone in the room.
$('footer form').submit(function(event){
event.stopPropagation();
event.preventDefault();
var form = this
, message = { author: currentUser
, body: $(form).find('input[name="content"]').val()
};
// No message content? don't do anything.
if (! message.body) return;
// Send the message constructed above, once the message is sent the
// `callback` will remove the submitted text and re-focus the input
spire.publish('spire.io chat example', message, function (err) {
if (err) throw err;
$(form).find('input').val('').focus();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment