From 8f7435f3fc99881cd9ff911531408c9e2c03304a Mon Sep 17 00:00:00 2001 From: David Sevilla Martin Date: Fri, 20 Mar 2020 09:58:33 -0400 Subject: [PATCH] forum: fix post stream scrubber dragging on mobile --- js/src/forum/components/PostStreamScrubber.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/js/src/forum/components/PostStreamScrubber.tsx b/js/src/forum/components/PostStreamScrubber.tsx index aa9e48315..6f120ceac 100644 --- a/js/src/forum/components/PostStreamScrubber.tsx +++ b/js/src/forum/components/PostStreamScrubber.tsx @@ -373,22 +373,24 @@ export default class PostStreamScrubber extends Component { ); } - onmousedown(e) { - this.mouseStart = e.clientY || e.originalEvent.touches[0].clientY; + onmousedown(e: MouseEvent) { + this.mouseStart = window.TouchEvent && e instanceof TouchEvent ? e.touches[0].clientY : e.clientY; this.indexStart = this.index; this.dragging = true; this.stream.paused = true; $('body').css('cursor', 'move'); } - onmousemove(e) { + onmousemove(e: MouseEvent) { if (!this.dragging) return; + let y = window.TouchEvent && e instanceof TouchEvent ? e.touches[0].clientY : e.clientY; + // Work out how much the mouse has moved by - first in pixels, then // convert it to a percentage of the scrollbar's height, and then // finally convert it into an index. Add this delta index onto // the index at which the drag was started, and then scroll there. - const deltaPixels = (e.clientY || e.originalEvent.touches[0].clientY) - this.mouseStart; + const deltaPixels = y - this.mouseStart; const deltaPercent = (deltaPixels / this.$('.Scrubber-scrollbar').outerHeight()) * 100; const deltaIndex = deltaPercent / this.percentPerPost().index || 0; const newIndex = Math.min(this.indexStart + deltaIndex, this.count() - 1);