@logo-elements/component-base
Version:
A set of mixins used by Logo Elements which is extended from Vaadin components.
40 lines (28 loc) • 1.26 kB
JavaScript
/**
* @license
* Copyright LOGO YAZILIM SANAYİ VE TİCARET A.Ş.
*
* Save to the extent permitted by law, you may not use, copy, modify,
* distribute or create derivative works of this material or any part
* of it without the prior written consent of LOGO YAZILIM SANAYİ VE TİCARET A.Ş. Limited.
* Any reproduction of this material must contain this notice.
*/
const testUserAgent = (regexp) => regexp.test(navigator.userAgent);
const testPlatform = (regexp) => regexp.test(navigator.platform);
const testVendor = (regexp) => regexp.test(navigator.vendor);
export const isAndroid = testUserAgent(/Android/);
export const isChrome = testUserAgent(/Chrome/) && testVendor(/Google Inc/);
export const isFirefox = testUserAgent(/Firefox/);
// iPadOS 13 lies and says it's a Mac, but we can distinguish by detecting touch support.
export const isIPad = testPlatform(/^iPad/) || (testPlatform(/^Mac/) && navigator.maxTouchPoints > 1);
export const isIPhone = testPlatform(/^iPhone/);
export const isIOS = isIPhone || isIPad;
export const isSafari = testUserAgent(/^((?!chrome|android).)*safari/i);
export const isTouch = (() => {
try {
document.createEvent('TouchEvent');
return true;
} catch (e) {
return false;
}
})();