fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

171 lines
3.5 KiB

7 years ago
// 浏览器相关方法
import { isString } from "../../2.base";
7 years ago
let __isIE;
7 years ago
export function isIE() {
if (!_global.navigator) {
return false;
}
if (!__isIE) {
__isIE = /(msie|trident)/i.test(navigator.userAgent.toLowerCase());
}
7 years ago
return __isIE;
}
7 years ago
let __IEVersion;
7 years ago
export function getIEVersion() {
if (!_global.navigator) {
return 0;
}
if (__IEVersion) {
return __IEVersion;
}
let version = 0;
const agent = navigator.userAgent.toLowerCase();
const v1 = agent.match(/(?:msie\s([\w.]+))/);
const v2 = agent.match(/(?:trident.*rv:([\w.]+))/);
if (v1 && v2 && v1[1] && v2[1]) {
version = Math.max(v1[1] * 1, v2[1] * 1);
} else if (v1 && v1[1]) {
version = v1[1] * 1;
} else if (v2 && v2[1]) {
version = v2[1] * 1;
} else {
version = 0;
}
__IEVersion = version;
7 years ago
return __IEVersion;
}
7 years ago
export function isIE9Below() {
if (!isIE()) {
return false;
}
7 years ago
return getIEVersion() < 9;
}
7 years ago
export function isEdge() {
if (!_global.navigator) {
return false;
}
7 years ago
return /edg/i.test(navigator.userAgent.toLowerCase());
}
7 years ago
export function isChrome() {
if (!_global.navigator) {
return false;
}
7 years ago
return /chrome/i.test(navigator.userAgent.toLowerCase());
}
export function isFireFox() {
if (!_global.navigator) {
return false;
}
return /firefox/i.test(navigator.userAgent.toLowerCase());
}
export function isOpera() {
if (!_global.navigator) {
return false;
}
return /opera/i.test(navigator.userAgent.toLowerCase());
}
export function isSafari() {
if (!_global.navigator) {
return false;
}
return /safari/i.test(navigator.userAgent.toLowerCase()) && !/chrome/i.test(navigator.userAgent.toLowerCase());
}
export function isKhtml() {
if (!_global.navigator) {
return false;
}
return /Konqueror|Safari|KHTML/i.test(navigator.userAgent);
}
export function isMac() {
if (!_global.navigator) {
return false;
}
return /macintosh|mac os x/i.test(navigator.userAgent);
}
export function isWindows() {
if (!_global.navigator) {
7 years ago
return false;
}
return /windows|win32/i.test(navigator.userAgent);
}
export function isSupportCss3(style) {
if (!_global.document) {
return false;
}
const prefix = ["webkit", "Moz", "ms", "o"];
const humpString = [];
const htmlStyle = document.documentElement.style;
let i;
let len;
function _toHumb(string) {
if (!isString(string)) {
return "";
}
return string.replace(/-(\w)/g, ($0, $1) => $1.toUpperCase());
};
for (i = 0; i < prefix.length; i++) {
humpString.push(_toHumb(`${prefix[i]}-${style}`));
}
humpString.push(_toHumb(style));
for (i = 0, len = humpString.length; i < len; i++) {
if (humpString[i] in htmlStyle) {
return true;
}
}
return false;
}
export function getSafariVersion() {
if (!_global.navigator) {
return 0;
}
const agent = navigator.userAgent.toLowerCase();
const version = agent.match(/version\/([\d.]+)/);
if (version && version[1]) {
return version[1] * 1;
}
return 0;
}
export function getMinimumFontSize() {
// not work for firefox
const el = document.createElement("div");
el.style.fontSize = "1px";
document.body.appendChild(el);
const size = getComputedStyle(el).fontSize;
el.remove();
return parseInt(size, 10);
}