Skip to content

Commit 05ef5d1

Browse files
committed
fix
1 parent 6b7856c commit 05ef5d1

File tree

2 files changed

+26
-18
lines changed

2 files changed

+26
-18
lines changed

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
import {SvgIcon} from '../svg.ts';
33
import {isPlainClick} from '../utils/dom.ts';
4-
import {triggersAreYouSure} from '../vendor/jquery.are-you-sure.ts';
4+
import {shouldTriggerAreYouSure} from '../vendor/jquery.are-you-sure.ts';
55
import {shallowRef} from 'vue';
66
import type {createViewFileTreeStore, FileTreeItem} from './ViewFileTreeStore.ts';
77
@@ -31,7 +31,7 @@ const onItemClick = (e: MouseEvent) => {
3131
// only handle the click event with partial page reloading if both
3232
// - the user didn't press any special key like "Ctrl+Click" (which may have custom browser behavior)
3333
// - the editor/commit form isn't dirty (a full page reload shows a confirmation dialog if the form contains unsaved changes)
34-
if (!isPlainClick(e) || triggersAreYouSure()) return;
34+
if (!isPlainClick(e) || shouldTriggerAreYouSure()) return;
3535
e.preventDefault();
3636
if (props.item.entryMode === 'tree') doLoadChildren();
3737
store.navigateTreeView(props.item.fullPath);

web_src/js/vendor/jquery.are-you-sure.ts

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// * use export to make it work with ES6 modules.
44
// * the addition of `const` to make it strict mode compatible.
55
// * ignore forms with "ignore-dirty" class, ignore hidden forms (closest('.tw-hidden'))
6-
// * extract the default options to make it available to other functions
7-
// * check if any form is dirty
6+
// * extract the dirty check logic into a separate function
87

98
/*!
109
* jQuery Plugin: Are-You-Sure (Dirty Form Detection)
@@ -18,21 +17,22 @@
1817
* Version: 1.9.0
1918
* Date: 13th August 2014
2019
*/
21-
const defaultOptions = {
22-
'message': 'You have unsaved changes!',
23-
'dirtyClass': 'dirty',
24-
'change': null,
25-
'silent': false,
26-
'addRemoveFieldsMarksDirty': false,
27-
'fieldEvents': 'change keyup propertychange input',
28-
'fieldSelector': ":input:not(input[type=submit]):not(input[type=button])"
29-
};
20+
21+
const dataKeyAysSettings = 'ays-settings';
3022

3123
export function initAreYouSure($) {
3224

3325
$.fn.areYouSure = function(options) {
3426

35-
var settings = $.extend({}, defaultOptions, options);
27+
var settings = $.extend({
28+
'message': 'You have unsaved changes!',
29+
'dirtyClass': 'dirty',
30+
'change': null,
31+
'silent': false,
32+
'addRemoveFieldsMarksDirty': false,
33+
'fieldEvents': 'change keyup propertychange input',
34+
'fieldSelector': ":input:not(input[type=submit]):not(input[type=button])"
35+
}, options);
3636

3737
var getValue = function($field) {
3838
if ($field.hasClass('ays-ignore')
@@ -127,6 +127,7 @@ export function initAreYouSure($) {
127127
$(fields).unbind(settings.fieldEvents, checkForm);
128128
$(fields).bind(settings.fieldEvents, checkForm);
129129
$form.data("ays-orig-field-count", $(fields).length);
130+
$form.data(dataKeyAysSettings, settings);
130131
setDirtyStatus($form, false);
131132
};
132133

@@ -165,7 +166,7 @@ export function initAreYouSure($) {
165166
if (!settings.silent && !window.aysUnloadSet) {
166167
window.aysUnloadSet = true;
167168
$(window).bind('beforeunload', function() {
168-
if (!triggersAreYouSure(settings)) return;
169+
if (!shouldTriggerAreYouSure(settings)) return;
169170

170171
// Prevent multiple prompts - seen on Chrome and IE
171172
if (navigator.userAgent.toLowerCase().match(/msie|chrome/)) {
@@ -212,7 +213,14 @@ export function ignoreAreYouSure(selectorOrEl: string|Element|$) {
212213
$(selectorOrEl).addClass('ignore-dirty');
213214
}
214215

215-
export function triggersAreYouSure(opts = {}) {
216-
const $forms = $('form:not(.ignore-dirty)').filter('.' + (opts.dirtyClass ?? defaultOptions.dirtyClass));
217-
return Array.from($forms).some((form) => form.closest('.tw-hidden') === null);
216+
export function shouldTriggerAreYouSure(): boolean {
217+
const forms = document.querySelectorAll('form:not(.ignore-dirty)');
218+
for (const form of forms) {
219+
const settings = $(form).data(dataKeyAysSettings);
220+
if (!settings) continue;
221+
if (!form.matches('.' + settings.dirtyClass)) continue;
222+
if (form.closest('.tw-hidden')) continue;
223+
return true;
224+
}
225+
return false;
218226
}

0 commit comments

Comments
 (0)