Do not use d3.mouse unless needed, instantly exit select.

This commit is contained in:
Tom MacWright
2013-02-08 10:21:04 -05:00
parent 20e1181b7a
commit 4a339ade87
+32 -22
View File
@@ -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);
};