@@ -16,6 +16,14 @@ function changeHash(hash) {
16
16
}
17
17
}
18
18
19
+ function isBlame ( ) {
20
+ return Boolean ( document . querySelector ( 'div.blame' ) ) ;
21
+ }
22
+
23
+ function getLineEls ( ) {
24
+ return document . querySelectorAll ( `.code-view td.lines-code${ isBlame ( ) ? '.blame-code' : '' } ` ) ;
25
+ }
26
+
19
27
function selectRange ( $linesEls , $selectionEndEl , $selectionStartEls ) {
20
28
$linesEls . closest ( 'tr' ) . removeClass ( 'active' ) ;
21
29
@@ -25,7 +33,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) {
25
33
const $viewGitBlame = $ ( 'a.view_git_blame' ) ;
26
34
27
35
const updateIssueHref = function ( anchor ) {
28
- if ( $refInNewIssue . length === 0 ) {
36
+ if ( ! $refInNewIssue . length ) {
29
37
return ;
30
38
}
31
39
const urlIssueNew = $refInNewIssue . attr ( 'data-url-issue-new' ) ;
@@ -35,7 +43,7 @@ function selectRange($linesEls, $selectionEndEl, $selectionStartEls) {
35
43
} ;
36
44
37
45
const updateViewGitBlameFragment = function ( anchor ) {
38
- if ( $viewGitBlame . length === 0 ) return ;
46
+ if ( ! $viewGitBlame . length ) return ;
39
47
let href = $viewGitBlame . attr ( 'href' ) ;
40
48
href = `${ href . replace ( / # L \d + $ | # L \d + - L \d + $ / , '' ) } ` ;
41
49
if ( anchor . length !== 0 ) {
@@ -121,13 +129,7 @@ function showLineButton() {
121
129
export function initRepoCodeView ( ) {
122
130
if ( $ ( '.code-view .lines-num' ) . length > 0 ) {
123
131
$ ( document ) . on ( 'click' , '.lines-num span' , function ( e ) {
124
- let linesEls ;
125
- if ( document . querySelector ( 'div.blame' ) ) {
126
- linesEls = document . querySelectorAll ( '.code-view td.lines-code.blame-code' ) ;
127
- } else {
128
- linesEls = document . querySelectorAll ( '.code-view td.lines-code' ) ;
129
- }
130
-
132
+ const linesEls = getLineEls ( ) ;
131
133
const selectedEls = Array . from ( linesEls ) . filter ( ( el ) => {
132
134
return el . matches ( `[rel=${ this . getAttribute ( 'id' ) } ]` ) ;
133
135
} ) ;
@@ -147,27 +149,22 @@ export function initRepoCodeView() {
147
149
}
148
150
149
151
// show code view menu marker (don't show in blame page)
150
- if ( $ ( 'div.blame' ) . length === 0 ) {
152
+ if ( ! isBlame ( ) ) {
151
153
showLineButton ( ) ;
152
154
}
153
155
} ) ;
154
156
155
157
$ ( window ) . on ( 'hashchange' , ( ) => {
156
158
let m = window . location . hash . match ( rangeAnchorRegex ) ;
157
- let $linesEls ;
158
- if ( $ ( 'div.blame' ) . length ) {
159
- $linesEls = $ ( '.code-view td.lines-code.blame-code' ) ;
160
- } else {
161
- $linesEls = $ ( '.code-view td.lines-code' ) ;
162
- }
159
+ const $linesEls = $ ( getLineEls ( ) ) ;
163
160
let $first ;
164
161
if ( m ) {
165
162
$first = $linesEls . filter ( `[rel=${ m [ 1 ] } ]` ) ;
166
163
if ( $first . length ) {
167
164
selectRange ( $linesEls , $first , $linesEls . filter ( `[rel=${ m [ 2 ] } ]` ) ) ;
168
165
169
166
// show code view menu marker (don't show in blame page)
170
- if ( $ ( 'div.blame' ) . length === 0 ) {
167
+ if ( ! isBlame ( ) ) {
171
168
showLineButton ( ) ;
172
169
}
173
170
@@ -182,7 +179,7 @@ export function initRepoCodeView() {
182
179
selectRange ( $linesEls , $first ) ;
183
180
184
181
// show code view menu marker (don't show in blame page)
185
- if ( $ ( 'div.blame' ) . length === 0 ) {
182
+ if ( ! isBlame ( ) ) {
186
183
showLineButton ( ) ;
187
184
}
188
185
0 commit comments