@@ -7,7 +7,7 @@ import {attachRefIssueContextPopup} from './contextpopup.ts';
77import { initCommentContent , initMarkupContent } from '../markup/content.ts' ;
88import { triggerUploadStateChanged } from './comp/EditorUpload.ts' ;
99import { convertHtmlToMarkdown } from '../markup/html2markdown.ts' ;
10- import { applyAreYouSure } from '../vendor/jquery.are-you-sure.ts' ;
10+ import { applyAreYouSure , reinitializeAreYouSure } from '../vendor/jquery.are-you-sure.ts' ;
1111
1212async function tryOnEditContent ( e ) {
1313 const clickTarget = e . target . closest ( '.edit-content' ) ;
@@ -20,16 +20,19 @@ async function tryOnEditContent(e) {
2020 const rawContent = segment . querySelector ( '.raw-content' ) ;
2121
2222 let comboMarkdownEditor : ComboMarkdownEditor ;
23+ let form : HTMLFormElement ;
2324
2425 const cancelAndReset = ( e ) => {
2526 e . preventDefault ( ) ;
27+ form . classList . add ( 'ignore-dirty' ) ;
2628 showElem ( renderContent ) ;
2729 hideElem ( editContentZone ) ;
2830 comboMarkdownEditor . dropzoneReloadFiles ( ) ;
2931 } ;
3032
3133 const saveAndRefresh = async ( e ) => {
3234 e . preventDefault ( ) ;
35+ form . classList . remove ( 'ignore-dirty' ) ;
3336 renderContent . classList . add ( 'is-loading' ) ;
3437 showElem ( renderContent ) ;
3538 hideElem ( editContentZone ) ;
@@ -49,6 +52,7 @@ async function tryOnEditContent(e) {
4952 showErrorToast ( data . errorMessage ) ;
5053 return ;
5154 }
55+ reinitializeAreYouSure ( form ) ;
5256 editContentZone . setAttribute ( 'data-content-version' , data . contentVersion ) ;
5357 if ( ! data . content ) {
5458 renderContent . innerHTML = document . querySelector ( '#no-content' ) . innerHTML ;
@@ -87,14 +91,15 @@ async function tryOnEditContent(e) {
8791 comboMarkdownEditor = getComboMarkdownEditor ( editContentZone . querySelector ( '.combo-markdown-editor' ) ) ;
8892 if ( ! comboMarkdownEditor ) {
8993 editContentZone . innerHTML = document . querySelector ( '#issue-comment-editor-template' ) . innerHTML ;
90- applyAreYouSure ( editContentZone . firstElementChild ) ;
94+ form = editContentZone . querySelector ( 'form' ) ;
95+ applyAreYouSure ( form ) ;
9196 const saveButton = querySingleVisibleElem < HTMLButtonElement > ( editContentZone , '.ui.primary.button' ) ;
9297 const cancelButton = querySingleVisibleElem < HTMLButtonElement > ( editContentZone , '.ui.cancel.button' ) ;
9398 comboMarkdownEditor = await initComboMarkdownEditor ( editContentZone . querySelector ( '.combo-markdown-editor' ) ) ;
9499 const syncUiState = ( ) => saveButton . disabled = comboMarkdownEditor . isUploading ( ) ;
95100 comboMarkdownEditor . container . addEventListener ( ComboMarkdownEditor . EventUploadStateChanged , syncUiState ) ;
96101 cancelButton . addEventListener ( 'click' , cancelAndReset ) ;
97- saveButton . addEventListener ( 'click ' , saveAndRefresh ) ;
102+ form . addEventListener ( 'submit ' , saveAndRefresh ) ;
98103 }
99104
100105 // FIXME: ideally here should reload content and attachment list from backend for existing editor, to avoid losing data
0 commit comments