Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/dragelement/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ var unhover = require('./unhover');
dragElement.unhover = unhover.wrapped;
dragElement.unhoverRaw = unhover.raw;

var supportsPassive = Lib.eventListenerOptionsSupported();

/**
* Abstracts click & drag interactions
*
Expand Down Expand Up @@ -101,7 +103,17 @@ dragElement.init = function init(options) {
element.style.pointerEvents = 'all';

element.onmousedown = onStart;
element.ontouchstart = onStart;

if(!supportsPassive) {
element.ontouchstart = onStart;
}
else {
if(element._ontouchstart) {
element.removeEventListener('touchstart', element._ontouchstart);
}
element._ontouchstart = onStart;
element.addEventListener('touchstart', onStart, {passive: false});
}

function _clampFn(dx, dy, minDrag) {
if(Math.abs(dx) < minDrag) dx = 0;
Expand Down
22 changes: 22 additions & 0 deletions src/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -890,3 +890,25 @@ lib.subplotSort = function(a, b) {
}
return numB - numA;
};

/*
* test if event listener options supported
*/
lib.eventListenerOptionsSupported = function() {
var supported = false;

try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supported = true;
}
});

window.addEventListener('test', null, opts);
window.removeEventListener('test', null, opts);
} catch(e) {
supported = false;
}

return supported;
};
18 changes: 16 additions & 2 deletions src/plots/cartesian/dragbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ var constants = require('./constants');
var MINDRAG = constants.MINDRAG;
var MINZOOM = constants.MINZOOM;

var supportsPassive = Lib.eventListenerOptionsSupported();

// flag for showing "doubleclick to zoom out" only at the beginning
var SHOWZOOMOUTTIP = true;

Expand Down Expand Up @@ -1041,8 +1043,20 @@ function calcLinks(constraintGroups, xIDs, yIDs) {

// still seems to be some confusion about onwheel vs onmousewheel...
function attachWheelEventHandler(element, handler) {
if(element.onwheel !== undefined) element.onwheel = handler;
else if(element.onmousewheel !== undefined) element.onmousewheel = handler;
if(!supportsPassive) {
if(element.onwheel !== undefined) element.onwheel = handler;
else if(element.onmousewheel !== undefined) element.onmousewheel = handler;
}
else {
var wheelEventName = element.onwheel !== undefined ? 'wheel' : 'mousewheel';

if(element._onwheel) {
element.removeEventListener(wheelEventName, element._onwheel);
}
element._onwheel = handler;

element.addEventListener(wheelEventName, handler, {passive: false});
}
}

module.exports = {
Expand Down