Created
May 19, 2014 08:40
-
-
Save sota1235/754a64e16640a10cc4f2 to your computer and use it in GitHub Desktop.
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
| ajax = new Ajax("/comments") | |
| insert_json = (data) -> | |
| lines = $.parseJSON(data).line.reverse() | |
| $("div#comments").html "" | |
| i = 0 | |
| while i < ((if lines.length < 10 then lines.length else 10)) | |
| main = $("<div>", | |
| class: "data" | |
| ) | |
| $("<span>", | |
| class: "date" | |
| ).text(lines[i]["date"]).appendTo main | |
| $("<div>", | |
| class: "comment" | |
| ).text(lines[i]["name"] + " : " + lines[i]["comment"]).appendTo main | |
| $("div#comments").append main | |
| i++ | |
| ajax.on_get = insert_json | |
| post = -> | |
| name = $("#chat #name").val() | |
| comment = $("#chat #comment").val() | |
| if comment.length < 1 | |
| alert "無言はなしよ" | |
| return | |
| ajax.post | |
| name: name | |
| comment: comment | |
| $("input,text").not("input[type=\"button\"],input[id=\"name\"]").val "" | |
| false | |
| $ -> | |
| json = "" | |
| ajax.start() | |
| $.get "/first_comments", (data) -> | |
| insert_json data | |
| $("#chat #send").click post | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment