1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 13:30:26 +00:00
mycorrhiza/static/editor.js
Mysh! a3fe98cf49
Javascript related code changes (#112)
* Add if statement for case where shortcutsGroup can be undefined
* Use "===" instead of "==". Comparison prefix "==" may cause unexpected type coercion
* Remove anonymous function wrapping
2021-10-29 20:13:59 +07:00

20 lines
567 B
JavaScript

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;
});
form.addEventListener('submit', function () {
window.hyphaChanged = false;
});
window.addEventListener('beforeunload', warnBeforeClosing);