Skip to content

Commit

Permalink
Fixes #20: errors due to vibration in iOS/Safari
Browse files Browse the repository at this point in the history
Also updates CSS to disable user selection of text in webkit browsers,
which require a prefix for user-select.
  • Loading branch information
kflorence committed Mar 1, 2024
1 parent d50916f commit def65f7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/components/interact.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import paper, { Point } from 'paper'
import { Cache } from './cache'
import { EventListeners } from './eventListeners'

const navigator = window.navigator

export class Interact {
#bounds
#cache = new Cache(Object.values(Interact.CacheKeys))
Expand Down Expand Up @@ -162,6 +164,15 @@ export class Interact {
return new Point(event.clientX, event.clientY)
}

static vibrate (pattern = 25) {
if (Interact.canVibrate) {
navigator.vibrate(pattern)
}
}

// WebKit does not support vibration
static canVibrate = typeof navigator.vibrate === 'function'

static CacheKeys = Object.freeze({
Down: 'down',
Move: 'move',
Expand All @@ -176,5 +187,4 @@ export class Interact {

static maxZoom = 2
static minZoom = 0.5
static vibratePattern = 25
}
5 changes: 2 additions & 3 deletions src/components/modifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Item } from './item'

const modifiersImmutable = document.getElementById('modifiers-immutable')
const modifiersMutable = document.getElementById('modifiers-mutable')
const navigator = window.navigator

let uniqueId = 0

Expand Down Expand Up @@ -148,7 +147,7 @@ export class Modifier extends Stateful {
onSelected () {
Modifier.deselect()

navigator.vibrate(Interact.vibratePattern)
Interact.vibrate()

this.update({ selected: true })

Expand All @@ -167,7 +166,7 @@ export class Modifier extends Stateful {
}

onToggle () {
navigator.vibrate(Interact.vibratePattern)
Interact.vibrate()
}

remove () {
Expand Down
8 changes: 8 additions & 0 deletions src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ body > header {
position: relative;
/* Prevent Chrome from trying to open search on tap in mobile. */
user-select: none;
/* For iOS/Safari. */
-webkit-user-select: none;
z-index: 1;
}

Expand Down Expand Up @@ -298,6 +300,8 @@ main {
'GRAD' 0,
'opsz' 24;
user-select: none;
/* For iOS/Safari. */
-webkit-user-select: none;
vertical-align: middle;
}

Expand All @@ -308,6 +312,8 @@ main {
'GRAD' 0,
'opsz' 24;
user-select: none;
/* For iOS/Safari. */
-webkit-user-select: none;
}

.menu {
Expand Down Expand Up @@ -351,6 +357,8 @@ main {

.modifiers {
user-select: none;
/* For iOS/Safari. */
-webkit-user-select: none;
}

.puzzle-error .flex-left,
Expand Down

0 comments on commit def65f7

Please sign in to comment.