Skip to content

Instantly share code, notes, and snippets.

@hyonschu
Created May 25, 2013 19:03
Show Gist options
  • Save hyonschu/5650337 to your computer and use it in GitHub Desktop.
Save hyonschu/5650337 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://chatbuilder.hackreactor.com/ChatBuilder.js"></script>
</head>
<body>
<script>
Chat.guide.start();
//Your JavaScript code will go right here!
delete Chat.display;
delete Chat.fetch;
delete Chat.send;
/* function splitMsgs(msgs) {
$("ul").empty();
for (var i=0;i<msgs.length;i++){
$("ul").append("<li>"+msgs[i]+"</li>");
}
} */
function fetchText() {
$.get("https://api.parse.com/1/classes/chats", { order: "createdAt" }, function(data) {
$("ul").empty();
for (var i=0;i<10;i++) {
$("ul").append("<li>"+data.results[i].text+"</li>");
}
});
};
$(document).ready(function(){
setInterval("fetchText();",3000);
$(".send").click(function(){
if ($(".draft").val().length < 1) {
$("ul").prepend("<font color='red'>You must type something in the chat box! </font>");
} else {
var JSONtext = JSON.stringify( { "text": Chat.username+": "+$(".draft").val() } )
$.post("https://api.parse.com/1/classes/chats", JSONtext);
$(".draft").val('');
console.log(JSONtext); }
})
})
</script>
<h2>Borken Chat</h2>
<input class="draft" type="text" value="Bob Loblaw At Large"/> <button class="send" >send</button>
<ul class="messages">
<!-- once you save this code to a local `.html()` file, you can delete these 3 fake, hard-coded li elements -->
<li>Mysterious_guide: Hey there! Lets build a chat application.</li>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment