summaryrefslogtreecommitdiff
path: root/public/assets/js/lib/views/index/hootbox.js
blob: 9d1cc3d92cd87dca924b5beff266435db7f0045b (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
var HootBox = FormView.extend({
  
  el: "#hootbox",
  
  events: {
  },
  
  initialize: function(){
    this.__super__.initialize.call(this)
    this.template = this.$(".template").html()
    this.$hoots = this.$("#hoots")
  },
  
  load: function(comments){
    comments.forEach(this.appendComment.bind(this))
  },
  
  parse: function(comment){
    var t = this.template.replace(/{{username}}/g, comment.username)
                         .replace(/{{comment}}/g, tidy_urls(comment.comment, true))
    return t
  },
  
  prependComment: function(comment){
    var $el = $( this.parse(comment) )
    this.$hoots.prepend($el)
  },

  appendComment: function(comment){
    var $el = $( this.parse(comment) )
    this.$hoots.append($el)
  },
  
  success: function(){
    this.prependComment(comment)
  }
})