Fix click suppression after dragend in cases where click doesn't fire.

Fixes Issue #1005 for both behavior.zoom and behavior.drag
This commit is contained in:
Dan Tillberg 2013-03-30 00:23:57 +00:00
Родитель 18105839c5
Коммит 636c3dbb6a
3 изменённых файлов: 18 добавлений и 13 удалений

Просмотреть файл

@ -65,18 +65,12 @@ d3.behavior.drag = function() {
// if moved, prevent the mouseup (and possibly click) from propagating
if (moved) {
d3_eventCancel();
if (d3.event.target === eventTarget) w.on("click.drag", click, true);
if (d3.event.target === eventTarget) d3_eventSuppress('click');
}
w .on(touchId != null ? "touchmove.drag-" + touchId : "mousemove.drag", null)
.on(touchId != null ? "touchend.drag-" + touchId : "mouseup.drag", null);
}
// prevent the subsequent click from propagating (e.g., for anchors)
function click() {
d3_eventCancel();
w.on("click.drag", null);
}
}
drag.origin = function(x) {

Просмотреть файл

@ -115,12 +115,7 @@ d3.behavior.zoom = function() {
function mouseup() {
if (moved) d3_eventCancel();
w.on("mousemove.zoom", null).on("mouseup.zoom", null);
if (moved && d3.event.target === eventTarget) w.on("click.zoom", click, true);
}
function click() {
d3_eventCancel();
w.on("click.zoom", null);
if (moved && d3.event.target === eventTarget) d3_eventSuppress('click');
}
}

Просмотреть файл

@ -13,6 +13,22 @@ function d3_eventSource() {
return e;
}
// In some cases, e.g. on dragend of behavior.zoom and behavior.drag, we need
// to suppress an event that fires immediately.
function d3_eventSuppress(name) {
var w = d3.select(d3_window);
function unbind() {
w.on(name + ".suppress", null);
}
w.on(name + ".suppress", function() {
// prevent the subsequent event from propagating (e.g., for anchors)
d3_eventCancel();
unbind();
}, true);
// clear the handler after a 0ms timeout in case it doesn't fire after all
setTimeout(unbind, 0);
}
// Like d3.dispatch, but for custom events abstracting native UI events. These
// events have a target component (such as a brush), a target element (such as
// the svg:g element containing the brush) and the standard arguments `d` (the