Add 'I' shortcut for switching between the last two backgrounds.

This commit is contained in:
Rodolphe PELLOUX-PRAYER
2015-11-21 16:50:04 +01:00
parent d124d13b4b
commit c19bb20e71
2 changed files with 29 additions and 1 deletions

View File

@@ -1808,6 +1808,10 @@ div.full-screen > button:hover {
background: #E8EBFF;
}
.layer-list li.switch {
background: #fffce8;
}
.layer-list label {
display: block;
padding: 5px 10px;

View File

@@ -8,7 +8,8 @@ iD.ui.Background = function(context) {
['bottom', [0, 1]]],
opacityDefault = (context.storage('background-opacity') !== null) ?
(+context.storage('background-opacity')) : 1.0,
customTemplate = context.storage('background-custom-template') || '';
customTemplate = context.storage('background-custom-template') || '',
latestBg = [context.background().baseLayerSource(), null];
// Can be 0 from <1.3.0 use or due to issue #1923.
if (opacityDefault === 0) opacityDefault = 1.0;
@@ -44,13 +45,21 @@ iD.ui.Background = function(context) {
return context.background().showsLayer(d);
}
function bgswitch(d) {
return latestBg[1] === d;
}
content.selectAll('.layer, .custom_layer')
.classed('active', active)
.classed('switch', bgswitch)
.selectAll('input')
.property('checked', active);
}
function clickSetSource(d) {
latestBg[1] = latestBg[0];
latestBg[0] = d;
d3.event.preventDefault();
context.background().baseLayerSource(d);
selectLayer();
@@ -156,6 +165,20 @@ iD.ui.Background = function(context) {
setVisible(!button.classed('active'));
}
function interchangeBg() {
var d = latestBg[1];
if (d == null) {
toggle();
return;
}
latestBg[1] = latestBg[0];
latestBg[0] = d;
context.background().baseLayerSource(d);
selectLayer();
}
function setVisible(show) {
if (show !== shown) {
button.classed('active', show);
@@ -323,6 +346,7 @@ iD.ui.Background = function(context) {
var keybinding = d3.keybinding('background')
.on(key, toggle)
.on('I', interchangeBg)
.on('F', hide)
.on('H', hide);