Skip to content

Commit 667e26c

Browse files
committed
rename vars for clarity
1 parent fef1096 commit 667e26c

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

web_src/js/features/repo-code.js

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ function changeHash(hash) {
1616
}
1717
}
1818

19-
function selectRange($list, $select, $from) {
20-
$list.closest('tr').removeClass('active');
19+
function selectRange($linesEls, $selectionEndEl, $selectionStartEls) {
20+
$linesEls.closest('tr').removeClass('active');
2121

2222
// add hashchange to permalink
2323
const $refInNewIssue = $('a.ref-in-new-issue');
@@ -35,9 +35,7 @@ function selectRange($list, $select, $from) {
3535
};
3636

3737
const updateViewGitBlameFragment = function (anchor) {
38-
if ($viewGitBlame.length === 0) {
39-
return;
40-
}
38+
if ($viewGitBlame.length === 0) return;
4139
let href = $viewGitBlame.attr('href');
4240
href = `${href.replace(/#L\d+$|#L\d+-L\d+$/, '')}`;
4341
if (anchor.length !== 0) {
@@ -47,17 +45,15 @@ function selectRange($list, $select, $from) {
4745
};
4846

4947
const updateCopyPermalinkUrl = function(anchor) {
50-
if ($copyPermalink.length === 0) {
51-
return;
52-
}
48+
if ($copyPermalink.length === 0) return;
5349
let link = $copyPermalink.attr('data-url');
5450
link = `${link.replace(/#L\d+$|#L\d+-L\d+$/, '')}#${anchor}`;
5551
$copyPermalink.attr('data-url', link);
5652
};
5753

58-
if ($from) {
59-
let a = parseInt($select.attr('rel').slice(1));
60-
let b = parseInt($from.attr('rel').slice(1));
54+
if ($selectionStartEls) {
55+
let a = parseInt($selectionEndEl.attr('rel').slice(1));
56+
let b = parseInt($selectionStartEls.attr('rel').slice(1));
6157
let c;
6258
if (a !== b) {
6359
if (a > b) {
@@ -69,7 +65,7 @@ function selectRange($list, $select, $from) {
6965
for (let i = a; i <= b; i++) {
7066
classes.push(`[rel=L${i}]`);
7167
}
72-
$list.filter(classes.join(',')).each(function () {
68+
$linesEls.filter(classes.join(',')).each(function () {
7369
$(this).closest('tr').addClass('active');
7470
});
7571
changeHash(`#L${a}-L${b}`);
@@ -80,12 +76,12 @@ function selectRange($list, $select, $from) {
8076
return;
8177
}
8278
}
83-
$select.closest('tr').addClass('active');
84-
changeHash(`#${$select.attr('rel')}`);
79+
$selectionEndEl.closest('tr').addClass('active');
80+
changeHash(`#${$selectionEndEl.attr('rel')}`);
8581

86-
updateIssueHref($select.attr('rel'));
87-
updateViewGitBlameFragment($select.attr('rel'));
88-
updateCopyPermalinkUrl($select.attr('rel'));
82+
updateIssueHref($selectionEndEl.attr('rel'));
83+
updateViewGitBlameFragment($selectionEndEl.attr('rel'));
84+
updateCopyPermalinkUrl($selectionEndEl.attr('rel'));
8985
}
9086

9187
function showLineButton() {
@@ -158,17 +154,17 @@ export function initRepoCodeView() {
158154

159155
$(window).on('hashchange', () => {
160156
let m = window.location.hash.match(rangeAnchorRegex);
161-
let $list;
157+
let $linesEls;
162158
if ($('div.blame').length) {
163-
$list = $('.code-view td.lines-code.blame-code');
159+
$linesEls = $('.code-view td.lines-code.blame-code');
164160
} else {
165-
$list = $('.code-view td.lines-code');
161+
$linesEls = $('.code-view td.lines-code');
166162
}
167163
let $first;
168164
if (m) {
169-
$first = $list.filter(`[rel=${m[1]}]`);
165+
$first = $linesEls.filter(`[rel=${m[1]}]`);
170166
if ($first.length) {
171-
selectRange($list, $first, $list.filter(`[rel=${m[2]}]`));
167+
selectRange($linesEls, $first, $linesEls.filter(`[rel=${m[2]}]`));
172168

173169
// show code view menu marker (don't show in blame page)
174170
if ($('div.blame').length === 0) {
@@ -181,9 +177,9 @@ export function initRepoCodeView() {
181177
}
182178
m = window.location.hash.match(singleAnchorRegex);
183179
if (m) {
184-
$first = $list.filter(`[rel=L${m[2]}]`);
180+
$first = $linesEls.filter(`[rel=L${m[2]}]`);
185181
if ($first.length) {
186-
selectRange($list, $first);
182+
selectRange($linesEls, $first);
187183

188184
// show code view menu marker (don't show in blame page)
189185
if ($('div.blame').length === 0) {

0 commit comments

Comments
 (0)