62 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-02-19 18:57:07 -05:00
'use strict'
2019-07-02 03:10:25 -04:00
2020-02-19 18:57:07 -05:00
import detectPassiveEvents from 'detect-passive-events'
2020-05-06 00:33:54 -04:00
import {
BREAKPOINT_EXTRA_LARGE,
BREAKPOINT_LARGE,
BREAKPOINT_MEDIUM,
BREAKPOINT_SMALL,
BREAKPOINT_EXTRA_SMALL,
} from '../constants'
2020-02-19 18:57:07 -05:00
2020-03-24 23:08:43 -04:00
export function isMobile(width) {
return width <= BREAKPOINT_EXTRA_SMALL
2020-03-24 23:08:43 -04:00
}
2020-02-19 18:57:07 -05:00
export function breakpointExtraLarge(width) {
return width > BREAKPOINT_EXTRA_LARGE
}
export function breakpointLarge(width) {
2020-04-09 15:18:14 -04:00
return width < BREAKPOINT_LARGE
2020-02-19 18:57:07 -05:00
}
export function breakpointMedium(width) {
2020-04-09 15:18:14 -04:00
return width < BREAKPOINT_MEDIUM
2020-02-19 18:57:07 -05:00
}
export function breakpointSmall(width) {
2020-04-09 15:18:14 -04:00
return width < BREAKPOINT_SMALL
2020-02-19 18:57:07 -05:00
}
export function breakpointExtraSmall(width) {
return width < BREAKPOINT_EXTRA_SMALL
}
2020-03-24 23:08:43 -04:00
export const getWindowDimension = () => {
const width = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth
const height = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
2020-04-07 21:06:59 -04:00
2020-03-24 23:08:43 -04:00
return { width, height }
2020-02-19 18:57:07 -05:00
}
2019-07-02 03:10:25 -04:00
2020-02-19 18:57:07 -05:00
const iOS = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream
2019-07-02 03:10:25 -04:00
2020-02-19 18:57:07 -05:00
let userTouching = false
2020-04-07 21:06:59 -04:00
const listenerOptions = detectPassiveEvents.hasSupport ? { passive: true } : false
2019-07-02 03:10:25 -04:00
function touchListener() {
2020-02-19 18:57:07 -05:00
userTouching = true
window.removeEventListener('touchstart', touchListener, listenerOptions)
2019-07-02 03:10:25 -04:00
}
2020-02-19 18:57:07 -05:00
window.addEventListener('touchstart', touchListener, listenerOptions)
2019-07-02 03:10:25 -04:00
export function isUserTouching() {
2020-02-19 18:57:07 -05:00
return userTouching
2019-07-02 03:10:25 -04:00
}
export function isIOS() {
2020-02-19 18:57:07 -05:00
return iOS
}