Ask user for confirmation when they abandon an edit in progress. This fixes #17

This commit is contained in:
Magnus Hoff 2017-10-28 15:21:47 +02:00
parent d570893a10
commit 6d56ad0001

View file

@ -13,6 +13,13 @@ function queryArgsFromForm(form) {
return items.join('&');
}
function isEdited(form) {
for (const {name, value, defaultValue} of form.elements) {
if (name && (value !== defaultValue)) return true;
}
return false;
}
let hasBeenOpen = false;
function openEditor() {
const container = document.querySelector(".container");
@ -91,8 +98,10 @@ function openEditor() {
ev.preventDefault();
ev.stopPropagation();
if (!isEdited(form) || confirm("Discard changes?")) {
container.classList.remove('edit');
form.reset();
}
});
}