Skip to content

Commit ae67243

Browse files
committed
Add RowsView
It represents all the rows with code on the page. Since we have few operations over rows, it sounds logical to extract them in a separate view. The main element is all the tables.
1 parent 9b9830d commit ae67243

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

code_comments/htdocs/code-comments.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,34 @@
260260
}
261261
});
262262

263+
window.RowsView = Backbone.View.extend( {
264+
initialize: function( atts ) {
265+
this.$el = $( this.el );
266+
this.$rows = $( 'tr', atts.tableSelector );
267+
},
268+
render: function() {
269+
// wrap TH content in spans so we can hide/show them
270+
this.wrapTHsInSpans();
271+
},
272+
getLineByTR: function( tr ) {
273+
return $.inArray( tr, this.$rows ) + 1;
274+
},
275+
getTrByLineNumber: function( line ) {
276+
return this.$rows[line - 1];
277+
},
278+
wrapTHsInSpans: function() {
279+
$( 'th', this.$rows ).each( function( i, elem ) {
280+
elem.innerHTML = '<span>' + elem.innerHTML + '</span>';
281+
});
282+
},
283+
hover: function( enter, leave ) {
284+
return this.$rows.hover( enter, leave );
285+
},
286+
getNumberOfTHsPerRow: function() {
287+
return this.$rows.eq( 0 ).find( 'th' ).length;
288+
}
289+
} );
290+
263291
window.TopComments = new CommentsList();
264292
window.LineComments = new CommentsList();
265293
window.TopCommentsBlock = new TopCommentsView();

0 commit comments

Comments
 (0)