提交 73a9f6e7 编写于 作者: P plainheart

fix(tooltip): fix code format and check if dom is supported before `testStyle`.

上级 242c4031
......@@ -20,6 +20,7 @@
import { TooltipOption } from './TooltipModel';
import Model from '../../model/Model';
import { toCamelCase } from '../../util/format';
import env from 'zrender/src/core/env';
/* global document */
......@@ -32,35 +33,38 @@ export function shouldTooltipConfine(tooltipModel: Model<TooltipOption>): boolea
}
function testStyle(styleProps: string[]): string | undefined {
const style = document.documentElement.style;
for (let i = 0, len = styleProps.length; i < len; i++) {
if (styleProps[i] in style) {
return styleProps[i];
}
}
if (!env.domSupported) {
return;
}
const style = document.documentElement.style;
for (let i = 0, len = styleProps.length; i < len; i++) {
if (styleProps[i] in style) {
return styleProps[i];
}
}
}
export const TRANSFORM_VENDOR = testStyle(
['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform']
['transform', 'webkitTransform', 'OTransform', 'MozTransform', 'msTransform']
);
export const TRANSITION_VENDOR = testStyle(
['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']
['webkitTransition', 'transition', 'OTransition', 'MozTransition', 'msTransition']
);
export function toCSSVendorPrefix(styleVendor: string, styleProp: string) {
styleProp = toCamelCase(styleProp, true);
const idx = styleVendor.indexOf(styleProp);
styleVendor = idx === -1
? styleProp
: `-${styleVendor.slice(0, idx)}-${styleProp}`;
return styleVendor.toLowerCase();
styleProp = toCamelCase(styleProp, true);
const idx = styleVendor.indexOf(styleProp);
styleVendor = idx === -1
? styleProp
: `-${styleVendor.slice(0, idx)}-${styleProp}`;
return styleVendor.toLowerCase();
}
export function getComputedStyle(el: HTMLElement, style?: string) {
const stl = (el as any).currentStyle
|| (document.defaultView && document.defaultView.getComputedStyle(el));
return stl
? style ? stl[style] : stl
: null;
const stl = (el as any).currentStyle
|| (document.defaultView && document.defaultView.getComputedStyle(el));
return stl
? style ? stl[style] : stl
: null;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册