show warning on navigation if currently editing comment or title (#32920)
This PR fixes the issue https://github.com/go-gitea/gitea/issues/32223 Make the browser to show the confirm popup, as it does with other forms. --------- Co-authored-by: Tim Wundenberg <tim@wundenbergs.de> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
parent
52b319bc00
commit
7580bd98c1
5 changed files with 27 additions and 16 deletions
13
web_src/js/vendor/jquery.are-you-sure.ts
vendored
13
web_src/js/vendor/jquery.are-you-sure.ts
vendored
|
@ -2,6 +2,7 @@
|
|||
// Fork of the upstream module. The only changes are:
|
||||
// * use export to make it work with ES6 modules.
|
||||
// * the addition of `const` to make it strict mode compatible.
|
||||
// * ignore forms with "ignore-dirty" class, ignore hidden forms (closest('.tw-hidden'))
|
||||
|
||||
/*!
|
||||
* jQuery Plugin: Are-You-Sure (Dirty Form Detection)
|
||||
|
@ -161,10 +162,10 @@ export function initAreYouSure($) {
|
|||
if (!settings.silent && !window.aysUnloadSet) {
|
||||
window.aysUnloadSet = true;
|
||||
$(window).bind('beforeunload', function() {
|
||||
const $dirtyForms = $("form").filter('.' + settings.dirtyClass);
|
||||
if ($dirtyForms.length == 0) {
|
||||
return;
|
||||
}
|
||||
const $forms = $("form:not(.ignore-dirty)").filter('.' + settings.dirtyClass);
|
||||
const dirtyFormCount = Array.from($forms).reduce((res, form) => form.closest('.tw-hidden') ? res : res + 1, 0);
|
||||
if (dirtyFormCount === 0) return;
|
||||
|
||||
// Prevent multiple prompts - seen on Chrome and IE
|
||||
if (navigator.userAgent.toLowerCase().match(/msie|chrome/)) {
|
||||
if (window.aysHasPrompted) {
|
||||
|
@ -199,3 +200,7 @@ export function initAreYouSure($) {
|
|||
export function applyAreYouSure(selectorOrEl: string|Element|$, opts = {}) {
|
||||
$(selectorOrEl).areYouSure(opts);
|
||||
}
|
||||
|
||||
export function reinitializeAreYouSure(selectorOrEl: string|Element|$) {
|
||||
$(selectorOrEl).trigger('reinitialize.areYouSure');
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue