1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-10-30 11:46:16 +00:00

Fix warn before closing

This commit is contained in:
handlerug 2021-07-13 21:21:46 +07:00
parent 76d77f0887
commit 9ad9db9825
No known key found for this signature in database
GPG Key ID: 38009F0605051491

View File

@ -1,14 +1,21 @@
(function () {
let changed = false;
let textarea = document.querySelector('.edit-form__textarea');
let form = document.querySelector('.edit-form');
let warnBeforeClosing = function (ev) {
if (!changed) return;
ev.preventDefault();
return ev.returnValue = 'Are you sure you want to exit? You have unsaved changes.';
};
textarea.addEventListener('input', function () {
if (!changed) window.addEventListener('beforeunload', warnBeforeClosing);
changed = true;
});
form.addEventListener('submit', function () {
changed = false;
});
window.addEventListener('beforeunload', warnBeforeClosing);
})();