mycorrhiza/static/editor.js
handlerug 76d77f0887 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.
2021-07-13 16:30:40 +07:00

15 lines
412 B
JavaScript

(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;
});
})();