forked from pedrofranceschi/Blogode
/
show.html
55 lines (44 loc) · 1.41 KB
/
show.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script>
$(document).ready(function() {
$("#submit").click(function() {
$.ajax({
type: "POST",
url: "/<%= post.id %>/comments/save",
data: { author_name: $("input#author_name").val(), author_email: $("input#author_email").val(), comment: $("textarea#comment").val() },
success: function() {
}
});
return false;
});
});
var client = new Faye.Client('/faye', {
timeout: 120
});
client.subscribe('/<%= post.id %>/comments/bayeux', function(response) {
$("#comments_list").append("<div id=\"comment_" + response.id + "\"> " +
" <h4>" + unescape(response.author_name) + "</h4> " +
" <p>" + unescape(response.comment) + "</p> " +
"</div>");
});
</script>
<h1><%= unescape(post.title) %></h1>
<p>by <%= post.user_name %></p>
<p><%- unescape(post.body) %></p>
<br/>
<h2>Comments</h2>
<div id="comments_list">
<% for (var i=0; i < comments.length; i++) { %>
<div id="comment_<%= i %>">
<h4><%= unescape(comments[i].author_name) %></h4>
<p><%= unescape(comments[i].comment) %></p>
</div>
<% } %>
</div>
<br/>
<h2>New comment</h2>
<form>
<input type="text" id="author_name" placeholder="Your name" size="41"/><br/>
<input type="text" id="author_email" placeholder="Your e-mail" size="41"/><br/><br/>
<textarea id="comment" cols="30" rows="5" placeholder="Your comment"></textarea><br/><br/>
<input type="submit" id="submit"/>
</form>