mirror of
https://github.com/FoggedLens/iD.git
synced 2026-04-21 11:16:36 +02:00
Fix localstorage history clearing
This commit is contained in:
@@ -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
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user