@@ -61,7 +61,7 @@ function initRepoIssueLabelFilter(elDropdown: Element) {
61
61
selectedLabelIds . add ( `${ Math . abs ( parseInt ( id ) ) } ` ) ; // "labels" contains negative ids, which are excluded
62
62
}
63
63
64
- const excludeLabel = ( e : MouseEvent | KeyboardEvent , item : Element ) => {
64
+ const excludeLabel = ( e : MouseEvent | KeyboardEvent , item : Element ) => {
65
65
e . preventDefault ( ) ;
66
66
e . stopPropagation ( ) ;
67
67
const labelId = item . getAttribute ( 'data-label-id' ) ;
@@ -124,7 +124,7 @@ export function initRepoIssueFilterItemLabel() {
124
124
125
125
export function initRepoIssueCommentDelete ( ) {
126
126
// Delete comment
127
- document . addEventListener ( 'click' , async ( e : MouseEvent & { target : HTMLElement } ) => {
127
+ document . addEventListener ( 'click' , async ( e : MouseEvent & { target : HTMLElement } ) => {
128
128
if ( ! e . target . matches ( '.delete-comment' ) ) return ;
129
129
e . preventDefault ( ) ;
130
130
@@ -199,7 +199,7 @@ export function initRepoIssueDependencyDelete() {
199
199
200
200
export function initRepoIssueCodeCommentCancel ( ) {
201
201
// Cancel inline code comment
202
- document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
202
+ document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
203
203
if ( ! e . target . matches ( '.cancel-code-comment' ) ) return ;
204
204
205
205
const form = e . target . closest ( 'form' ) ;
@@ -217,7 +217,7 @@ export function initRepoPullRequestUpdate() {
217
217
const pullUpdateButton = document . querySelector ( '.update-button > button' ) ;
218
218
if ( ! pullUpdateButton ) return ;
219
219
220
- pullUpdateButton . addEventListener ( 'click' , async function ( e ) {
220
+ pullUpdateButton . addEventListener ( 'click' , async function ( e ) {
221
221
e . preventDefault ( ) ;
222
222
const redirect = this . getAttribute ( 'data-redirect' ) ;
223
223
this . classList . add ( 'is-loading' ) ;
@@ -273,9 +273,11 @@ export function initRepoPullRequestAllowMaintainerEdit() {
273
273
const url = `${ wrapper . getAttribute ( 'data-url' ) } /set_allow_maintainer_edit` ;
274
274
wrapper . classList . add ( 'is-loading' ) ;
275
275
try {
276
- const resp = await POST ( url , { data : new URLSearchParams ( {
277
- allow_maintainer_edit : String ( checkbox . checked ) ,
278
- } ) } ) ;
276
+ const resp = await POST ( url , {
277
+ data : new URLSearchParams ( {
278
+ allow_maintainer_edit : String ( checkbox . checked ) ,
279
+ } ) ,
280
+ } ) ;
279
281
if ( ! resp . ok ) {
280
282
throw new Error ( 'Failed to update maintainer edit permission' ) ;
281
283
}
@@ -340,7 +342,7 @@ export function initRepoIssueWipTitle() {
340
342
export function initRepoIssueComments ( ) {
341
343
if ( ! $ ( '.repository.view.issue .timeline' ) . length ) return ;
342
344
343
- document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
345
+ document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
344
346
const urlTarget = document . querySelector ( ':target' ) ;
345
347
if ( ! urlTarget ) return ;
346
348
@@ -406,7 +408,7 @@ export function initRepoPullRequestReview() {
406
408
}
407
409
}
408
410
409
- $ ( document ) . on ( 'click' , '.show-outdated' , function ( e ) {
411
+ $ ( document ) . on ( 'click' , '.show-outdated' , function ( e ) {
410
412
e . preventDefault ( ) ;
411
413
const id = this . getAttribute ( 'data-comment' ) ;
412
414
hideElem ( this ) ;
@@ -415,7 +417,7 @@ export function initRepoPullRequestReview() {
415
417
showElem ( `#hide-outdated-${ id } ` ) ;
416
418
} ) ;
417
419
418
- $ ( document ) . on ( 'click' , '.hide-outdated' , function ( e ) {
420
+ $ ( document ) . on ( 'click' , '.hide-outdated' , function ( e ) {
419
421
e . preventDefault ( ) ;
420
422
const id = this . getAttribute ( 'data-comment' ) ;
421
423
hideElem ( this ) ;
@@ -424,7 +426,7 @@ export function initRepoPullRequestReview() {
424
426
showElem ( `#show-outdated-${ id } ` ) ;
425
427
} ) ;
426
428
427
- $ ( document ) . on ( 'click' , 'button.comment-form-reply' , async function ( e ) {
429
+ $ ( document ) . on ( 'click' , 'button.comment-form-reply' , async function ( e ) {
428
430
e . preventDefault ( ) ;
429
431
await handleReply ( this ) ;
430
432
} ) ;
@@ -492,7 +494,7 @@ export function initRepoPullRequestReview() {
492
494
493
495
export function initRepoIssueReferenceIssue ( ) {
494
496
// Reference issue
495
- $ ( document ) . on ( 'click' , '.reference-issue' , function ( e ) {
497
+ $ ( document ) . on ( 'click' , '.reference-issue' , function ( e ) {
496
498
const target = this . getAttribute ( 'data-target' ) ;
497
499
const content = document . querySelector ( `#${ target } ` ) ?. textContent ?? '' ;
498
500
const poster = this . getAttribute ( 'data-poster-username' ) ;
@@ -546,12 +548,15 @@ export function initRepoIssueTitleEdit() {
546
548
issueTitleInput . value = oldTitle ;
547
549
}
548
550
issueTitleInput . focus ( ) ;
551
+
552
+ window . addEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
549
553
} ) ;
550
554
issueTitleEditor . querySelector ( '.ui.cancel.button' ) . addEventListener ( 'click' , ( ) => {
551
555
hideElem ( issueTitleEditor ) ;
552
556
hideElem ( '#pull-desc-editor' ) ;
553
557
showElem ( issueTitleDisplay ) ;
554
558
showElem ( '#pull-desc-display' ) ;
559
+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
555
560
} ) ;
556
561
557
562
const pullDescEditor = document . querySelector ( '#pull-desc-editor' ) ; // it may not exist for a merged PR
@@ -577,6 +582,7 @@ export function initRepoIssueTitleEdit() {
577
582
}
578
583
}
579
584
}
585
+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
580
586
window . location . reload ( ) ;
581
587
} catch ( error ) {
582
588
console . error ( error ) ;
@@ -585,8 +591,13 @@ export function initRepoIssueTitleEdit() {
585
591
} ) ;
586
592
}
587
593
594
+ // Show a warning message when the user tries to navigate, even though he is currently editing
595
+ function showUserHintOnNavigate ( e : BeforeUnloadEvent ) {
596
+ e . preventDefault ( ) ;
597
+ }
598
+
588
599
export function initRepoIssueBranchSelect ( ) {
589
- document . querySelector ( '#branch-select' ) ?. addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
600
+ document . querySelector ( '#branch-select' ) ?. addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
590
601
const el = e . target . closest ( '.item[data-branch]' ) ;
591
602
if ( ! el ) return ;
592
603
const pullTargetBranch = document . querySelector ( '#pull-target-branch' ) ;
0 commit comments