Fix localstorage history clearing

This commit is contained in:
Ansis Brammanis
2013-02-08 11:04:05 -05:00
parent 0b89df063f
commit 2c9732f547
2 changed files with 14 additions and 12 deletions
+8 -7
View File
@@ -175,7 +175,7 @@ iD.History = function(context) {
if (!lock) return;
context.storage(getKey('lock'), null);
if (!stack.length) {
if (stack.length <= 1) {
context.storage(getKey('history'), null);
context.storage(getKey('nextIDs'), null);
context.storage(getKey('index'), null);
@@ -183,9 +183,11 @@ iD.History = function(context) {
}
var json = JSON.stringify(stack.map(function(i) {
return _.extend(i, {
graph: i.graph.entities
});
return {
annotation: i.annotation,
imagery_used: i.imagery_used,
entities: i.graph.entities
}
}));
context.storage(getKey('history'), json);
@@ -201,8 +203,7 @@ iD.History = function(context) {
},
restorableChanges: function() {
if (!this.lock()) return false;
return !!context.storage(getKey('history'));
return lock && !!context.storage(getKey('history'));
},
load: function() {
@@ -221,7 +222,7 @@ iD.History = function(context) {
context.storage(getKey('index', null));
stack = JSON.parse(json).map(function(d, i) {
d.graph = iD.Graph(stack[0].graph).load(d.graph);
d.graph = iD.Graph(stack[0].graph).load(d.entities);
return d;
});
dispatch.change();
+6 -5
View File
@@ -193,11 +193,12 @@ iD.ui = function(context) {
contributors.append('span')
.attr('class', 'contributor-count');
window.onbeforeunload = function() {
history.save();
if (history.hasChanges()) return 'You have unsaved changes';
};
history.on('change.editor', function() {
window.onbeforeunload = history.hasChanges() ? function() {
history.save();
return 'You have unsaved changes.';
} : null;
var undo = history.undoAnnotation(),
redo = history.redoAnnotation();
@@ -264,7 +265,7 @@ iD.ui = function(context) {
context.storage('sawSplash', true);
}
if (history.restorableChanges()) {
if (history.lock() && history.restorableChanges()) {
iD.ui.restore(context.container(), history);
}