diff options
Diffstat (limited to 'public/assets/js/lib/views/index/hootbox.js')
| -rw-r--r-- | public/assets/js/lib/views/index/hootbox.js | 91 |
1 files changed, 49 insertions, 42 deletions
diff --git a/public/assets/js/lib/views/index/hootbox.js b/public/assets/js/lib/views/index/hootbox.js index 72fbfde..a5d2270 100644 --- a/public/assets/js/lib/views/index/hootbox.js +++ b/public/assets/js/lib/views/index/hootbox.js @@ -1,56 +1,63 @@ var HootBox = FormView.extend({ - el: "#hootbox", - - events: { - }, - + + events: {}, + action: "/api/thread/1/comment", - - initialize: function(){ - this.__super__.initialize.call(this) - this.template = this.$(".template").html() - this.$hoots = this.$("#hoots") - this.$comment = this.$("[name=comment]") + + initialize: function () { + this.__super__.initialize.call(this); + this.template = this.$(".template").html(); + this.$hoots = this.$("#hoots"); + this.$comment = this.$("[name=comment]"); + }, + + show: function () { + this.$el.show(); }, - - load: function(comments){ - if (!comments || !comments.length && ! this.options.required) { - this.$el.hide() - return + + hide: function () { + this.$el.hide(); + }, + + load: function (comments) { + if (!comments || (!comments.length && !this.options.required)) { + this.$el.hide(); + return; } - comments.forEach(this.appendComment.bind(this)) + comments.forEach(this.appendComment.bind(this)); }, - - parse: function(comment){ - var t = this.template.replace(/{{image}}/g, profile_image(comment.username)) - .replace(/{{username}}/g, comment.username) - .replace(/{{comment}}/g, tidy_urls(comment.comment, true)) - var $t = $(t) - return $t + + parse: function (comment) { + var t = this.template + .replace(/{{image}}/g, profile_image(comment.username)) + .replace(/{{username}}/g, comment.username) + .replace(/{{comment}}/g, tidy_urls(comment.comment, true)); + var $t = $(t); + return $t; }, - - prependComment: function(comment){ - var $el = this.parse(comment) - this.$hoots.prepend($el) + + prependComment: function (comment) { + var $el = this.parse(comment); + this.$hoots.prepend($el); }, - appendComment: function(comment){ - var $el = this.parse(comment) - this.$hoots.append($el) + appendComment: function (comment) { + var $el = this.parse(comment); + this.$hoots.append($el); }, - validate: function(){ - var errors = [] - var comment = $("[name=comment]").val() - if (! comment || ! comment.length) { - errors.push("Please enter a comment.") + validate: function () { + var errors = []; + var comment = $("[name=comment]").val(); + if (!comment || !comment.length) { + errors.push("Please enter a comment."); } - return errors.length ? errors : null + return errors.length ? errors : null; }, - success: function(data){ - this.prependComment(data.comment) - this.$("[name=comment]").val("") - } -})
\ No newline at end of file + success: function (data) { + this.prependComment(data.comment); + this.$("[name=comment]").val(""); + }, +}); |
