Created
July 17, 2011 01:11
-
-
Save statico/1086999 to your computer and use it in GitHub Desktop.
PubNub Example Chat
This file contains 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
<div><input id=input placeholder=you-chat-here /></div> | |
<div id=box></div> | |
<div id=pubnub pub-key=demo sub-key=demo></div> | |
<script src=http://cdn.pubnub.com/pubnub-3.1.min.js></script> |
This file contains 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
var box = PUBNUB.$('box'), input = PUBNUB.$('input'), channel = 'chat'; | |
PUBNUB.subscribe({ | |
channel : channel, | |
callback : function(text) { box.innerHTML = (''+text).replace( /[<>]/g, '' ) + '<br/>' + box.innerHTML; } | |
}); | |
PUBNUB.bind( 'keyup', input, function(e) { | |
(e.keyCode || e.charCode) === 13 && PUBNUB.publish({ | |
channel : channel, message : input.value | |
}); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment