fix(sticky-headers): add feature detection

Closes #290
This commit is contained in:
Adam Bradley
2015-10-15 23:24:37 -05:00
parent d3a40aedf3
commit d9e19d38ff
3 changed files with 64 additions and 25 deletions

View File

@ -0,0 +1,51 @@
export class FeatureDetect {
run(window, document) {
this._results = {};
for (let name in featureDetects) {
this._results[name] = featureDetects[name](window, document, document.body);
}
}
has(featureName) {
return !!this._results[featureName];
}
static add(name, fn) {
featureDetects[name] = fn;
}
}
let featureDetects = {};
FeatureDetect.add('positionsticky', function(window, document) {
// css position sticky
let ele = document.createElement('div');
ele.style.cssText = 'position:-webkit-sticky;position:sticky';
return ele.style.position.indexOf('sticky') > -1;
});
FeatureDetect.add('hairlines', function(window, document, body) {
/**
* 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;
});