Skip to content

Commit

Permalink
Merge pull request #5025 from priyanomi/range-slider-touch-integration
Browse files Browse the repository at this point in the history
Add Touch Support to RangeSlider #1098
  • Loading branch information
archmoj authored Jul 31, 2020
2 parents 0de3bf3 + 6105a07 commit 3d516f0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/components/rangeslider/draw.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,21 +236,24 @@ function setupDragElement(rangeSlider, gd, axisOpts, opts) {
var grabAreaMin = rangeSlider.select('rect.' + constants.grabAreaMinClassName).node();
var grabAreaMax = rangeSlider.select('rect.' + constants.grabAreaMaxClassName).node();

rangeSlider.on('mousedown', function() {
function mouseDownHandler() {
var event = d3.event;
var target = event.target;
var startX = event.clientX;
var startX = event.clientX || event.touches[0].clientX;
var offsetX = startX - rangeSlider.node().getBoundingClientRect().left;
var minVal = opts.d2p(axisOpts._rl[0]);
var maxVal = opts.d2p(axisOpts._rl[1]);

var dragCover = dragElement.coverSlip();

this.addEventListener('touchmove', mouseMove);
this.addEventListener('touchend', mouseUp);
dragCover.addEventListener('mousemove', mouseMove);
dragCover.addEventListener('mouseup', mouseUp);

function mouseMove(e) {
var delta = +e.clientX - startX;
var clientX = e.clientX || e.touches[0].clientX;
var delta = +clientX - startX;
var pixelMin, pixelMax, cursor;

switch(target) {
Expand Down Expand Up @@ -295,9 +298,14 @@ function setupDragElement(rangeSlider, gd, axisOpts, opts) {
function mouseUp() {
dragCover.removeEventListener('mousemove', mouseMove);
dragCover.removeEventListener('mouseup', mouseUp);
this.removeEventListener('touchmove', mouseMove);
this.removeEventListener('touchend', mouseUp);
Lib.removeElement(dragCover);
}
});
}

rangeSlider.on('mousedown', mouseDownHandler);
rangeSlider.on('touchstart', mouseDownHandler);
}

function setDataRange(rangeSlider, gd, axisOpts, opts) {
Expand Down

0 comments on commit 3d516f0

Please sign in to comment.