forked from ionic-team/ionic-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfeature-detect.ts
More file actions
58 lines (47 loc) · 1.51 KB
/
feature-detect.ts
File metadata and controls
58 lines (47 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
export class FeatureDetect {
private _results: {[featureName: string]: boolean} = {};
run(window: Window, document: Document) {
for (let name in featureDetects) {
this._results[name] = featureDetects[name](window, document, document.body);
}
}
has(featureName: string): boolean {
return !!this._results[featureName];
}
static add(name: string, fn: any) {
featureDetects[name] = fn;
}
}
let featureDetects: {[featureName: string]: Function} = {};
FeatureDetect.add('hairlines', function(window: Window, document: Document, body: HTMLBodyElement): boolean {
/**
* Hairline Shim
* Add the "hairline" CSS class name to the body tag
* if the browser supports subpixels.
*/
let canDo = false;
if (window.devicePixelRatio >= 2) {
var hairlineEle = document.createElement('div');
hairlineEle.style.border = '.5px solid transparent';
body.appendChild(hairlineEle);
if (hairlineEle.offsetHeight === 1) {
body.classList.add('hairlines');
canDo = true;
}
body.removeChild(hairlineEle);
}
return canDo;
});
FeatureDetect.add('backdrop-filter', function(window: Window, document: Document, body: HTMLBodyElement): boolean {
/**
* backdrop-filter Shim
* Checks if css backdrop-filter is implemented by the browser.
*/
let styles = <any>body.style;
let backdrop = styles['backdrop-filter'] !== undefined ||
styles['-webkit-backdrop-filter'] !== undefined;
if (backdrop) {
body.classList.add('backdrop-filter');
}
return backdrop;
});