Skip to content

Commit 89564f1

Browse files
manucorporatadamdbradley
authored andcommitted
feat(feature-detect): detect if backdrop-filter is supported
Currently `backdrop-filter` is only supported by Safari and it allows web developers to implement awesome background blur effects like a native iOS app
1 parent 4009575 commit 89564f1

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

src/util/feature-detect.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11

22
export class FeatureDetect {
3-
private _results: any = {};
3+
private _results: {[featureName: string]: boolean} = {};
44

55
run(window: Window, document: Document) {
66
for (let name in featureDetects) {
77
this._results[name] = featureDetects[name](window, document, document.body);
88
}
99
}
1010

11-
has(featureName: string) {
11+
has(featureName: string): boolean {
1212
return !!this._results[featureName];
1313
}
1414

@@ -18,10 +18,10 @@ export class FeatureDetect {
1818

1919
}
2020

21-
let featureDetects = {};
21+
let featureDetects: {[featureName: string]: Function} = {};
2222

2323

24-
FeatureDetect.add('hairlines', function(window: Window, document: Document, body: HTMLBodyElement) {
24+
FeatureDetect.add('hairlines', function(window: Window, document: Document, body: HTMLBodyElement): boolean {
2525
/**
2626
* Hairline Shim
2727
* Add the "hairline" CSS class name to the body tag
@@ -41,3 +41,18 @@ FeatureDetect.add('hairlines', function(window: Window, document: Document, body
4141
}
4242
return canDo;
4343
});
44+
45+
FeatureDetect.add('backdrop-filter', function(window: Window, document: Document, body: HTMLBodyElement): boolean {
46+
/**
47+
* backdrop-filter Shim
48+
* Checks if css backdrop-filter is implemented by the browser.
49+
*/
50+
let styles = <any>body.style;
51+
let backdrop = styles['backdrop-filter'] !== undefined ||
52+
styles['-webkit-backdrop-filter'] !== undefined;
53+
if (backdrop) {
54+
body.classList.add('backdrop-filter');
55+
}
56+
return backdrop;
57+
});
58+

0 commit comments

Comments
 (0)