PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/media/js/newsblur/models/comments.js

https://github.com/samuelclay/NewsBlur
JavaScript | 48 lines | 31 code | 17 blank | 0 comment | 1 complexity | 0bc1ddb0992f471ef01f54ebb7e3208f MD5 | raw file
Possible License(s): MIT, GPL-2.0, BSD-3-Clause
  1. NEWSBLUR.Models.Comment = Backbone.Model.extend({
  2. urlRoot: '/social/comment',
  3. initialize: function() {
  4. this.bind('change:replies', this.changes_replies);
  5. this.bind('change:comments', this.strip_html_in_comments);
  6. this.changes_replies();
  7. },
  8. changes_replies: function() {
  9. if (this.get('replies')) {
  10. this.replies = new NEWSBLUR.Collections.CommentReplies(this.get('replies'));
  11. }
  12. },
  13. strip_html_in_comments: function() {
  14. this.attributes['comments'] = this.strip_html(this.get('comments'));
  15. },
  16. strip_html: function(html) {
  17. return html.replace(/<\/?[^>]+(>|$)/g, "");
  18. }
  19. });
  20. NEWSBLUR.Collections.Comments = Backbone.Collection.extend({
  21. url: '/social/comments',
  22. model: NEWSBLUR.Models.Comment
  23. });
  24. NEWSBLUR.Models.CommentReply = Backbone.Model.extend({
  25. stripped_comments: function() {
  26. return NEWSBLUR.Models.Comment.prototype.strip_html(this.get('comments'));
  27. }
  28. });
  29. NEWSBLUR.Collections.CommentReplies = Backbone.Collection.extend({
  30. model: NEWSBLUR.Models.CommentReply
  31. });