@@ -141,38 +141,39 @@ export function initRepoEditor() {
141141 }
142142 } ) ;
143143
144+ const elForm = document . querySelector < HTMLFormElement > ( '.repository.editor .edit.form' ) ;
145+
146+ // Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
147+ // to enable or disable the commit button
148+ const commitButton = document . querySelector < HTMLButtonElement > ( '#commit-button' ) ;
149+ const dirtyFileClass = 'dirty-file' ;
150+
151+ // Enabling the button at the start if the page has posted
152+ if ( document . querySelector < HTMLInputElement > ( 'input[name="page_has_posted"]' ) ?. value === 'true' ) {
153+ commitButton . disabled = false ;
154+ }
155+
156+ // Registering a custom listener for the file path and the file content
157+ // FIXME: it is not quite right here (old bug), it causes double-init, the global areYouSure "dirty" class will also be added
158+ applyAreYouSure ( elForm , {
159+ silent : true ,
160+ dirtyClass : dirtyFileClass ,
161+ fieldSelector : ':input:not(.commit-form-wrapper :input)' ,
162+ change ( $form : any ) {
163+ const dirty = $form [ 0 ] ?. classList . contains ( dirtyFileClass ) ;
164+ commitButton . disabled = ! dirty ;
165+ } ,
166+ } ) ;
167+
144168 // on the upload page, there is no editor(textarea)
145169 const editArea = document . querySelector < HTMLTextAreaElement > ( '.page-content.repository.editor textarea#edit_area' ) ;
146170 if ( ! editArea ) return ;
147171
148- const elForm = document . querySelector < HTMLFormElement > ( '.repository.editor .edit.form' ) ;
149172 initEditPreviewTab ( elForm ) ;
150173
151174 ( async ( ) => {
152175 const editor = await createCodeEditor ( editArea , filenameInput ) ;
153176
154- // Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
155- // to enable or disable the commit button
156- const commitButton = document . querySelector < HTMLButtonElement > ( '#commit-button' ) ;
157- const dirtyFileClass = 'dirty-file' ;
158-
159- // Disabling the button at the start
160- if ( document . querySelector < HTMLInputElement > ( 'input[name="page_has_posted"]' ) . value !== 'true' ) {
161- commitButton . disabled = true ;
162- }
163-
164- // Registering a custom listener for the file path and the file content
165- // FIXME: it is not quite right here (old bug), it causes double-init, the global areYouSure "dirty" class will also be added
166- applyAreYouSure ( elForm , {
167- silent : true ,
168- dirtyClass : dirtyFileClass ,
169- fieldSelector : ':input:not(.commit-form-wrapper :input)' ,
170- change ( $form : any ) {
171- const dirty = $form [ 0 ] ?. classList . contains ( dirtyFileClass ) ;
172- commitButton . disabled = ! dirty ;
173- } ,
174- } ) ;
175-
176177 // Update the editor from query params, if available,
177178 // only after the dirtyFileClass initialization
178179 const params = new URLSearchParams ( window . location . search ) ;
0 commit comments