1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00
mycorrhiza/static/editor.js

20 lines
567 B
JavaScript
Raw Normal View History

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