chore(): add types to Refresher

This commit is contained in:
Adam Bradley
2016-01-14 21:04:20 -06:00
parent 4a9c3a11a6
commit 02626b9489
7 changed files with 71 additions and 56 deletions

View File

@ -51,7 +51,7 @@ export class Animation {
private _finishes: Array<any>; private _finishes: Array<any>;
public isProgress: boolean; public isProgress: boolean;
constructor(ele, opts={}) { constructor(ele?, opts={}) {
this.reset(); this.reset();
this._opts = assign({ this._opts = assign({
@ -524,16 +524,16 @@ export class Animation {
dest._ani = []; dest._ani = [];
for (let i = 0; i < src._chld.length; i++) { for (let i = 0; i < src._chld.length; i++) {
dest.add( copy(new Animation(null), src._chld[i]) ); dest.add( copy(new Animation(), src._chld[i]) );
} }
return dest; return dest;
} }
return copy(new Animation(null), this); return copy(new Animation(), this);
} }
dispose(removeElement) { dispose(removeElement?) {
let i; let i;
for (i = 0; i < this._chld.length; i++) { for (i = 0; i < this._chld.length; i++) {

View File

@ -34,10 +34,11 @@ import {ScrollTo} from '../../animations/scroll-to';
}) })
export class Content extends Ion { export class Content extends Ion {
private _padding: number = 0; private _padding: number = 0;
private _scrollEle: HTMLElement;
private _onScroll: any; private _onScroll: any;
private _scrollTo: ScrollTo; private _scrollTo: ScrollTo;
scrollElement: HTMLElement;
/** /**
* @param {ElementRef} elementRef A reference to the component's DOM element. * @param {ElementRef} elementRef A reference to the component's DOM element.
* @param {Config} config The config object to change content's default settings. * @param {Config} config The config object to change content's default settings.
@ -62,7 +63,7 @@ export class Content extends Ion {
*/ */
ngOnInit() { ngOnInit() {
let self = this; let self = this;
self._scrollEle = self._elementRef.nativeElement.children[0]; self.scrollElement = self._elementRef.nativeElement.children[0];
self._onScroll = function(ev) { self._onScroll = function(ev) {
self._app.setScrolling(); self._app.setScrolling();
@ -70,13 +71,13 @@ export class Content extends Ion {
if (self._config.get('tapPolyfill') === true) { if (self._config.get('tapPolyfill') === true) {
self._zone.runOutsideAngular(function() { self._zone.runOutsideAngular(function() {
self._scrollEle.addEventListener('scroll', self._onScroll); self.scrollElement.addEventListener('scroll', self._onScroll);
}); });
} }
} }
ngOnDestroy() { ngOnDestroy() {
this._scrollEle.removeEventListener('scroll', this._onScroll); this.scrollElement.removeEventListener('scroll', this._onScroll);
} }
/** /**
@ -105,24 +106,24 @@ export class Content extends Ion {
* @returns {Function} A function that removes the scroll handler. * @returns {Function} A function that removes the scroll handler.
*/ */
addScrollEventListener(handler) { addScrollEventListener(handler) {
if (!this._scrollEle) { if (!this.scrollElement) {
return; return;
} }
// ensure we're not creating duplicates // ensure we're not creating duplicates
this._scrollEle.removeEventListener('scroll', handler); this.scrollElement.removeEventListener('scroll', handler);
this._scrollEle.addEventListener('scroll', handler); this.scrollElement.addEventListener('scroll', handler);
return () => { return () => {
this._scrollEle.removeEventListener('scroll', handler); this.scrollElement.removeEventListener('scroll', handler);
} }
} }
onScrollEnd(callback) { onScrollEnd(callback) {
let lastScrollTop = null; let lastScrollTop = null;
let framesUnchanged = 0; let framesUnchanged = 0;
let _scrollEle = this._scrollEle; let _scrollEle = this.scrollElement;
function next() { function next() {
let currentScrollTop = _scrollEle.scrollTop; let currentScrollTop = _scrollEle.scrollTop;
@ -175,15 +176,15 @@ export class Content extends Ion {
* @returns {Function} A function that removes the touchmove handler. * @returns {Function} A function that removes the touchmove handler.
*/ */
addTouchMoveListener(handler) { addTouchMoveListener(handler) {
if (!this._scrollEle) { return; } if (!this.scrollElement) { return; }
// ensure we're not creating duplicates // ensure we're not creating duplicates
this._scrollEle.removeEventListener('touchmove', handler); this.scrollElement.removeEventListener('touchmove', handler);
this._scrollEle.addEventListener('touchmove', handler); this.scrollElement.addEventListener('touchmove', handler);
return () => { return () => {
this._scrollEle.removeEventListener('touchmove', handler); this.scrollElement.removeEventListener('touchmove', handler);
} }
} }
@ -221,7 +222,7 @@ export class Content extends Ion {
this._scrollTo.dispose(); this._scrollTo.dispose();
} }
this._scrollTo = new ScrollTo(this._scrollEle); this._scrollTo = new ScrollTo(this.scrollElement);
return this._scrollTo.start(x, y, duration, tolerance); return this._scrollTo.start(x, y, duration, tolerance);
} }
@ -256,7 +257,7 @@ export class Content extends Ion {
this._scrollTo.dispose(); this._scrollTo.dispose();
} }
this._scrollTo = new ScrollTo(this._scrollEle); this._scrollTo = new ScrollTo(this.scrollElement);
return this._scrollTo.start(0, 0, 300, 0); return this._scrollTo.start(0, 0, 300, 0);
} }
@ -279,7 +280,7 @@ export class Content extends Ion {
* {Number} dimensions.scrollRight scroll scrollLeft + scrollWidth * {Number} dimensions.scrollRight scroll scrollLeft + scrollWidth
*/ */
getContentDimensions() { getContentDimensions() {
let _scrollEle = this._scrollEle; let _scrollEle = this.scrollElement;
let parentElement = _scrollEle.parentElement; let parentElement = _scrollEle.parentElement;
return { return {
@ -311,7 +312,7 @@ export class Content extends Ion {
console.debug('content addScrollPadding', newPadding); console.debug('content addScrollPadding', newPadding);
this._padding = newPadding; this._padding = newPadding;
this._scrollEle.style.paddingBottom = newPadding + 'px'; this.scrollElement.style.paddingBottom = newPadding + 'px';
} }
} }

View File

@ -3,8 +3,10 @@ import {SlideEdgeGesture} from '../../gestures/slide-edge-gesture';
import {assign} from '../../util/util'; import {assign} from '../../util/util';
export class MenuContentGesture extends SlideEdgeGesture { export class MenuContentGesture extends SlideEdgeGesture {
constructor(menu: Menu, targetEl: Element, options = {}) {
constructor(public menu: Menu, targetEl: Element, options = {}) {
super(targetEl, assign({ super(targetEl, assign({
direction: (menu.side === 'left' || menu.side === 'right') ? 'x' : 'y', direction: (menu.side === 'left' || menu.side === 'right') ? 'x' : 'y',
@ -13,7 +15,6 @@ export class MenuContentGesture extends SlideEdgeGesture {
maxEdgeStart: menu.maxEdgeStart || 75 maxEdgeStart: menu.maxEdgeStart || 75
}, options)); }, options));
this.menu = menu;
this.listen(); this.listen();
} }

View File

@ -1,4 +1,4 @@
import {Component, forwardRef, Directive, Host, EventEmitter, ElementRef, NgZone, Input} from 'angular2/core'; import {Component, forwardRef, Directive, Host, EventEmitter, ElementRef, NgZone, Input, Output, Renderer} from 'angular2/core';
import {Ion} from '../ion'; import {Ion} from '../ion';
import {IonicApp} from '../app/app'; import {IonicApp} from '../app/app';
@ -93,11 +93,6 @@ import {MenuType} from './menu-types';
*/ */
@Component({ @Component({
selector: 'ion-menu', selector: 'ion-menu',
defaultInputs: {
'side': 'left',
'menuType': 'reveal'
},
outputs: ['opening'],
host: { host: {
'role': 'navigation', 'role': 'navigation',
'[attr.side]': 'side', '[attr.side]': 'side',
@ -112,7 +107,7 @@ export class Menu extends Ion {
private _gesture: Gesture; private _gesture: Gesture;
private _targetGesture: Gesture; private _targetGesture: Gesture;
private _type: MenuType; private _type: MenuType;
opening: EventEmitter<Menu> = new EventEmitter();
isOpen: boolean = false; isOpen: boolean = false;
isEnabled: boolean = true; isEnabled: boolean = true;
backdrop: MenuBackdrop; backdrop: MenuBackdrop;
@ -124,15 +119,18 @@ export class Menu extends Ion {
@Input() type: string; @Input() type: string;
@Input() maxEdgeStart; @Input() maxEdgeStart;
@Output() opening: EventEmitter<any> = new EventEmitter();
constructor( constructor(
elementRef: ElementRef, private _elementRef: ElementRef,
private _config: Config, private _config: Config,
private app: IonicApp, private _app: IonicApp,
private platform: Platform, private _platform: Platform,
private keyboard: Keyboard, private _renderer: Renderer,
private zone: NgZone private _keyboard: Keyboard,
private _zone: NgZone
) { ) {
super(elementRef); super(_elementRef);
} }
/** /**
@ -150,15 +148,16 @@ export class Menu extends Ion {
if (self.side !== 'left' && self.side !== 'right') { if (self.side !== 'left' && self.side !== 'right') {
self.side = 'left'; self.side = 'left';
} }
self._renderer.setElementAttribute(self._elementRef, 'side', self.side);
if (!self.id) { if (!self.id) {
// Auto register // Auto register
self.id = self.side + 'Menu'; self.id = self.side + 'Menu';
if (self.app.getComponent(self.id)) { if (self._app.getComponent(self.id)) {
// id already exists, make sure this one is unique // id already exists, make sure this one is unique
self.id += (++menuIds); self.id += (++menuIds);
} }
self.app.register(self.id, self); self._app.register(self.id, self);
} }
self._initGesture(); self._initGesture();
@ -180,7 +179,7 @@ export class Menu extends Ion {
* @private * @private
*/ */
_initGesture() { _initGesture() {
this.zone.runOutsideAngular(() => { this._zone.runOutsideAngular(() => {
switch(this.side) { switch(this.side) {
case 'right': case 'right':
this._gesture = new gestures.RightMenuGesture(this); this._gesture = new gestures.RightMenuGesture(this);
@ -203,6 +202,7 @@ export class Menu extends Ion {
type = this._config.get('menuType'); type = this._config.get('menuType');
} }
this.type = type; this.type = type;
this._renderer.setElementAttribute(this._elementRef, 'menuType', type);
} }
/** /**
@ -287,7 +287,7 @@ export class Menu extends Ion {
this.getBackdropElement().classList.add('show-backdrop'); this.getBackdropElement().classList.add('show-backdrop');
this._prevent(); this._prevent();
this.keyboard.close(); this._keyboard.close();
} }
} }
@ -404,7 +404,7 @@ export class Menu extends Ion {
* @private * @private
*/ */
ngOnDestroy() { ngOnDestroy() {
this.app.unregister(this.id); this._app.unregister(this.id);
this._gesture && this._gesture.destroy(); this._gesture && this._gesture.destroy();
this._targetGesture && this._targetGesture.destroy(); this._targetGesture && this._targetGesture.destroy();
this._type && this._type.ngOnDestroy(); this._type && this._type.ngOnDestroy();

View File

@ -1000,7 +1000,7 @@ export class NavController extends Ion {
} }
let viewContainer = this._viewManager.getViewContainer(location); let viewContainer = this._viewManager.getViewContainer(location);
let hostViewRef = let hostViewRef: any =
viewContainer.createHostView(hostProtoViewRef, viewContainer.length, providers); viewContainer.createHostView(hostProtoViewRef, viewContainer.length, providers);
let pageElementRef = this._viewManager.getHostElement(hostViewRef); let pageElementRef = this._viewManager.getHostElement(hostViewRef);
let component = this._viewManager.getComponent(pageElementRef); let component = this._viewManager.getComponent(pageElementRef);

View File

@ -43,13 +43,14 @@ import {isDefined} from '../../util/util';
'</div>' '</div>'
}) })
export class RadioButton { export class RadioButton {
@Input() value: string = ''; labelId: any;
@Input() checked: any = false; @Input() checked: any = false;
@Input() disabled: boolean = false; @Input() disabled: boolean = false;
@Input() id: string; @Input() id: string;
@Output() select: EventEmitter<RadioButton> = new EventEmitter(); @Input() value: string = '';
labelId: any; @Output() select: EventEmitter<RadioButton> = new EventEmitter();
constructor( constructor(
private _form: Form, private _form: Form,
@ -236,8 +237,7 @@ export class RadioGroup {
this._renderer.setElementAttribute(this._elementRef, 'aria-describedby', header.id); this._renderer.setElementAttribute(this._elementRef, 'aria-describedby', header.id);
} }
let buttons = this._buttons.toArray(); this._buttons.toArray().forEach(button => {
for (let button of buttons) {
button.select.subscribe(() => { button.select.subscribe(() => {
this.writeValue(button.value); this.writeValue(button.value);
this.onChange(button.value); this.onChange(button.value);
@ -253,7 +253,7 @@ export class RadioGroup {
this._renderer.setElementAttribute(this._elementRef, 'aria-activedescendant', button.id); this._renderer.setElementAttribute(this._elementRef, 'aria-activedescendant', button.id);
} }
} }
} });
} }
} }

View File

@ -82,7 +82,11 @@ import {raf, ready, CSS} from '../../util/dom';
}) })
export class Refresher { export class Refresher {
private ele: HTMLElement; private ele: HTMLElement;
private _touchMoveListener;
private _touchEndListener;
private _handleScrollListener;
isActive: boolean;
isDragging: boolean = false; isDragging: boolean = false;
isOverscrolling: boolean = false; isOverscrolling: boolean = false;
dragOffset: number = 0; dragOffset: number = 0;
@ -91,6 +95,14 @@ export class Refresher {
activated: boolean = false; activated: boolean = false;
scrollTime: number = 500; scrollTime: number = 500;
canOverscroll: boolean = false; canOverscroll: boolean = false;
startY;
deltaY;
scrollHost;
scrollChild;
showIcon: boolean;
showSpinner: boolean;
isRefreshing: boolean;
isRefreshingTail: boolean;
@Input() pullingIcon: string; @Input() pullingIcon: string;
@Input() pullingText: string; @Input() pullingText: string;
@ -129,12 +141,12 @@ export class Refresher {
}) })
this.showSpinner = !isDefined(this.refreshingIcon) && this.spinner != 'none'; this.showSpinner = !isDefined(this.refreshingIcon) && this.spinner != 'none';
this.showIcon = isDefined(this.refreshingIcon); this.showIcon = isDefined(this.refreshingIcon);
this._touchMoveListener = this._handleTouchMove.bind(this); this._touchMoveListener = this._handleTouchMove.bind(this);
this._touchEndListener = this._handleTouchEnd.bind(this); this._touchEndListener = this._handleTouchEnd.bind(this);
this._handleScrollListener = this._handleScroll.bind(this); this._handleScrollListener = this._handleScroll.bind(this);
sc.addEventListener('touchmove', this._touchMoveListener); sc.addEventListener('touchmove', this._touchMoveListener);
sc.addEventListener('touchend', this._touchEndListener); sc.addEventListener('touchend', this._touchEndListener);
sc.addEventListener('scroll', this._handleScrollListener); sc.addEventListener('scroll', this._handleScrollListener);
@ -143,8 +155,7 @@ export class Refresher {
/** /**
* @private * @private
*/ */
onDehydrate() { ngOnDestroy() {
console.log('DEHYDRATION');
let sc = this.content.scrollElement; let sc = this.content.scrollElement;
sc.removeEventListener('touchmove', this._touchMoveListener); sc.removeEventListener('touchmove', this._touchMoveListener);
sc.removeEventListener('touchend', this._touchEndListener); sc.removeEventListener('touchend', this._touchEndListener);
@ -280,14 +291,14 @@ export class Refresher {
* @param {TODO} duration TODO * @param {TODO} duration TODO
* @param {Function} callback TODO * @param {Function} callback TODO
*/ */
scrollTo(Y, duration, callback) { scrollTo(Y, duration, callback?) {
// scroll animation loop w/ easing // scroll animation loop w/ easing
// credit https://gist.github.com/dezinezync/5487119 // credit https://gist.github.com/dezinezync/5487119
var start = Date.now(), var start = Date.now(),
from = this.lastOverscroll; from = this.lastOverscroll;
if (from === Y) { if (from === Y) {
callback(); callback && callback();
return; /* Prevent scrolling to the Y point if already there */ return; /* Prevent scrolling to the Y point if already there */
} }
@ -304,7 +315,7 @@ export class Refresher {
// fraction based on the easing method // fraction based on the easing method
easedT = easeOutCubic(time); easedT = easeOutCubic(time);
this.overscroll(parseInt((easedT * (Y - from)) + from, 10)); this.overscroll( Math.round((easedT * (Y - from)) + from) );
if (time < 1) { if (time < 1) {
raf(scroll.bind(this)); raf(scroll.bind(this));
@ -354,7 +365,7 @@ export class Refresher {
} }
if (this.isDragging) { if (this.isDragging) {
this.nativescroll(this.scrollHost, parseInt(this.deltaY - this.dragOffset, 10) * -1); this.nativescroll(this.scrollHost, Math.round(this.deltaY - this.dragOffset) * -1);
} }
// if we're not at overscroll 0 yet, 0 out // if we're not at overscroll 0 yet, 0 out
@ -378,8 +389,9 @@ export class Refresher {
} }
this.isDragging = true; this.isDragging = true;
// overscroll according to the user's drag so far // overscroll according to the user's drag so far
this.overscroll(parseInt((this.deltaY - this.dragOffset) / 3, 10)); this.overscroll( Math.round((this.deltaY - this.dragOffset) / 3) );
// Pass an incremental pull amount to the EventEmitter // Pass an incremental pull amount to the EventEmitter
this.pulling.next(this.lastOverscroll); this.pulling.next(this.lastOverscroll);
@ -388,6 +400,7 @@ export class Refresher {
if (!this.activated && this.lastOverscroll > this.ptrThreshold) { if (!this.activated && this.lastOverscroll > this.ptrThreshold) {
this.activated = true; this.activated = true;
raf(this.activate.bind(this)); raf(this.activate.bind(this));
} else if (this.activated && this.lastOverscroll < this.ptrThreshold) { } else if (this.activated && this.lastOverscroll < this.ptrThreshold) {
this.activated = false; this.activated = false;
raf(this.deactivate.bind(this)); raf(this.deactivate.bind(this));