Extract iD.ui.UndoRedo

This commit is contained in:
John Firebaugh
2013-02-12 11:55:38 -08:00
parent 5761c31d29
commit e73c19a4e8
4 changed files with 52 additions and 41 deletions

View File

@@ -81,6 +81,7 @@
<script src='js/id/ui/lasso.js'></script>
<script src='js/id/ui/source_switch.js'></script>
<script src='js/id/ui/toggle.js'></script>
<script src='js/id/ui/undo_redo.js'></script>
<script src='js/id/actions.js'></script>
<script src="js/id/actions/add_midpoint.js"></script>

View File

@@ -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 */

View File

@@ -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("<span class='undo icon'></span><small></small>")
.on('click.editor', history.undo)
.call(undo_tooltip);
undo_buttons.append('button')
.attr({ id: 'redo', 'class': 'col6' })
.classed('disabled', true)
.html("<span class='redo icon'><small></small>")
.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]))

47
js/id/ui/undo_redo.js Normal file
View File

@@ -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('<span class="undo icon"/>')
.on('click', context.undo)
.call(tooltip);
var redoButton = selection.append('button')
.attr('class', 'col6 disabled')
.html('<span class="redo icon"/>')
.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);
});
}
};