web-apps/apps/common/mobile/utils/device.jsx

53 lines
1.4 KiB
React
Raw Normal View History

2020-10-14 08:57:15 +00:00
import React from 'react';
import { f7 } from 'framework7-react';
2021-01-24 21:30:49 +00:00
import { Dom7 } from 'framework7'
2020-10-14 08:57:15 +00:00
class WrapDevice {
2020-10-14 08:57:15 +00:00
constructor(){
const ua = navigator.userAgent,
isMobile = /Mobile(\/|\s|;)/.test(ua);
this.isPhone = /(iPhone|iPod)/.test(ua) ||
2021-09-06 16:28:09 +00:00
(!/(Silk)/.test(ua) && (/(Android)/.test(ua) && !/Galaxy Tab S6|SCH-I800|Lenovo YT-X705X/.test(ua) && (/(Android 2)/.test(ua) || isMobile))) ||
2020-10-14 08:57:15 +00:00
(/(BlackBerry|BB)/.test(ua) && isMobile) ||
/(Windows Phone)/.test(ua);
this.isTablet = !this.isPhone && (/iPad/.test(ua) || /Android/.test(ua) || /(RIM Tablet OS)/.test(ua) ||
(/MSIE 10/.test(ua) && /; Touch/.test(ua)));
}
initDom() {
const $$ = Dom7;
if ( this.sailfish ) {
$$('html').addClass('sailfish');
}
$$('html').addClass(this.phone ? 'phone' : 'tablet');
// $$(window).on('resize', _.bind(this.onWindowResize, this));
}
2020-10-14 08:57:15 +00:00
get phone() {
return this.isPhone
}
get tablet() {
return this.isTablet
}
get sailfish() {
return /Sailfish/.test(navigator.userAgent) || /Jolla/.test(navigator.userAgent);
}
get android() {
return f7.device.android;
}
get ios() {
return f7.device.ios;
}
}
const device = new WrapDevice();
2020-10-14 08:57:15 +00:00
export {device as Device};