Skip to content

Commit

Permalink
Revert "Revert "Revert "Use passive event listeners instead of `preve…
Browse files Browse the repository at this point in the history
…ntDefault` (mapbox#1146) (h/t @danielsippel)" (mapbox#1158)""

This reverts commit 773abe7.
  • Loading branch information
danielsippel committed Apr 18, 2024
1 parent aa966d9 commit aceb9a2
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export default function(ctx) {
};

events.touchstart = function(event) {
// Prevent emulated mouse events because we will fully handle the touch here.
// This does not stop the touch events from propogating to mapbox though.
event.originalEvent.preventDefault();
if (!ctx.options.touchEnabled) {
return;
}
Expand All @@ -92,6 +95,7 @@ export default function(ctx) {
};

events.touchmove = function(event) {
event.originalEvent.preventDefault();
if (!ctx.options.touchEnabled) {
return;
}
Expand All @@ -101,6 +105,7 @@ export default function(ctx) {
};

events.touchend = function(event) {
event.originalEvent.preventDefault();
if (!ctx.options.touchEnabled) {
return;
}
Expand Down Expand Up @@ -219,9 +224,9 @@ export default function(ctx) {
ctx.map.on('mouseup', events.mouseup);
ctx.map.on('data', events.data);

ctx.map.on('touchmove', events.touchmove, {passive:true});
ctx.map.on('touchstart', events.touchstart, {passive:true});
ctx.map.on('touchend', events.touchend, {passive:true});
ctx.map.on('touchmove', events.touchmove);
ctx.map.on('touchstart', events.touchstart);
ctx.map.on('touchend', events.touchend);

ctx.container.addEventListener('mouseout', events.mouseout);

Expand Down

0 comments on commit aceb9a2

Please sign in to comment.