2015-06-12 11:31:18 -04:00
|
|
|
/**
|
|
|
|
* @file browser.js
|
|
|
|
*/
|
2015-05-03 16:12:38 -07:00
|
|
|
import document from 'global/document';
|
|
|
|
import window from 'global/window';
|
|
|
|
|
2016-08-05 14:38:42 -04:00
|
|
|
const USER_AGENT = window.navigator && window.navigator.userAgent || "";
|
2015-08-21 17:43:07 -04:00
|
|
|
const webkitVersionMap = (/AppleWebKit\/([\d.]+)/i).exec(USER_AGENT);
|
|
|
|
const appleWebkitVersion = webkitVersionMap ? parseFloat(webkitVersionMap.pop()) : null;
|
2015-05-03 16:12:38 -07:00
|
|
|
|
2015-06-12 11:31:18 -04:00
|
|
|
/*
|
2015-05-03 16:12:38 -07:00
|
|
|
* Device is an iPhone
|
2015-06-12 11:31:18 -04:00
|
|
|
*
|
2015-05-03 16:12:38 -07:00
|
|
|
* @type {Boolean}
|
|
|
|
* @constant
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
export const IS_IPAD = (/iPad/i).test(USER_AGENT);
|
2016-02-04 12:32:33 -05:00
|
|
|
|
|
|
|
// The Facebook app's UIWebView identifies as both an iPhone and iPad, so
|
|
|
|
// to identify iPhones, we need to exclude iPads.
|
|
|
|
// http://artsy.github.io/blog/2012/10/18/the-perils-of-ios-user-agent-sniffing/
|
|
|
|
export const IS_IPHONE = (/iPhone/i).test(USER_AGENT) && !IS_IPAD;
|
2015-05-03 16:12:38 -07:00
|
|
|
export const IS_IPOD = (/iPod/i).test(USER_AGENT);
|
|
|
|
export const IS_IOS = IS_IPHONE || IS_IPAD || IS_IPOD;
|
|
|
|
|
2016-07-25 09:49:38 -04:00
|
|
|
export const IOS_VERSION = (function() {
|
2016-08-03 15:29:12 -04:00
|
|
|
const match = USER_AGENT.match(/OS (\d+)_/i);
|
2016-07-25 09:49:38 -04:00
|
|
|
|
|
|
|
if (match && match[1]) {
|
|
|
|
return match[1];
|
|
|
|
}
|
2016-08-05 14:38:42 -04:00
|
|
|
return null;
|
2016-07-25 09:49:38 -04:00
|
|
|
}());
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
export const IS_ANDROID = (/Android/i).test(USER_AGENT);
|
|
|
|
export const ANDROID_VERSION = (function() {
|
|
|
|
// This matches Android Major.Minor.Patch versions
|
|
|
|
// ANDROID_VERSION is Major.Minor as a Number, if Minor isn't available, then only Major is returned
|
2016-08-03 15:29:12 -04:00
|
|
|
const match = USER_AGENT.match(/Android (\d+)(?:\.(\d+))?(?:\.(\d+))*/i);
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
if (!match) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-08-03 15:29:12 -04:00
|
|
|
const major = match[1] && parseFloat(match[1]);
|
|
|
|
const minor = match[2] && parseFloat(match[2]);
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
if (major && minor) {
|
|
|
|
return parseFloat(match[1] + '.' + match[2]);
|
|
|
|
} else if (major) {
|
|
|
|
return major;
|
|
|
|
}
|
2016-07-25 09:49:38 -04:00
|
|
|
return null;
|
|
|
|
}());
|
|
|
|
|
2015-05-03 16:12:38 -07:00
|
|
|
// Old Android is defined as Version older than 2.3, and requiring a webkit version of the android browser
|
|
|
|
export const IS_OLD_ANDROID = IS_ANDROID && (/webkit/i).test(USER_AGENT) && ANDROID_VERSION < 2.3;
|
2015-08-21 17:43:07 -04:00
|
|
|
export const IS_NATIVE_ANDROID = IS_ANDROID && ANDROID_VERSION < 5 && appleWebkitVersion < 537;
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
export const IS_FIREFOX = (/Firefox/i).test(USER_AGENT);
|
2016-04-19 15:02:53 -04:00
|
|
|
export const IS_EDGE = (/Edge/i).test(USER_AGENT);
|
|
|
|
export const IS_CHROME = !IS_EDGE && (/Chrome/i).test(USER_AGENT);
|
2015-05-03 16:12:38 -07:00
|
|
|
export const IS_IE8 = (/MSIE\s8\.0/).test(USER_AGENT);
|
2016-07-25 09:49:38 -04:00
|
|
|
export const IE_VERSION = (function(result) {
|
2016-07-18 14:32:31 -04:00
|
|
|
return result && parseFloat(result[1]);
|
2016-07-25 09:49:38 -04:00
|
|
|
}((/MSIE\s(\d+)\.\d/).exec(USER_AGENT)));
|
2015-05-03 16:12:38 -07:00
|
|
|
|
|
|
|
export const TOUCH_ENABLED = !!(('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch);
|
|
|
|
export const BACKGROUND_SIZE_SUPPORTED = 'backgroundSize' in document.createElement('video').style;
|