Skip to content

Commit d3a7eab

Browse files
authored
Merge pull request #2296 from plotly/prevent-mobile-panning
Panning in mobile devices
2 parents 665e071 + d14318d commit d3a7eab

File tree

12 files changed

+241
-201
lines changed

12 files changed

+241
-201
lines changed

package-lock.json

+47-111
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
"gl-surface3d": "^1.3.4",
8686
"glslify": "^6.1.0",
8787
"has-hover": "^1.0.1",
88+
"has-passive-events": "^1.0.0",
8889
"kdgrass": "^1.0.1",
8990
"mapbox-gl": "^0.22.0",
9091
"matrix-camera-controller": "^2.1.3",
@@ -117,8 +118,8 @@
117118
"browserify-transform-tools": "^1.7.0",
118119
"check-node-version": "^3.2.0",
119120
"deep-equal": "^1.0.1",
120-
"ecstatic": "^3.1.1",
121-
"eslint": "^4.16.0",
121+
"ecstatic": "^3.2.0",
122+
"eslint": "^4.17.0",
122123
"falafel": "^2.0.0",
123124
"fs-extra": "^2.0.0",
124125
"fuse.js": "^3.2.0",
@@ -137,7 +138,7 @@
137138
"karma-jasmine-spec-tags": "^1.0.1",
138139
"karma-spec-reporter": "0.0.32",
139140
"karma-verbose-reporter": "0.0.6",
140-
"madge": "^3.0.0",
141+
"madge": "^3.0.1",
141142
"minify-stream": "^1.1.0",
142143
"minimist": "^1.2.0",
143144
"node-sass": "^4.7.2",

src/components/dragelement/index.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
var mouseOffset = require('mouse-event-offset');
1313
var hasHover = require('has-hover');
14+
var supportsPassive = require('has-passive-events');
1415

1516
var Plotly = require('../../plotly');
1617
var Lib = require('../../lib');
@@ -27,7 +28,6 @@ var unhover = require('./unhover');
2728
dragElement.unhover = unhover.wrapped;
2829
dragElement.unhoverRaw = unhover.raw;
2930

30-
var supportsPassive = Lib.eventListenerOptionsSupported();
3131

3232
/**
3333
* Abstracts click & drag interactions
@@ -124,6 +124,8 @@ dragElement.init = function init(options) {
124124
var clampFn = options.clampFn || _clampFn;
125125

126126
function onStart(e) {
127+
e.preventDefault();
128+
127129
// make dragging and dragged into properties of gd
128130
// so that others can look at and modify them
129131
gd._dragged = false;
@@ -164,10 +166,12 @@ dragElement.init = function init(options) {
164166
document.addEventListener('touchmove', onMove);
165167
document.addEventListener('touchend', onDone);
166168

167-
return Lib.pauseEvent(e);
169+
return;
168170
}
169171

170172
function onMove(e) {
173+
e.preventDefault();
174+
171175
var offset = pointerOffset(e);
172176
var minDrag = options.minDrag || constants.MINDRAG;
173177
var dxdy = clampFn(offset[0] - startX, offset[1] - startY, minDrag);
@@ -181,7 +185,7 @@ dragElement.init = function init(options) {
181185

182186
if(gd._dragged && options.moveFn && !rightClick) options.moveFn(dx, dy);
183187

184-
return Lib.pauseEvent(e);
188+
return;
185189
}
186190

187191
function onDone(e) {
@@ -190,6 +194,8 @@ dragElement.init = function init(options) {
190194
document.removeEventListener('touchmove', onMove);
191195
document.removeEventListener('touchend', onDone);
192196

197+
e.preventDefault();
198+
193199
if(hasHover) {
194200
Lib.removeElement(dragCover);
195201
}
@@ -246,7 +252,7 @@ dragElement.init = function init(options) {
246252

247253
gd._dragged = false;
248254

249-
return Lib.pauseEvent(e);
255+
return;
250256
}
251257
};
252258

src/lib/index.js

-36
Original file line numberDiff line numberDiff line change
@@ -150,20 +150,6 @@ lib.swapAttrs = function(cont, attrList, part1, part2) {
150150
}
151151
};
152152

153-
/**
154-
* to prevent event bubbling, in particular text selection during drag.
155-
* see http://stackoverflow.com/questions/5429827/
156-
* how-can-i-prevent-text-element-selection-with-cursor-drag
157-
* for maximum effect use:
158-
* return pauseEvent(e);
159-
*/
160-
lib.pauseEvent = function(e) {
161-
if(e.stopPropagation) e.stopPropagation();
162-
if(e.preventDefault) e.preventDefault();
163-
e.cancelBubble = true;
164-
return false;
165-
};
166-
167153
/**
168154
* SVG painter's algo worked around with reinsertion
169155
*/
@@ -890,25 +876,3 @@ lib.subplotSort = function(a, b) {
890876
}
891877
return numB - numA;
892878
};
893-
894-
/*
895-
* test if event listener options supported
896-
*/
897-
lib.eventListenerOptionsSupported = function() {
898-
var supported = false;
899-
900-
try {
901-
var opts = Object.defineProperty({}, 'passive', {
902-
get: function() {
903-
supported = true;
904-
}
905-
});
906-
907-
window.addEventListener('test', null, opts);
908-
window.removeEventListener('test', null, opts);
909-
} catch(e) {
910-
supported = false;
911-
}
912-
913-
return supported;
914-
};

0 commit comments

Comments
 (0)