summaryrefslogtreecommitdiff
path: root/client/vendor/util.js
blob: 5d51c34b80d74c6d1eed6ba153c47d528d856892 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const isIphone = (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))
const isIpad = (navigator.userAgent.match(/iPad/i))
const isAndroid = (navigator.userAgent.match(/Android/i))
const isMobile = isIphone || isIpad || isAndroid
const isDesktop = ! isMobile

document.body.classList.add(isMobile ? 'mobile' : 'desktop')

const browser = { isIphone, isIpad, isAndroid, isMobile, isDesktop }

function clamp(n,a,b){ return n<a?a:n<b?n:b }
function mod(n,m){ return n-(m * Math.floor(n/m)) }
function choice (a){ return a[ randint(a.length) ] }
function randint(n){ return  Math.floor(Math.random() * n) }
function randrange(a,b) { return Math.random() * (b-a) + a }
function firstTouch(f){ return e => { e.preventDefault(); f(e.touches[0]) }}

export {
  browser,
  clamp, mod,
  choice, randint, randrange,
  firstTouch,
}