diff --git a/index.html b/index.html
index cdf6b38e4..4ea9d9721 100644
--- a/index.html
+++ b/index.html
@@ -81,6 +81,7 @@
+
diff --git a/js/id/id.js b/js/id/id.js
index a7d7a44ac..f0747ad02 100644
--- a/js/id/id.js
+++ b/js/id/id.js
@@ -34,7 +34,7 @@ window.iD = function () {
context.replace = history.replace;
context.pop = history.pop;
context.undo = history.undo;
- context.redo = history.undo;
+ context.redo = history.redo;
context.changes = history.changes;
/* Graph */
diff --git a/js/id/ui.js b/js/id/ui.js
index 564c07983..8515d3dfd 100644
--- a/js/id/ui.js
+++ b/js/id/ui.js
@@ -29,23 +29,9 @@ iD.ui = function(context) {
.attr('class', 'button-wrap joined col4')
.call(iD.ui.Modes(context), limiter);
- var undo_buttons = limiter.append('div')
- .attr('class', 'button-wrap joined col1'),
- undo_tooltip = bootstrap.tooltip().placement('bottom').html(true);
-
- undo_buttons.append('button')
- .attr({ id: 'undo', 'class': 'col6' })
- .classed('disabled', true)
- .html("")
- .on('click.editor', history.undo)
- .call(undo_tooltip);
-
- undo_buttons.append('button')
- .attr({ id: 'redo', 'class': 'col6' })
- .classed('disabled', true)
- .html("")
- .on('click.editor', history.redo)
- .call(undo_tooltip);
+ limiter.append('div')
+ .attr('class', 'button-wrap joined col1')
+ .call(iD.ui.UndoRedo(context));
limiter.append('div').attr('class','button-wrap col1').append('button')
.attr('class', 'save col12')
@@ -134,27 +120,6 @@ iD.ui = function(context) {
if (history.hasChanges()) return t('unsaved_changes');
};
- history.on('change.editor', function() {
- var undo = history.undoAnnotation(),
- redo = history.redoAnnotation();
-
- function refreshTooltip(selection) {
- if (selection.property('tooltipVisible')) {
- selection.call(undo_tooltip.show);
- }
- }
-
- limiter.select('#undo')
- .classed('disabled', !undo)
- .attr('data-original-title', iD.ui.tooltipHtml(undo || t('nothing_to_undo'), iD.ui.cmd('⌘Z')))
- .call(refreshTooltip);
-
- limiter.select('#redo')
- .classed('disabled', !redo)
- .attr('data-original-title', iD.ui.tooltipHtml(redo || t('nothing_to_redo'), iD.ui.cmd('⌘⇧Z')))
- .call(refreshTooltip);
- });
-
d3.select(window).on('resize.editor', function() {
map.size(m.size());
});
@@ -170,8 +135,6 @@ iD.ui = function(context) {
var pa = 5;
var keybinding = d3.keybinding('main')
- .on(iD.ui.cmd('⌘Z'), function() { history.undo(); })
- .on(iD.ui.cmd('⌘⇧Z'), function() { history.redo(); })
.on('⌫', function() { d3.event.preventDefault(); })
.on('←', pan([pa, 0]))
.on('↑', pan([0, pa]))
diff --git a/js/id/ui/undo_redo.js b/js/id/ui/undo_redo.js
new file mode 100644
index 000000000..f38066af4
--- /dev/null
+++ b/js/id/ui/undo_redo.js
@@ -0,0 +1,47 @@
+iD.ui.UndoRedo = function(context) {
+ return function(selection) {
+ var tooltip = bootstrap.tooltip()
+ .placement('bottom')
+ .html(true);
+
+ var undoButton = selection.append('button')
+ .attr('class', 'col6 disabled')
+ .html('')
+ .on('click', context.undo)
+ .call(tooltip);
+
+ var redoButton = selection.append('button')
+ .attr('class', 'col6 disabled')
+ .html('')
+ .on('click', context.redo)
+ .call(tooltip);
+
+ var keybinding = d3.keybinding('undo')
+ .on(iD.ui.cmd('⌘Z'), context.undo)
+ .on(iD.ui.cmd('⌘⇧Z'), context.redo);
+
+ d3.select(document)
+ .call(keybinding);
+
+ context.history().on('change.editor', function() {
+ var undo = context.history().undoAnnotation(),
+ redo = context.history().redoAnnotation();
+
+ function refreshTooltip(selection) {
+ if (selection.property('tooltipVisible')) {
+ selection.call(tooltip.show);
+ }
+ }
+
+ undoButton
+ .classed('disabled', !undo)
+ .attr('data-original-title', iD.ui.tooltipHtml(undo || t('nothing_to_undo'), iD.ui.cmd('⌘Z')))
+ .call(refreshTooltip);
+
+ redoButton
+ .classed('disabled', !redo)
+ .attr('data-original-title', iD.ui.tooltipHtml(redo || t('nothing_to_redo'), iD.ui.cmd('⌘⇧Z')))
+ .call(refreshTooltip);
+ });
+ }
+};