Warn before leaving when you have changes. Fixes #341

This commit is contained in:
Tom MacWright
2013-01-09 16:18:19 -05:00
parent b896115de3
commit e781c02863
+12
View File
@@ -173,6 +173,18 @@ window.iD = function(container) {
.text(num_changes);
});
history.on('change.warn-unload', function() {
var changes = history.changes(),
has_changes = !!d3.sum(d3.values(changes).map(function(c) {
return c.length;
}));
window.onbeforeunload = has_changes ? function() {
return 'You have unsaved changes.';
} : null;
});
bar.append('div')
.attr('class', 'messages');