@@ -61,7 +61,7 @@ function initRepoIssueLabelFilter(elDropdown: Element) {
6161 selectedLabelIds . add ( `${ Math . abs ( parseInt ( id ) ) } ` ) ; // "labels" contains negative ids, which are excluded
6262 }
6363
64- const excludeLabel = ( e : MouseEvent | KeyboardEvent , item : Element ) => {
64+ const excludeLabel = ( e : MouseEvent | KeyboardEvent , item : Element ) => {
6565 e . preventDefault ( ) ;
6666 e . stopPropagation ( ) ;
6767 const labelId = item . getAttribute ( 'data-label-id' ) ;
@@ -124,7 +124,7 @@ export function initRepoIssueFilterItemLabel() {
124124
125125export function initRepoIssueCommentDelete ( ) {
126126 // Delete comment
127- document . addEventListener ( 'click' , async ( e : MouseEvent & { target : HTMLElement } ) => {
127+ document . addEventListener ( 'click' , async ( e : MouseEvent & { target : HTMLElement } ) => {
128128 if ( ! e . target . matches ( '.delete-comment' ) ) return ;
129129 e . preventDefault ( ) ;
130130
@@ -199,7 +199,7 @@ export function initRepoIssueDependencyDelete() {
199199
200200export function initRepoIssueCodeCommentCancel ( ) {
201201 // Cancel inline code comment
202- document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
202+ document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
203203 if ( ! e . target . matches ( '.cancel-code-comment' ) ) return ;
204204
205205 const form = e . target . closest ( 'form' ) ;
@@ -217,7 +217,7 @@ export function initRepoPullRequestUpdate() {
217217 const pullUpdateButton = document . querySelector ( '.update-button > button' ) ;
218218 if ( ! pullUpdateButton ) return ;
219219
220- pullUpdateButton . addEventListener ( 'click' , async function ( e ) {
220+ pullUpdateButton . addEventListener ( 'click' , async function ( e ) {
221221 e . preventDefault ( ) ;
222222 const redirect = this . getAttribute ( 'data-redirect' ) ;
223223 this . classList . add ( 'is-loading' ) ;
@@ -273,9 +273,11 @@ export function initRepoPullRequestAllowMaintainerEdit() {
273273 const url = `${ wrapper . getAttribute ( 'data-url' ) } /set_allow_maintainer_edit` ;
274274 wrapper . classList . add ( 'is-loading' ) ;
275275 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+ } ) ;
279281 if ( ! resp . ok ) {
280282 throw new Error ( 'Failed to update maintainer edit permission' ) ;
281283 }
@@ -340,7 +342,7 @@ export function initRepoIssueWipTitle() {
340342export function initRepoIssueComments ( ) {
341343 if ( ! $ ( '.repository.view.issue .timeline' ) . length ) return ;
342344
343- document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
345+ document . addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
344346 const urlTarget = document . querySelector ( ':target' ) ;
345347 if ( ! urlTarget ) return ;
346348
@@ -406,7 +408,7 @@ export function initRepoPullRequestReview() {
406408 }
407409 }
408410
409- $ ( document ) . on ( 'click' , '.show-outdated' , function ( e ) {
411+ $ ( document ) . on ( 'click' , '.show-outdated' , function ( e ) {
410412 e . preventDefault ( ) ;
411413 const id = this . getAttribute ( 'data-comment' ) ;
412414 hideElem ( this ) ;
@@ -415,7 +417,7 @@ export function initRepoPullRequestReview() {
415417 showElem ( `#hide-outdated-${ id } ` ) ;
416418 } ) ;
417419
418- $ ( document ) . on ( 'click' , '.hide-outdated' , function ( e ) {
420+ $ ( document ) . on ( 'click' , '.hide-outdated' , function ( e ) {
419421 e . preventDefault ( ) ;
420422 const id = this . getAttribute ( 'data-comment' ) ;
421423 hideElem ( this ) ;
@@ -424,7 +426,7 @@ export function initRepoPullRequestReview() {
424426 showElem ( `#show-outdated-${ id } ` ) ;
425427 } ) ;
426428
427- $ ( document ) . on ( 'click' , 'button.comment-form-reply' , async function ( e ) {
429+ $ ( document ) . on ( 'click' , 'button.comment-form-reply' , async function ( e ) {
428430 e . preventDefault ( ) ;
429431 await handleReply ( this ) ;
430432 } ) ;
@@ -492,7 +494,7 @@ export function initRepoPullRequestReview() {
492494
493495export function initRepoIssueReferenceIssue ( ) {
494496 // Reference issue
495- $ ( document ) . on ( 'click' , '.reference-issue' , function ( e ) {
497+ $ ( document ) . on ( 'click' , '.reference-issue' , function ( e ) {
496498 const target = this . getAttribute ( 'data-target' ) ;
497499 const content = document . querySelector ( `#${ target } ` ) ?. textContent ?? '' ;
498500 const poster = this . getAttribute ( 'data-poster-username' ) ;
@@ -546,12 +548,15 @@ export function initRepoIssueTitleEdit() {
546548 issueTitleInput . value = oldTitle ;
547549 }
548550 issueTitleInput . focus ( ) ;
551+
552+ window . addEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
549553 } ) ;
550554 issueTitleEditor . querySelector ( '.ui.cancel.button' ) . addEventListener ( 'click' , ( ) => {
551555 hideElem ( issueTitleEditor ) ;
552556 hideElem ( '#pull-desc-editor' ) ;
553557 showElem ( issueTitleDisplay ) ;
554558 showElem ( '#pull-desc-display' ) ;
559+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
555560 } ) ;
556561
557562 const pullDescEditor = document . querySelector ( '#pull-desc-editor' ) ; // it may not exist for a merged PR
@@ -577,6 +582,7 @@ export function initRepoIssueTitleEdit() {
577582 }
578583 }
579584 }
585+ window . removeEventListener ( 'beforeunload' , showUserHintOnNavigate ) ;
580586 window . location . reload ( ) ;
581587 } catch ( error ) {
582588 console . error ( error ) ;
@@ -585,8 +591,13 @@ export function initRepoIssueTitleEdit() {
585591 } ) ;
586592}
587593
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+
588599export function initRepoIssueBranchSelect ( ) {
589- document . querySelector ( '#branch-select' ) ?. addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
600+ document . querySelector ( '#branch-select' ) ?. addEventListener ( 'click' , ( e : MouseEvent & { target : HTMLElement } ) => {
590601 const el = e . target . closest ( '.item[data-branch]' ) ;
591602 if ( ! el ) return ;
592603 const pullTargetBranch = document . querySelector ( '#pull-target-branch' ) ;
0 commit comments