0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-10-14 05:46:20 +02:00

Enable commit button only if something has changed

This commit is contained in:
bytedream 2025-05-08 12:27:10 +02:00
parent 9811c28627
commit 3ad1e7e215
2 changed files with 25 additions and 24 deletions

View File

@ -77,7 +77,7 @@
</div>
{{end}}
</div>
<button id="commit-button" type="submit" class="ui primary button">
<button id="commit-button" type="submit" class="ui primary button" {{if .PageIsEdit}}disabled{{end}}>
{{if eq .commit_choice "commit-to-new-branch"}}{{ctx.Locale.Tr "repo.editor.propose_file_change"}}{{else}}{{ctx.Locale.Tr "repo.editor.commit_changes"}}{{end}}
</button>
<a class="ui button red" href="{{if .ReturnURI}}{{.ReturnURI}}{{else}}{{$.BranchLink}}/{{PathEscapeSegments .TreePath}}{{end}}">{{ctx.Locale.Tr "repo.editor.cancel"}}</a>

View File

@ -141,24 +141,16 @@ export function initRepoEditor() {
}
});
// on the upload page, there is no editor(textarea)
const editArea = document.querySelector<HTMLTextAreaElement>('.page-content.repository.editor textarea#edit_area');
if (!editArea) return;
const elForm = document.querySelector<HTMLFormElement>('.repository.editor .edit.form');
initEditPreviewTab(elForm);
(async () => {
const editor = await createCodeEditor(editArea, filenameInput);
// Using events from https://github.com/codedance/jquery.AreYouSure#advanced-usage
// to enable or disable the commit button
const commitButton = document.querySelector<HTMLButtonElement>('#commit-button');
const dirtyFileClass = 'dirty-file';
// Disabling the button at the start
if (document.querySelector<HTMLInputElement>('input[name="page_has_posted"]').value !== 'true') {
commitButton.disabled = true;
// Enabling the button at the start if the page has posted
if (document.querySelector<HTMLInputElement>('input[name="page_has_posted"]')?.value === 'true') {
commitButton.disabled = false;
}
// Registering a custom listener for the file path and the file content
@ -173,6 +165,15 @@ export function initRepoEditor() {
},
});
// on the upload page, there is no editor(textarea)
const editArea = document.querySelector<HTMLTextAreaElement>('.page-content.repository.editor textarea#edit_area');
if (!editArea) return;
initEditPreviewTab(elForm);
(async () => {
const editor = await createCodeEditor(editArea, filenameInput);
// Update the editor from query params, if available,
// only after the dirtyFileClass initialization
const params = new URLSearchParams(window.location.search);