Report element removals correctly

An element with a `defaultValue` now becomes dirty when removed; elements
without become clean. As a result, removing an existing section makes the
document dirty while removing a new section makes it clean(er).
This commit is contained in:
hideheader 2015-03-16 16:47:56 -04:00
parent b7483035d5
commit 4e7b15f491

17
edit.js
View File

@ -46,8 +46,13 @@ function setCleanItem(node, clean) {
initTitle(); initTitle();
} }
function isCleanGlobal() { function isCleanGlobal() {
return Object.keys(items) var clean = Object.keys(items)
.every(function(item) { return items[item] }); .every(function(item) { return items[item] });
if (clean) document.body.classList.remove("dirty");
else document.body.classList.add("dirty");
return clean;
} }
function setCleanGlobal(form) { function setCleanGlobal(form) {
if (!form) form = null; if (!form) form = null;
@ -66,6 +71,7 @@ function setCleanGlobal(form) {
editors.forEach(function(cm) { editors.forEach(function(cm) {
cm.lastChange = cm.changeGeneration(); cm.lastChange = cm.changeGeneration();
cm.getTextArea().parentNode.defaultValue = cm.lastChange;
indicateCodeChange(cm); indicateCodeChange(cm);
}); });
@ -317,8 +323,8 @@ function removeAppliesTo(event) {
e.querySelector(".add-applies-to").addEventListener("click", function() {addAppliesTo(this.parentNode.parentNode)}, false); e.querySelector(".add-applies-to").addEventListener("click", function() {addAppliesTo(this.parentNode.parentNode)}, false);
appliesToList.appendChild(e); appliesToList.appendChild(e);
} }
Array.prototype.forEach.call(appliesTo.querySelectorAll(".dirty"), function(node) { Array.prototype.forEach.call(appliesTo.querySelectorAll("input, select"), function(node) {
setCleanItem(node, true); setCleanItem(node, !node.defaultValue);
}); });
} }
@ -331,9 +337,10 @@ function removeSection(event) {
setCleanItem(wrapper.parentNode, true); setCleanItem(wrapper.parentNode, true);
} }
section.parentNode.removeChild(section); section.parentNode.removeChild(section);
Array.prototype.forEach.call(section.querySelectorAll(".dirty"), function(node) { Array.prototype.forEach.call(section.querySelectorAll("input, select"), function(node) {
setCleanItem(node, true); setCleanItem(node, !node.defaultValue);
}); });
setCleanItem(section, !section.defaultValue);
} }
function setupGlobalSearch() { function setupGlobalSearch() {