mirror of
https://github.com/Sped0n/bridget.git
synced 2026-04-19 20:49:30 -07:00
get device type
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
import { imgIndexSpanUpdate } from './indexDisp'
|
import { imgIndexSpanUpdate } from './indexDisp'
|
||||||
import { trackMouseInit } from './trackMouse'
|
import { trackMouseInit } from './desktop'
|
||||||
import { thresholdCtlInit } from './thresholdCtl'
|
import { thresholdCtlInit } from './thresholdCtl'
|
||||||
import { imagesArrayLen } from './dataFetch'
|
import { imagesArrayLen } from './dataFetch'
|
||||||
import { vwRefreshInit } from './overlay'
|
import { vwRefreshInit } from './overlay'
|
||||||
import { preloader } from './imageCache'
|
import { preloader } from './imageCache'
|
||||||
|
import { getDeviceType } from './utils'
|
||||||
|
|
||||||
function init(): void {
|
function desktopInit(): void {
|
||||||
preloader(0)
|
preloader(0)
|
||||||
vwRefreshInit()
|
vwRefreshInit()
|
||||||
imgIndexSpanUpdate(0, imagesArrayLen)
|
imgIndexSpanUpdate(0, imagesArrayLen)
|
||||||
@@ -13,4 +14,8 @@ function init(): void {
|
|||||||
trackMouseInit()
|
trackMouseInit()
|
||||||
}
|
}
|
||||||
|
|
||||||
init()
|
function mobileInit(): void {
|
||||||
|
console.log('mobile')
|
||||||
|
}
|
||||||
|
|
||||||
|
getDeviceType().mobile ? mobileInit() : desktopInit()
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ export interface imgElement {
|
|||||||
bgStyle: string
|
bgStyle: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface deviceType {
|
||||||
|
mobile: boolean
|
||||||
|
tablet: boolean
|
||||||
|
desktop: boolean
|
||||||
|
}
|
||||||
|
|
||||||
// cache a xy position to array
|
// cache a xy position to array
|
||||||
export const styleCache = (
|
export const styleCache = (
|
||||||
x: number,
|
x: number,
|
||||||
@@ -129,3 +135,19 @@ export function preloadImage(src: string): void {
|
|||||||
const cache = new Image()
|
const cache = new Image()
|
||||||
cache.src = src
|
cache.src = src
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const getDeviceType = (): deviceType => {
|
||||||
|
const ua: string = navigator.userAgent
|
||||||
|
const result: deviceType = { mobile: false, tablet: false, desktop: false }
|
||||||
|
if (/(tablet|ipad|playbook|silk)|(android(?!.*mobi))/i.test(ua)) {
|
||||||
|
result.mobile = true
|
||||||
|
result.tablet = true
|
||||||
|
} else if (
|
||||||
|
/Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Kindle|Silk-Accelerated|(hpw|web)OS|Opera M(obi|ini)/.test(
|
||||||
|
ua
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
result.mobile = true
|
||||||
|
} else result.desktop = true
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user