diff options
author | wxiaoguang <wxiaoguang@gmail.com> | 2024-12-22 01:11:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-21 12:11:22 -0500 |
commit | 09a0041965ead62ba96a96bc47a0e8699ec99650 (patch) | |
tree | 829a4e9a9485d82d400f696d4b86631d12e64753 /web_src/js | |
parent | 23687a0a71c1a678ef7b443d8427eb840fdcedf9 (diff) | |
download | gitea-09a0041965ead62ba96a96bc47a0e8699ec99650.tar.gz gitea-09a0041965ead62ba96a96bc47a0e8699ec99650.zip |
Fix areYouSure confirm (#32941)
See the comment
Diffstat (limited to 'web_src/js')
-rw-r--r-- | web_src/js/features/common-fetch-action.ts | 3 | ||||
-rw-r--r-- | web_src/js/features/repo-editor.ts | 4 | ||||
-rw-r--r-- | web_src/js/features/repo-issue.ts | 3 | ||||
-rw-r--r-- | web_src/js/vendor/jquery.are-you-sure.ts | 6 |
4 files changed, 12 insertions, 4 deletions
diff --git a/web_src/js/features/common-fetch-action.ts b/web_src/js/features/common-fetch-action.ts index 1a5b38e3e5..bc72f4089a 100644 --- a/web_src/js/features/common-fetch-action.ts +++ b/web_src/js/features/common-fetch-action.ts @@ -3,6 +3,7 @@ import {showErrorToast} from '../modules/toast.ts'; import {addDelegatedEventListener, submitEventSubmitter} from '../utils/dom.ts'; import {confirmModal} from './comp/ConfirmModal.ts'; import type {RequestOpts} from '../types.ts'; +import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts'; const {appSubUrl, i18n} = window.config; @@ -27,7 +28,7 @@ async function fetchActionDoRequest(actionElem: HTMLElement, url: string, opt: R if (resp.status === 200) { let {redirect} = await resp.json(); redirect = redirect || actionElem.getAttribute('data-redirect'); - actionElem.classList.remove('dirty'); // remove the areYouSure check before reloading + ignoreAreYouSure(actionElem); // ignore the areYouSure check before reloading if (redirect) { fetchActionDoRedirect(redirect); } else { diff --git a/web_src/js/features/repo-editor.ts b/web_src/js/features/repo-editor.ts index 32d0b84f4c..64d0402d84 100644 --- a/web_src/js/features/repo-editor.ts +++ b/web_src/js/features/repo-editor.ts @@ -6,7 +6,7 @@ import {attachRefIssueContextPopup} from './contextpopup.ts'; import {POST} from '../modules/fetch.ts'; import {initDropzone} from './dropzone.ts'; import {confirmModal} from './comp/ConfirmModal.ts'; -import {applyAreYouSure} from '../vendor/jquery.are-you-sure.ts'; +import {applyAreYouSure, ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts'; import {fomanticQuery} from '../modules/fomantic/base.ts'; function initEditPreviewTab(elForm: HTMLFormElement) { @@ -188,7 +188,7 @@ export function initRepoEditor() { header: elForm.getAttribute('data-text-empty-confirm-header'), content: elForm.getAttribute('data-text-empty-confirm-content'), })) { - elForm.classList.remove('dirty'); + ignoreAreYouSure(elForm); elForm.submit(); } } diff --git a/web_src/js/features/repo-issue.ts b/web_src/js/features/repo-issue.ts index 1e1bbd64f0..f47e05c47c 100644 --- a/web_src/js/features/repo-issue.ts +++ b/web_src/js/features/repo-issue.ts @@ -16,6 +16,7 @@ import {GET, POST} from '../modules/fetch.ts'; import {showErrorToast} from '../modules/toast.ts'; import {initRepoIssueSidebar} from './repo-issue-sidebar.ts'; import {fomanticQuery} from '../modules/fomantic/base.ts'; +import {ignoreAreYouSure} from '../vendor/jquery.are-you-sure.ts'; const {appSubUrl} = window.config; @@ -578,7 +579,7 @@ export function initRepoIssueTitleEdit() { } } } - issueTitleEditor.classList.remove('dirty'); + ignoreAreYouSure(issueTitleEditor); window.location.reload(); } catch (error) { console.error(error); diff --git a/web_src/js/vendor/jquery.are-you-sure.ts b/web_src/js/vendor/jquery.are-you-sure.ts index 7f0bef8040..51359c87a7 100644 --- a/web_src/js/vendor/jquery.are-you-sure.ts +++ b/web_src/js/vendor/jquery.are-you-sure.ts @@ -204,3 +204,9 @@ export function applyAreYouSure(selectorOrEl: string|Element|$, opts = {}) { export function reinitializeAreYouSure(selectorOrEl: string|Element|$) { $(selectorOrEl).trigger('reinitialize.areYouSure'); } + +export function ignoreAreYouSure(selectorOrEl: string|Element|$) { + // here we should only add "ignore-dirty" but not remove "dirty". + // because when using "enter" to submit a form, the "dirty" class will appear again before reloading. + $(selectorOrEl).addClass('ignore-dirty'); +} |