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