var CommentsView = FormView.extend({ el: "#comments", events: { "focus textarea": "focus", "blur textarea": "blur", }, initialize: function(){ this.__super__.initialize.call(this) this.template = this.$(".template").html() }, load: function(comments){ comments.forEach(this.appendComment.bind(this)) }, parse: function(comment){ if (! comment.comment.length) return "" var datetime = verbose_date(comment.date, true) var t = this.template.replace(/{{username}}/g, comment.username) .replace(/{{comment}}/g, tidy_urls(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) }, focus: function(){ app.typing = true }, blur: function(){ app.typing = false }, })