@@ -7,7 +7,7 @@ import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.js';
7
7
import { initViewedCheckboxListenerFor , countAndUpdateViewedFiles , initExpandAndCollapseFilesButton } from './pull-view-file.js' ;
8
8
import { initImageDiff } from './imagediff.js' ;
9
9
import { showErrorToast } from '../modules/toast.js' ;
10
- import { submitEventSubmitter } from '../utils/dom.js' ;
10
+ import { submitEventSubmitter , queryElemSiblings , hideElem , showElem } from '../utils/dom.js' ;
11
11
import { POST , GET } from '../modules/fetch.js' ;
12
12
13
13
const { pageData, i18n} = window . config ;
@@ -16,7 +16,6 @@ function initRepoDiffReviewButton() {
16
16
const reviewBox = document . getElementById ( 'review-box' ) ;
17
17
if ( ! reviewBox ) return ;
18
18
19
- const $reviewBox = $ ( reviewBox ) ;
20
19
const counter = reviewBox . querySelector ( '.review-comments-counter' ) ;
21
20
if ( ! counter ) return ;
22
21
@@ -27,23 +26,27 @@ function initRepoDiffReviewButton() {
27
26
const num = parseInt ( counter . getAttribute ( 'data-pending-comment-number' ) ) + 1 || 1 ;
28
27
counter . setAttribute ( 'data-pending-comment-number' , num ) ;
29
28
counter . textContent = num ;
30
- // Force the browser to reflow the DOM. This is to ensure that the browser replay the animation
31
- $reviewBox . removeClass ( 'pulse' ) ;
32
- $reviewBox . width ( ) ;
33
- $reviewBox . addClass ( 'pulse' ) ;
29
+
30
+ reviewBox . classList . remove ( 'pulse' ) ;
31
+ requestAnimationFrame ( ( ) => {
32
+ reviewBox . classList . add ( 'pulse' ) ;
33
+ } ) ;
34
34
} ) ;
35
35
} ) ;
36
36
}
37
37
38
38
function initRepoDiffFileViewToggle ( ) {
39
39
$ ( '.file-view-toggle' ) . on ( 'click' , function ( ) {
40
- const $this = $ ( this ) ;
41
- $this . parent ( ) . children ( ) . removeClass ( 'active' ) ;
42
- $this . addClass ( 'active' ) ;
40
+ for ( const el of queryElemSiblings ( this ) ) {
41
+ el . classList . remove ( 'active' ) ;
42
+ }
43
+ this . classList . add ( 'active' ) ;
43
44
44
- const $target = $ ( $this . data ( 'toggle-selector' ) ) ;
45
- $target . parent ( ) . children ( ) . addClass ( 'tw-hidden' ) ;
46
- $target . removeClass ( 'tw-hidden' ) ;
45
+ const target = document . querySelector ( this . getAttribute ( 'data-toggle-selector' ) ) ;
46
+ if ( ! target ) return ;
47
+
48
+ hideElem ( queryElemSiblings ( target ) ) ;
49
+ showElem ( target ) ;
47
50
} ) ;
48
51
}
49
52
@@ -57,9 +60,9 @@ function initRepoDiffConversationForm() {
57
60
return ;
58
61
}
59
62
60
- if ( $form . hasClass ( 'is-loading' ) ) return ;
63
+ if ( e . target . classList . contains ( 'is-loading' ) ) return ;
61
64
try {
62
- $form . addClass ( 'is-loading' ) ;
65
+ e . target . classList . add ( 'is-loading' ) ;
63
66
const formData = new FormData ( $form [ 0 ] ) ;
64
67
65
68
// if the form is submitted by a button, append the button's name and value to the form data
@@ -74,18 +77,22 @@ function initRepoDiffConversationForm() {
74
77
const { path, side, idx} = $newConversationHolder . data ( ) ;
75
78
76
79
$form . closest ( '.conversation-holder' ) . replaceWith ( $newConversationHolder ) ;
80
+ let selector ;
77
81
if ( $form . closest ( 'tr' ) . data ( 'line-type' ) === 'same' ) {
78
- $ ( `[data-path="${ path } "] .add-code-comment[data-idx="${ idx } "]` ) . addClass ( 'tw-invisible' ) ;
82
+ selector = `[data-path="${ path } "] .add-code-comment[data-idx="${ idx } "]` ;
79
83
} else {
80
- $ ( `[data-path="${ path } "] .add-code-comment[data-side="${ side } "][data-idx="${ idx } "]` ) . addClass ( 'tw-invisible' ) ;
84
+ selector = `[data-path="${ path } "] .add-code-comment[data-side="${ side } "][data-idx="${ idx } "]` ;
85
+ }
86
+ for ( const el of document . querySelectorAll ( selector ) ) {
87
+ el . classList . add ( 'tw-invisible' ) ;
81
88
}
82
89
$newConversationHolder . find ( '.dropdown' ) . dropdown ( ) ;
83
90
initCompReactionSelector ( $newConversationHolder ) ;
84
91
} catch ( error ) {
85
92
console . error ( 'Error:' , error ) ;
86
93
showErrorToast ( i18n . network_error ) ;
87
94
} finally {
88
- $form . removeClass ( 'is-loading' ) ;
95
+ e . target . classList . remove ( 'is-loading' ) ;
89
96
}
90
97
} ) ;
91
98
@@ -145,13 +152,13 @@ function onShowMoreFiles() {
145
152
}
146
153
147
154
export async function loadMoreFiles ( url ) {
148
- const $ target = $ ( 'a#diff-show-more-files' ) ;
149
- if ( $ target. hasClass ( 'disabled' ) || pageData . diffFileInfo . isLoadingNewData ) {
155
+ const target = document . querySelector ( 'a#diff-show-more-files' ) ;
156
+ if ( target ?. classList . contains ( 'disabled' ) || pageData . diffFileInfo . isLoadingNewData ) {
150
157
return ;
151
158
}
152
159
153
160
pageData . diffFileInfo . isLoadingNewData = true ;
154
- $ target. addClass ( 'disabled' ) ;
161
+ target ?. classList . add ( 'disabled' ) ;
155
162
156
163
try {
157
164
const response = await GET ( url ) ;
@@ -168,7 +175,7 @@ export async function loadMoreFiles(url) {
168
175
console . error ( 'Error:' , error ) ;
169
176
showErrorToast ( 'An error occurred while loading more files.' ) ;
170
177
} finally {
171
- $ target. removeClass ( 'disabled' ) ;
178
+ target ?. classList . remove ( 'disabled' ) ;
172
179
pageData . diffFileInfo . isLoadingNewData = false ;
173
180
}
174
181
}
@@ -185,11 +192,11 @@ function initRepoDiffShowMore() {
185
192
e . preventDefault ( ) ;
186
193
const $target = $ ( e . target ) ;
187
194
188
- if ( $ target. hasClass ( 'disabled' ) ) {
195
+ if ( e . target . classList . contains ( 'disabled' ) ) {
189
196
return ;
190
197
}
191
198
192
- $ target. addClass ( 'disabled' ) ;
199
+ e . target . classList . add ( 'disabled' ) ;
193
200
194
201
const url = $target . data ( 'href' ) ;
195
202
@@ -205,7 +212,7 @@ function initRepoDiffShowMore() {
205
212
} catch ( error ) {
206
213
console . error ( 'Error:' , error ) ;
207
214
} finally {
208
- $ target. removeClass ( 'disabled' ) ;
215
+ e . target . classList . remove ( 'disabled' ) ;
209
216
}
210
217
} ) ;
211
218
}
0 commit comments