mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-22 16:16:51 +00:00
Fix warn before closing
This commit is contained in:
parent
76d77f0887
commit
9ad9db9825
@ -1,14 +1,21 @@
|
|||||||
(function () {
|
(function () {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
let textarea = document.querySelector('.edit-form__textarea');
|
let textarea = document.querySelector('.edit-form__textarea');
|
||||||
|
let form = document.querySelector('.edit-form');
|
||||||
|
|
||||||
let warnBeforeClosing = function (ev) {
|
let warnBeforeClosing = function (ev) {
|
||||||
|
if (!changed) return;
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
return ev.returnValue = 'Are you sure you want to exit? You have unsaved changes.';
|
return ev.returnValue = 'Are you sure you want to exit? You have unsaved changes.';
|
||||||
};
|
};
|
||||||
|
|
||||||
textarea.addEventListener('input', function () {
|
textarea.addEventListener('input', function () {
|
||||||
if (!changed) window.addEventListener('beforeunload', warnBeforeClosing);
|
|
||||||
changed = true;
|
changed = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
form.addEventListener('submit', function () {
|
||||||
|
changed = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener('beforeunload', warnBeforeClosing);
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user