|
148 | 148 | view.appendTo( this.$( "ul.comments" ) ); |
149 | 149 | }, |
150 | 150 | showAddCommentDialog: function() { |
151 | | - var $parentRow = $( this.el ).prev()[0], |
152 | | - $th = ( $( 'th', $parentRow ).length) ? $( 'th', $parentRow ) : $parentRow, |
153 | | - $item = $th.last(), |
154 | | - file = $item.parents( 'li' ).find( 'h2>a:first' ).text(), |
155 | | - line = $.inArray( $parentRow, CodeComments.$tableRows ) + 1, |
156 | | - displayLine = $item.text().trim() || $th.first().text() + ' (deleted)'; |
157 | | - |
158 | | - AddCommentDialog.open( LineComments, this.line, file, displayLine ); |
| 151 | + row = new RowView( { el: $( this.el ).prev().get( 0 ) } ); |
| 152 | + AddCommentDialog.open( LineComments, this.line, row.getFile(), row.getDisplayLine() ); |
159 | 153 | } |
160 | 154 | }); |
161 | 155 |
|
|
224 | 218 | window.LineCommentBubblesView = Backbone.View.extend({ |
225 | 219 | render: function() { |
226 | 220 | var callbackMouseover = function( event ) { |
227 | | - var $th = ( $( 'th', this ).length) ? $( 'th', this ) : $( this ), |
228 | | - $item = $th.last(), |
229 | | - file = $item.parents( 'li' ).find( 'h2>a:first' ).text(), |
230 | | - line = $.inArray( this, CodeComments.$tableRows ) + 1, |
231 | | - displayLine = $item.text().trim() || $th.first().text() + ' (deleted)'; |
232 | | - |
233 | | - $item.children().css( 'display', 'none' ); |
234 | | - |
235 | | - $item.prepend( '<a title="Comment on this line" href="#L' + line + '" class="bubble"><span class="ui-icon ui-icon-comment"></span></a>' ); |
| 221 | + var row = new RowView( { el: this } ), |
| 222 | + file = row.getFile(), |
| 223 | + line = row.getLineNumber(), |
| 224 | + displayLine = row.getDisplayLine(); |
| 225 | + row.replaceLineNumberCellContent( '<a title="Comment on this line" href="#L' + line + '" class="bubble"><span class="ui-icon ui-icon-comment"></span></a>' ); |
236 | 226 |
|
237 | 227 | $( 'a.bubble' ).click( function( e ) { |
238 | 228 | e.preventDefault(); |
|
241 | 231 | }; |
242 | 232 |
|
243 | 233 | var callbackMouseout = function( event ) { |
244 | | - var $th = $( 'th', this ).length ? $( 'th', this ) : $( this ); |
245 | | - $( 'a.bubble', $th ).remove(); |
246 | | - $th.children().css( 'display', '' ); |
| 234 | + var tr = $( 'th', this ).length? this : $( this ).parent().get( 0 ), |
| 235 | + row = new RowView( { el: tr } ); |
| 236 | + $( 'a.bubble', tr ).remove(); |
| 237 | + row.bringBackOriginalLineNumberCellContent(); |
247 | 238 | }; |
248 | 239 |
|
249 | 240 | Rows.hover( callbackMouseover, callbackMouseout ); |
|
278 | 269 | } |
279 | 270 | } ); |
280 | 271 |
|
| 272 | + window.RowView = Backbone.View.extend( { |
| 273 | + initialize: function( atts ) { |
| 274 | + this.$th = this.$( 'th' ); |
| 275 | + this.$lineNumberCell = this.$th.last(); |
| 276 | + this.$el = $( this.el ); |
| 277 | + }, |
| 278 | + replaceLineNumberCellContent: function( html ) { |
| 279 | + this.$lineNumberCell.children().css( 'display', 'none' ); |
| 280 | + this.$lineNumberCell.prepend( html ); |
| 281 | + }, |
| 282 | + bringBackOriginalLineNumberCellContent: function() { |
| 283 | + this.$lineNumberCell.children().css( 'display', '' ); |
| 284 | + }, |
| 285 | + getFile: function() { |
| 286 | + return this.$el.parents( 'li' ).find( 'h2>a:first' ).text(); |
| 287 | + }, |
| 288 | + getLineNumber: function() { |
| 289 | + return Rows.getLineByTR( this.el ); |
| 290 | + }, |
| 291 | + getDisplayLine: function() { |
| 292 | + return this.$lineNumberCell.text().trim() || this.$th.first().text() + ' (deleted)'; |
| 293 | + } |
| 294 | + } ); |
| 295 | + |
281 | 296 | window.TopComments = new CommentsList(); |
282 | 297 | window.LineComments = new CommentsList(); |
283 | 298 | window.TopCommentsBlock = new TopCommentsView(); |
|
0 commit comments