Commit 356d94fb authored by Mike Bostock's avatar Mike Bostock
Browse files

Merge branch 'fix-multiple-zoom-touchstart' into 3.4.7

parents 6dd366a3 31d0712f
...@@ -1362,7 +1362,7 @@ ...@@ -1362,7 +1362,7 @@
} }
} }
function touchstarted() { function touchstarted() {
var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, target = d3.select(d3.event.target).on(touchmove, moved).on(touchend, ended), subject = d3.select(that).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress(); var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that).on(mousedown, null).on(touchstart, started), dragRestore = d3_event_dragSuppress();
d3_selection_interrupt.call(that); d3_selection_interrupt.call(that);
started(); started();
zoomstarted(dispatch); zoomstarted(dispatch);
...@@ -1375,6 +1375,9 @@ ...@@ -1375,6 +1375,9 @@
return touches; return touches;
} }
function started() { function started() {
var target = d3.event.target;
d3.select(target).on(touchmove, moved).on(touchend, ended);
targets.push(target);
var changed = d3.event.changedTouches; var changed = d3.event.changedTouches;
for (var i = 0, n = changed.length; i < n; ++i) { for (var i = 0, n = changed.length; i < n; ++i) {
locations0[changed[i].identifier] = null; locations0[changed[i].identifier] = null;
...@@ -1423,7 +1426,7 @@ ...@@ -1423,7 +1426,7 @@
return void relocate(); return void relocate();
} }
} }
target.on(zoomName, null); d3.selectAll(targets).on(zoomName, null);
subject.on(mousedown, mousedowned).on(touchstart, touchstarted); subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
dragRestore(); dragRestore();
zoomended(dispatch); zoomended(dispatch);
......
This diff is collapsed.
...@@ -190,7 +190,7 @@ d3.behavior.zoom = function() { ...@@ -190,7 +190,7 @@ d3.behavior.zoom = function() {
zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier,
touchmove = "touchmove" + zoomName, touchmove = "touchmove" + zoomName,
touchend = "touchend" + zoomName, touchend = "touchend" + zoomName,
target = d3.select(d3.event.target).on(touchmove, moved).on(touchend, ended), targets = [],
subject = d3.select(that).on(mousedown, null).on(touchstart, started), // prevent duplicate events subject = d3.select(that).on(mousedown, null).on(touchstart, started), // prevent duplicate events
dragRestore = d3_event_dragSuppress(); dragRestore = d3_event_dragSuppress();
...@@ -210,7 +210,13 @@ d3.behavior.zoom = function() { ...@@ -210,7 +210,13 @@ d3.behavior.zoom = function() {
// Temporarily override touchstart while gesture is active. // Temporarily override touchstart while gesture is active.
function started() { function started() {
// Only track touches started on the target element.
// Listen for touchmove and touchend on the target of touchstart.
var target = d3.event.target;
d3.select(target).on(touchmove, moved).on(touchend, ended);
targets.push(target);
// Only track touches started on the same subject element.
var changed = d3.event.changedTouches; var changed = d3.event.changedTouches;
for (var i = 0, n = changed.length; i < n; ++i) { for (var i = 0, n = changed.length; i < n; ++i) {
locations0[changed[i].identifier] = null; locations0[changed[i].identifier] = null;
...@@ -275,7 +281,7 @@ d3.behavior.zoom = function() { ...@@ -275,7 +281,7 @@ d3.behavior.zoom = function() {
} }
} }
// Otherwise, remove touchmove and touchend listeners. // Otherwise, remove touchmove and touchend listeners.
target.on(zoomName, null); d3.selectAll(targets).on(zoomName, null);
subject.on(mousedown, mousedowned).on(touchstart, touchstarted); subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
dragRestore(); dragRestore();
zoomended(dispatch); zoomended(dispatch);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment