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:
14
static/editor.js
Normal file
14
static/editor.js
Normal 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;
|
||||
});
|
||||
})();
|
||||
Reference in New Issue
Block a user