Skip to content

Commit

Permalink
Fixes the web UI time-bar not being clickable/draggable on mobile saf…
Browse files Browse the repository at this point in the history
…ari (#553)
  • Loading branch information
doughsay committed May 25, 2023
1 parent 6c04af7 commit 313850e
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions assets/js/hooks/time-bar.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import os from "platform-detect/os.mjs"
import browser from "platform-detect/browser.mjs"

export const TimeBarHook = {
mounted() {
const { duration } = this.el.dataset
Expand All @@ -15,23 +18,31 @@ export const TimeBarHook = {
this.progressBarHoverStyles = this.getHoverStyles(this.progressBar)
this.handleHoverStyles = this.getHoverStyles(this.handle)

this.attach(this.wrapper, "mousedown")
this.attach(window, "mousemove")
this.attach(window, "mouseup")
if (os.ios && browser.safari) {
this.attach(this.wrapper, "mousedown", "touchstart")
this.attach(window, "mousemove", "touchmove")
this.attach(window, "mouseup", "touchend")
} else {
this.attach(this.wrapper, "mousedown")
this.attach(window, "mousemove")
this.attach(window, "mouseup")
}

this.attach(document.body, "mouseleave")
this.attach(window, "resize")
},

attach(target, event) {
const callback = (e) => this[event](e)
attach(target, callbackName, eventName = null) {
const event = eventName || callbackName
const callback = (e) => this[callbackName](e)
target.addEventListener(event, callback)

this.listeners = this.listeners || []
this.listeners.push([target, event, callback])
},

updateState(event) {
const x = event.clientX
const x = os.ios && browser.safari ? event.pageX : event.clientX

this.position = Math.min(x, this.width)
this.ratio = this.position / this.width
Expand Down Expand Up @@ -72,7 +83,7 @@ export const TimeBarHook = {
},

mousedown(event) {
if (event.buttons === 1) {
if (event.type === "touchstart" || event.buttons === 1) {
this.snapshotState()
this.updateState(event)
this.startDragging()
Expand Down

0 comments on commit 313850e

Please sign in to comment.