blob: 164a3b1a8630d4ce00a50b4ab8754f76c6c1d5b0 (
plain)
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
|
var CommentsView = FormView.extend({
el: "#comments",
events: {
},
initialize: function(){
this.__super__.initialize.call(this)
this.template = this.$(".template").html()
},
load: function(comments){
comments.forEach(this.appendComment.bind(this))
},
parse: function(comment){
var datetime = verbose_date(comment.date)
var t = this.template.replace(/{{username}}/g, comment.username)
.replace(/{{comment}}/g, comment.comment)
.replace(/{{date}}/g, datetime[0])
.replace(/{{time}}/g, datetime[1])
return t
},
prependComment: function(comment){
var $el = $( this.parse(comment) )
this.$el.prepend($el)
},
appendComment: function(comment){
var $el = $( this.parse(comment) )
this.$el.append($el)
},
success: function(){
this.prependComment(comment)
}
})
|