Skip to content

Commit

Permalink
feat(feature-detect): detect if backdrop-filter is supported
Browse files Browse the repository at this point in the history
Currently `backdrop-filter` is only supported by Safari and it allows web developers to implement awesome background blur effects like a native iOS app
  • Loading branch information
manucorporat authored and adamdbradley committed Jun 27, 2016
1 parent 4009575 commit 89564f1
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/util/feature-detect.ts
@@ -1,14 +1,14 @@

export class FeatureDetect {
private _results: any = {};
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) {
has(featureName: string): boolean {
return !!this._results[featureName];
}

Expand All @@ -18,10 +18,10 @@ export class FeatureDetect {

}

let featureDetects = {};
let featureDetects: {[featureName: string]: Function} = {};


FeatureDetect.add('hairlines', function(window: Window, document: Document, body: HTMLBodyElement) {
FeatureDetect.add('hairlines', function(window: Window, document: Document, body: HTMLBodyElement): boolean {
/**
* Hairline Shim
* Add the "hairline" CSS class name to the body tag
Expand All @@ -41,3 +41,18 @@ FeatureDetect.add('hairlines', function(window: Window, document: Document, body
}
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;
});

0 comments on commit 89564f1

Please sign in to comment.