diff --git a/static/editor.js b/static/editor.js index 1ae08cb..64c9d2d 100644 --- a/static/editor.js +++ b/static/editor.js @@ -1,14 +1,21 @@ (function () { let changed = false; let textarea = document.querySelector('.edit-form__textarea'); + let form = document.querySelector('.edit-form'); let warnBeforeClosing = function (ev) { + if (!changed) return; 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; }); + + form.addEventListener('submit', function () { + changed = false; + }); + + window.addEventListener('beforeunload', warnBeforeClosing); })();