diff --git a/js/id/behavior/select.js b/js/id/behavior/select.js index 5df11b91f..32e246e98 100644 --- a/js/id/behavior/select.js +++ b/js/id/behavior/select.js @@ -8,7 +8,7 @@ iD.behavior.Select = function(context) { function click(event) { d3.event = event; - var datum = d3.select(d3.event.target).datum(); + var datum = d3.event.target.__data__; if (datum instanceof iD.Entity) { if (d3.event.shiftKey) { context.enter(iD.modes.Select(context, context.selection().concat([datum.id]))); @@ -21,41 +21,51 @@ iD.behavior.Select = function(context) { } function mousedown() { - pos = d3.mouse(context.surface().node()); - selection - .on('mousemove.select', mousemove) - .on('touchmove.select', mousemove); + var datum = d3.event.target.__data__; + if (datum instanceof iD.Entity) { + pos = [d3.event.x, d3.event.y]; + selection + .on('mousemove.select', mousemove) + .on('touchmove.select', mousemove); - // we've seen a mousedown within 400ms of this one, so ignore - // both because they will be a double click - if (timeout !== null) { - window.clearTimeout(timeout); - selection.on('mousemove.select', null); - timeout = null; + // we've seen a mousedown within 400ms of this one, so ignore + // both because they will be a double click + if (timeout !== null) { + window.clearTimeout(timeout); + selection.on('mousemove.select', null); + timeout = null; + } else { + // queue the click handler to fire in 400ms if no other clicks + // are detected + timeout = window.setTimeout((function(event) { + return function() { + click(event); + timeout = null; + selection.on('mousemove.select', null); + }; + // save the event for the click handler + })(d3.event), 200); + } } else { - // queue the click handler to fire in 400ms if no other clicks - // are detected - timeout = window.setTimeout((function(event) { - return function() { - click(event); - timeout = null; - selection.on('mousemove.select', null); - }; - // save the event for the click handler - })(d3.event), 200); + context.enter(iD.modes.Browse(context)); } } // allow mousemoves to cancel the click function mousemove() { - if (iD.geo.dist(d3.mouse(context.surface().node()), pos) > 4) { + if (iD.geo.dist([d3.event.x, d3.event.y], pos) > 4) { window.clearTimeout(timeout); timeout = null; } } + function mouseup() { + selection.on('mousemove.select', null); + } + selection .on('mousedown.select', mousedown) + .on('mouseup.select', mouseup) .on('touchstart.select', mousedown); };