From c19bb20e71f7330d0e783293b1b2980ecf41516b Mon Sep 17 00:00:00 2001 From: Rodolphe PELLOUX-PRAYER Date: Sat, 21 Nov 2015 16:50:04 +0100 Subject: [PATCH] Add 'I' shortcut for switching between the last two backgrounds. --- css/app.css | 4 ++++ js/id/ui/background.js | 26 +++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/css/app.css b/css/app.css index 865c92a70..4c4875fa0 100644 --- a/css/app.css +++ b/css/app.css @@ -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; diff --git a/js/id/ui/background.js b/js/id/ui/background.js index c999edd82..60c891146 100644 --- a/js/id/ui/background.js +++ b/js/id/ui/background.js @@ -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);