diff --git a/css/20_map.css b/css/20_map.css index a85448b9c..2fe35369b 100644 --- a/css/20_map.css +++ b/css/20_map.css @@ -92,6 +92,15 @@ g.vertex.vertex-hover { display: block; } +.mode-draw-area .hover-disabled g.vertex.vertex-hover, +.mode-draw-line .hover-disabled g.vertex.vertex-hover, +.mode-add-area .hover-disabled g.vertex.vertex-hover, +.mode-add-line .hover-disabled g.vertex.vertex-hover, +.mode-add-point .hover-disabled g.vertex.vertex-hover, +.mode-drag-node .hover-disabled g.vertex.vertex-hover { + display: none; +} + g.vertex.related:not(.selected) .shadow, g.vertex.hover:not(.selected) .shadow, g.midpoint.related:not(.selected) .shadow, diff --git a/modules/behavior/hover.js b/modules/behavior/hover.js index 9161bb382..2f13f1072 100644 --- a/modules/behavior/hover.js +++ b/modules/behavior/hover.js @@ -15,7 +15,7 @@ import { utilRebind } from '../util/rebind'; */ export function behaviorHover() { var dispatch = d3.dispatch('hover'), - selection = d3.select(null), + _selection = d3.select(null), buttonDown, altDisables, target; @@ -23,28 +23,36 @@ export function behaviorHover() { function keydown() { if (altDisables && d3.event.keyCode === d3keybinding.modifierCodes.alt) { - dispatch.call('hover', this, null); - selection.selectAll('.hover') + _selection.selectAll('.hover') .classed('hover-suppressed', true) .classed('hover', false); + + _selection + .classed('hover-disabled', true); + + dispatch.call('hover', this, null); } } function keyup() { if (altDisables && d3.event.keyCode === d3keybinding.modifierCodes.alt) { - dispatch.call('hover', this, target ? target.id : null); - selection.selectAll('.hover-suppressed') + _selection.selectAll('.hover-suppressed') .classed('hover-suppressed', false) .classed('hover', true); + + _selection + .classed('hover-disabled', false); + + dispatch.call('hover', this, target ? target.id : null); } } - var hover = function(__) { - selection = __; + var hover = function(selection) { + _selection = selection; - selection + _selection .on('mouseover.hover', mouseover) .on('mouseout.hover', mouseout) .on('mousedown.hover', mousedown); @@ -86,9 +94,9 @@ export function behaviorHover() { if (d === target) return; target = d; - selection.selectAll('.hover') + _selection.selectAll('.hover') .classed('hover', false); - selection.selectAll('.hover-suppressed') + _selection.selectAll('.hover-suppressed') .classed('hover-suppressed', false); if (target instanceof osmEntity) { @@ -102,10 +110,11 @@ export function behaviorHover() { var suppressed = altDisables && d3.event && d3.event.altKey; - selection.selectAll(selector) + _selection.selectAll(selector) .classed(suppressed ? 'hover-suppressed' : 'hover', true); - dispatch.call('hover', this, target.id); + dispatch.call('hover', this, !suppressed && target.id); + } else { dispatch.call('hover', this, null); } @@ -114,13 +123,13 @@ export function behaviorHover() { }; - hover.off = function(selection) { - selection.selectAll('.hover') + hover.off = function() { + _selection.selectAll('.hover') .classed('hover', false); - selection.selectAll('.hover-suppressed') + _selection.selectAll('.hover-suppressed') .classed('hover-suppressed', false); - selection + _selection .on('mouseover.hover', null) .on('mouseout.hover', null) .on('mousedown.hover', null); diff --git a/test/spec/behavior/hover.js b/test/spec/behavior/hover.js index 00686c869..72c36cb82 100644 --- a/test/spec/behavior/hover.js +++ b/test/spec/behavior/hover.js @@ -70,6 +70,12 @@ describe('iD.behaviorHover', function() { expect(container.selectAll('.hover').nodes()).to.have.length(0); expect(container.selectAll('.hover-suppressed').nodes()).to.have.length(1); }); + + it('adds the .hover-disabled class to the surface', function () { + container.call(iD.behaviorHover(context).altDisables(true)); + happen.keydown(window, {keyCode: 18}); + expect(container.classed('hover-disabled')).to.be.true; + }); }); describe('alt keyup', function () { @@ -82,5 +88,12 @@ describe('iD.behaviorHover', function() { expect(container.selectAll('.hover').nodes()).to.have.length(1); expect(container.selectAll('.hover-suppressed').nodes()).to.have.length(0); }); + + it('removes the .hover-disabled class from the surface', function () { + container.call(iD.behaviorHover(context).altDisables(true)); + happen.keydown(window, {keyCode: 18}); + happen.keyup(window, {keyCode: 18}); + expect(container.classed('hover-disabled')).to.be.false; + }); }); });