Skip to content

Commit 74c1378

Browse files
Remove jQuery .attr from the diff page (#30021)
- Switched from jQuery `.attr` to plain javascript `getAttribute` and `setAttribute` - Tested the review box counter and Previous/Next code review conversation buttons. They work as before --------- Signed-off-by: Yarden Shoham <[email protected]> Co-authored-by: silverwind <[email protected]>
1 parent 26dbca7 commit 74c1378

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

web_src/js/features/repo-diff.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,20 @@ import {POST, GET} from '../modules/fetch.js';
1313
const {pageData, i18n} = window.config;
1414

1515
function initRepoDiffReviewButton() {
16-
const $reviewBox = $('#review-box');
17-
const $counter = $reviewBox.find('.review-comments-counter');
16+
const reviewBox = document.getElementById('review-box');
17+
if (!reviewBox) return;
18+
19+
const $reviewBox = $(reviewBox);
20+
const counter = reviewBox.querySelector('.review-comments-counter');
21+
if (!counter) return;
1822

1923
$(document).on('click', 'button[name="pending_review"]', (e) => {
2024
const $form = $(e.target).closest('form');
2125
// Watch for the form's submit event.
2226
$form.on('submit', () => {
23-
const num = parseInt($counter.attr('data-pending-comment-number')) + 1 || 1;
24-
$counter.attr('data-pending-comment-number', num);
25-
$counter.text(num);
27+
const num = parseInt(counter.getAttribute('data-pending-comment-number')) + 1 || 1;
28+
counter.setAttribute('data-pending-comment-number', num);
29+
counter.textContent = num;
2630
// Force the browser to reflow the DOM. This is to ensure that the browser replay the animation
2731
$reviewBox.removeClass('pulse');
2832
$reviewBox.width();
@@ -65,7 +69,7 @@ function initRepoDiffConversationForm() {
6569
formData.append(submitter.name, submitter.value);
6670
}
6771

68-
const response = await POST($form.attr('action'), {data: formData});
72+
const response = await POST(e.target.getAttribute('action'), {data: formData});
6973
const $newConversationHolder = $(await response.text());
7074
const {path, side, idx} = $newConversationHolder.data();
7175

@@ -118,7 +122,7 @@ export function initRepoDiffConversationNav() {
118122
const index = $conversations.index($conversation);
119123
const previousIndex = index > 0 ? index - 1 : $conversations.length - 1;
120124
const $previousConversation = $conversations.eq(previousIndex);
121-
const anchor = $previousConversation.find('.comment').first().attr('id');
125+
const anchor = $previousConversation.find('.comment').first()[0].getAttribute('id');
122126
window.location.href = `#${anchor}`;
123127
});
124128
$(document).on('click', '.next-conversation', (e) => {
@@ -127,7 +131,7 @@ export function initRepoDiffConversationNav() {
127131
const index = $conversations.index($conversation);
128132
const nextIndex = index < $conversations.length - 1 ? index + 1 : 0;
129133
const $nextConversation = $conversations.eq(nextIndex);
130-
const anchor = $nextConversation.find('.comment').first().attr('id');
134+
const anchor = $nextConversation.find('.comment').first()[0].getAttribute('id');
131135
window.location.href = `#${anchor}`;
132136
});
133137
}
@@ -173,8 +177,7 @@ function initRepoDiffShowMore() {
173177
$(document).on('click', 'a#diff-show-more-files', (e) => {
174178
e.preventDefault();
175179

176-
const $target = $(e.target);
177-
const linkLoadMore = $target.attr('data-href');
180+
const linkLoadMore = e.target.getAttribute('data-href');
178181
loadMoreFiles(linkLoadMore);
179182
});
180183

0 commit comments

Comments
 (0)