@@ -13,16 +13,20 @@ import {POST, GET} from '../modules/fetch.js';
13
13
const { pageData, i18n} = window . config ;
14
14
15
15
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 ;
18
22
19
23
$ ( document ) . on ( 'click' , 'button[name="pending_review"]' , ( e ) => {
20
24
const $form = $ ( e . target ) . closest ( 'form' ) ;
21
25
// Watch for the form's submit event.
22
26
$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 ;
26
30
// Force the browser to reflow the DOM. This is to ensure that the browser replay the animation
27
31
$reviewBox . removeClass ( 'pulse' ) ;
28
32
$reviewBox . width ( ) ;
@@ -65,7 +69,7 @@ function initRepoDiffConversationForm() {
65
69
formData . append ( submitter . name , submitter . value ) ;
66
70
}
67
71
68
- const response = await POST ( $form . attr ( 'action' ) , { data : formData } ) ;
72
+ const response = await POST ( e . target . getAttribute ( 'action' ) , { data : formData } ) ;
69
73
const $newConversationHolder = $ ( await response . text ( ) ) ;
70
74
const { path, side, idx} = $newConversationHolder . data ( ) ;
71
75
@@ -118,7 +122,7 @@ export function initRepoDiffConversationNav() {
118
122
const index = $conversations . index ( $conversation ) ;
119
123
const previousIndex = index > 0 ? index - 1 : $conversations . length - 1 ;
120
124
const $previousConversation = $conversations . eq ( previousIndex ) ;
121
- const anchor = $previousConversation . find ( '.comment' ) . first ( ) . attr ( 'id' ) ;
125
+ const anchor = $previousConversation . find ( '.comment' ) . first ( ) [ 0 ] . getAttribute ( 'id' ) ;
122
126
window . location . href = `#${ anchor } ` ;
123
127
} ) ;
124
128
$ ( document ) . on ( 'click' , '.next-conversation' , ( e ) => {
@@ -127,7 +131,7 @@ export function initRepoDiffConversationNav() {
127
131
const index = $conversations . index ( $conversation ) ;
128
132
const nextIndex = index < $conversations . length - 1 ? index + 1 : 0 ;
129
133
const $nextConversation = $conversations . eq ( nextIndex ) ;
130
- const anchor = $nextConversation . find ( '.comment' ) . first ( ) . attr ( 'id' ) ;
134
+ const anchor = $nextConversation . find ( '.comment' ) . first ( ) [ 0 ] . getAttribute ( 'id' ) ;
131
135
window . location . href = `#${ anchor } ` ;
132
136
} ) ;
133
137
}
@@ -173,8 +177,7 @@ function initRepoDiffShowMore() {
173
177
$ ( document ) . on ( 'click' , 'a#diff-show-more-files' , ( e ) => {
174
178
e . preventDefault ( ) ;
175
179
176
- const $target = $ ( e . target ) ;
177
- const linkLoadMore = $target . attr ( 'data-href' ) ;
180
+ const linkLoadMore = e . target . getAttribute ( 'data-href' ) ;
178
181
loadMoreFiles ( linkLoadMore ) ;
179
182
} ) ;
180
183
0 commit comments