|
46 | 46 | template: _.template(CodeComments.templates.comment), |
47 | 47 | initialize: function() { |
48 | 48 | this.model.bind('change', this.render, this); |
| 49 | + this.is_active = this.model.id == CodeComments.active_comment_id; |
49 | 50 | }, |
50 | 51 | render: function() { |
51 | 52 | $(this.el).html(this.template(_.extend(this.model.toJSON(), { |
52 | 53 | delete_url: CodeComments.delete_url, |
53 | | - active: this.model.id == CodeComments.active_comment_id, |
| 54 | + active: this.is_active, |
54 | 55 | can_delete: CodeComments.is_admin |
55 | 56 | }))); |
56 | 57 | return this; |
| 58 | + }, |
| 59 | + appendTo: function($el) { |
| 60 | + $el.append( this.render().el ); |
| 61 | + if ( this.is_active ) { |
| 62 | + var comment_offset = $(this.el).offset(); |
| 63 | + window.scrollTo( comment_offset.left, comment_offset.top ); |
| 64 | + } |
57 | 65 | } |
58 | 66 | }); |
59 | 67 |
|
|
79 | 87 |
|
80 | 88 | addOne: function(comment) { |
81 | 89 | var view = new CommentView({model: comment}); |
82 | | - this.$("ul.comments").append(view.render().el); |
| 90 | + view.appendTo( $( "ul.comments" ) ); |
83 | 91 | }, |
84 | 92 | addAll: function() { |
85 | 93 | var view = this; |
|
101 | 109 | this.viewPerLine = {}; |
102 | 110 | }, |
103 | 111 | render: function() { |
104 | | - LineComments.fetchComments( 'line' ).complete( function() { |
105 | | - window.setTimeout( function() { |
106 | | - var anchor_id = '#comment-' + CodeComments.active_comment_id; |
107 | | - if ( '' != anchor_id && $( anchor_id ).offset() ) { |
108 | | - var new_position = $( anchor_id ).offset(); |
109 | | - window.scrollTo( new_position.left, new_position.top ); |
110 | | - } |
111 | | - }, 30 ); // slight pause allows DOM updates to complete |
112 | | - } ); |
| 112 | + LineComments.fetchComments( 'line' ); |
113 | 113 | }, |
114 | 114 | addOne: function(comment) { |
115 | 115 | var line = comment.get('line'); |
|
149 | 149 | addOne: function(comment) { |
150 | 150 | var view = new CommentView({model: comment}); |
151 | 151 | this.line = comment.get('line'); |
152 | | - this.$("ul.comments").append(view.render().el); |
| 152 | + view.appendTo( $( "ul.comments" ) ); |
153 | 153 | }, |
154 | 154 | showAddCommentDialog: function() { |
155 | 155 | var $parentRow = $( this.el ).prev()[0], |
|
0 commit comments