Last active
December 18, 2015 04:39
-
-
Save guymorita/5726564 to your computer and use it in GitHub Desktop.
ChatBuilder(working)
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="http://chatbuilder.hackreactor.com/ChatBuilder.js"></script> | |
</head> | |
<body> | |
<script> | |
/* | |
* Nice, you found the HTML source code for ChatBuilder! This document kicks everything off when you load it | |
* in your browser, and is a starting point for the whole app. It's pretty incomplete though--you should | |
* make your own version of it that works better! | |
* | |
* You can't edit the code here until it's in a file on your hard drive, so copy this whole page of source | |
* code and paste it into a plain text editor like Sublime Text 2 (http://www.sublimetext.com/). Save it as | |
* a `.html` file, and open that file with Google Chrome. You can now edit it however you like, and refresh | |
* the page to see your modifications take effect on how the application runs. | |
* | |
* Fair warning: one or more of the steps ahead could require a good amount of research to understand all | |
* the terms and technologies mentioned. Googling words you haven't heard before is a great idea. Just be | |
* careful not to spend too long in 'research mode' without making any forward progress on your real goal of | |
* completing the app! | |
* | |
* | |
* When you've got this code saved as a local file, uncomment the line of JavaScript code below and open | |
* the new file in Google Chrome. Your next instructions will be waiting for you in the JavaScript console. | |
* If you already know the Chrome JS development tools pretty well, feel free to skip this opening tutorial | |
* by calling the `.start()` function on `Chat.guide` instead of `.intro()` | |
*/ | |
Chat.guide.start(); | |
$(document).ready(function(){ | |
delete Chat.display; | |
delete Chat.send; | |
delete Chat.fetch; | |
setTimeout(function(){ | |
window.location.reload(1); | |
}, 3000); | |
var message_list = $('ul.messages') | |
var myChatFetch = function() { | |
$.get( | |
"https://api.parse.com/1/classes/chats?order=createdAt", | |
{}, | |
function(data) { | |
$.each(data.results, function(k,v) { | |
var new_list_item = '<li>' + v.text + '</li>'; | |
message_list.append(new_list_item); | |
}); | |
}); | |
}; | |
myChatFetch(); | |
$('button.send').on('click', function() { | |
$.post( | |
"https://api.parse.com/1/classes/chats", | |
JSON.stringify({text: $('input.draft').val()}), | |
function(data){ | |
window.location.reload(1) | |
}); | |
}) | |
}); | |
// var hist = Chat.fetch(function(strings) { | |
// $.each(strings, function(k,v) { | |
// var new_list_item = '<li>' + v + '</li>' | |
// message_list.append(new_list_item) | |
// }) | |
// }); | |
// $.post( | |
// "https://api.parse.com/1/classes/chats", | |
// JSON.stringify({text: "hellllooooo string"}), | |
// function(data){ | |
// console.log(data); | |
// }); | |
// $.get("https://api.parse.com/1/classes/chats?order=createdAt",{},function(data) { console.log(data)}); | |
// $.get(p,{order:"-createdAt"},function(t){var e,n;return e=t.results.length&&+new Date(t.results[0].createdAt),n=i({},ce,""+m+": "+c[Math.floor(Math.random()*c.length)]),n=i(n,de,m),+new Date-2e4*Math.random()>e&&$.post(p,JSON.stringify(n)),t.results.length>r?$.post("https://api.parse.com/1/batch",JSON.stringify({requests:$.map(t.results.slice(r).slice(-50),function(t){return{method:"DELETE",path:"/1/classes/chats/"+t.objectId}})} | |
// "https://api.parse.com/1/classes/chats" | |
// }); | |
// Chat.display(v) | |
// $.get("https://api.parse.com/1/classes/chat",{text: "Guy: Hello"},"json"); | |
// } | |
// $.get("https://chatbuilder:javascript-key=QC2F43aSAghM97XidJw8Qiy1NXlpL5LR45rhAVAf@api.parse.com/1/classes/",(Chat.display),"json"); | |
// https://chatbuilder:javascript-key=QC2F43aSAghM97XidJw8Qiy1NXlpL5LR45rhAVAf@api.parse.com/1/classes/ | |
//$.post("https://api.parse.com/1/classes", { text: "Guy: hello", username: "Guy" } ); | |
// history.length | |
//Your JavaScript code will go right here! | |
</script> | |
<h2>Fixed Chat</h2> | |
<ul class="messages"> | |
<!-- once you save this code to a local `.html()` file, you can delete these 3 fake, hard-coded li elements --> | |
</ul> | |
<input class="draft" type="text"/> <button class="send">send</button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment