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

@@ -1,7 +1,8 @@
import {Directive, ElementRef, Host, Optional} from 'angular2/angular2';
import {Content} from '../content/content';
import {throttle} from '../../util/util';
import {position, offset, CSS} from '../../util/dom';
import {position, offset, CSS, raf} from '../../util/dom';
import {FeatureDetect} from '../../util/feature-detect';
import {IonicConfig} from '../../config/config';
/**
@@ -38,15 +39,16 @@ export class ItemGroupTitle {
* TODO
* @param {ElementRef} elementRef TODO
*/
constructor(elementRef: ElementRef, config: IonicConfig, content: Content) {
constructor(elementRef: ElementRef, config: IonicConfig, content: Content, featureDetect: FeatureDetect) {
this.isSticky = true;
this.content = content;
this.ele = elementRef.nativeElement;
this.parent = this.ele.parentNode;
this.isCssValid = featureDetect.has('positionsticky')
}
onInit() {
if(!this.content) { return; }
if (!this.content || this.isCssValid) { return; }
this.scrollContent = this.content.elementRef.nativeElement.children[0];
@@ -55,7 +57,6 @@ export class ItemGroupTitle {
this.scrollTransition = 0;
this.isSticking = false;
this.scrollContent.addEventListener('scroll', event => this.scrollEvent(event));
this.calculateScrollLimits = scrollTop => {
@@ -98,9 +99,7 @@ export class ItemGroupTitle {
this.applyTransform(element, translateDyPixelsUp);
}
else {
// see http://www.paulirish.com/2011/requestanimationframe-for-smart-animating/
// see http://ionicframework.com/docs/api/utility/ionic.DomUtil/
requestAnimationFrame( a => this.applyTransform(element, translateDyPixelsUp) );
raf( a => this.applyTransform(element, translateDyPixelsUp) );
}
}