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