1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2025-12-09 18:08:07 +00:00

Warn before closing if unsaved on edit page

It doesn't fire if you go back to the edit page and the browser
auto-fills the previous contents, but oh well.
This commit is contained in:
handlerug
2021-07-13 16:28:21 +07:00
parent 551876dd32
commit 76d77f0887
3 changed files with 35 additions and 19 deletions

14
static/editor.js Normal file
View File

@@ -0,0 +1,14 @@
(function () {
let changed = false;
let textarea = document.querySelector('.edit-form__textarea');
let warnBeforeClosing = function (ev) {
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;
});
})();