Created
February 22, 2012 01:44
-
-
Save nlacasse/1880533 to your computer and use it in GitHub Desktop.
Form to write your messages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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