chore(): fix typescript errors

This commit is contained in:
Adam Bradley
2016-01-11 21:10:19 -06:00
parent 29c572d41f
commit 44cbbd286b
7 changed files with 83 additions and 65 deletions

View File

@ -38,11 +38,11 @@ export class ItemSlidingGesture extends DragGesture {
};
}
onDragStart(ev) {
onDragStart(ev): boolean {
let itemContainerEle = getItemConatiner(ev.target);
if (!itemContainerEle) {
console.debug('onDragStart, no itemContainerEle');
return;
return false;
}
this.closeOpened(itemContainerEle);
@ -63,6 +63,8 @@ export class ItemSlidingGesture extends DragGesture {
this.set(itemContainerEle, 'startX', ev.center[this.direction]);
this.dragEnded = false;
return true;
}
onDrag(ev) {

View File

@ -3,6 +3,8 @@ import {defaults} from '../util';
export class DragGesture extends Gesture {
public dragging: boolean;
constructor(element, opts = {}) {
defaults(opts, {});
super(element, opts);
@ -29,11 +31,9 @@ export class DragGesture extends Gesture {
this.onDragEnd(ev);
this.dragging = false;
});
//this.hammertime.get('pan').set(this._options);
}
onDrag() {}
onDragStart() {}
onDragEnd() {}
onDrag(ev: any): boolean { return true; }
onDragStart(ev: any): boolean { return true; }
onDragEnd(ev: any): void {}
}

View File

@ -1,5 +1,5 @@
import {defaults, assign} from '../util';
import {Hammer} from './hammer';
import {Hammer, DIRECTION_HORIZONTAL, DIRECTION_VERTICAL} from './hammer';
/**
* A gesture recognizer class.
@ -9,8 +9,12 @@ import {Hammer} from './hammer';
export class Gesture {
public element: HTMLElement;
public direction: any;
private _hammer: any;
private _options: any;
private _callbacks: any = {};
constructor(element, opts = {}) {
constructor(element, opts: any = {}) {
defaults(opts, {
domEvents: true
});
@ -19,12 +23,10 @@ export class Gesture {
// Map 'x' or 'y' string to hammerjs opts
this.direction = opts.direction || 'x';
opts.direction = this.direction === 'x' ?
Hammer.DIRECTION_HORIZONTAL :
Hammer.DIRECTION_VERTICAL;
DIRECTION_HORIZONTAL :
DIRECTION_VERTICAL;
this._options = opts;
this._callbacks = {};
}
options(opts = {}) {
@ -33,30 +35,30 @@ export class Gesture {
on(type, cb) {
if(type == 'pinch' || type == 'rotate') {
this.hammertime.get('pinch').set({enable: true});
this._hammer.get('pinch').set({enable: true});
}
this.hammertime.on(type, cb);
this._hammer.on(type, cb);
(this._callbacks[type] || (this._callbacks[type] = [])).push(cb);
}
off(type, cb) {
this.hammertime.off(type, this._callbacks[type] ? cb : null);
this._hammer.off(type, this._callbacks[type] ? cb : null);
}
listen() {
this.hammertime = new Hammer(this.element, this._options);
this._hammer = Hammer(this.element, this._options);
}
unlisten() {
if (this.hammertime) {
if (this._hammer) {
for (let type in this._callbacks) {
for (let i = 0; i < this._callbacks[type].length; i++) {
this.hammertime.off(type, this._callbacks[type]);
this._hammer.off(type, this._callbacks[type]);
}
}
this.hammertime.destroy();
this.hammertime = null;
this._callbacks = {}
this._hammer.destroy();
this._hammer = null;
this._callbacks = {};
}
}

View File

@ -1,14 +1,17 @@
import {assign} from '../util/util';
const win: any = window;
const doc: any = document;
/*! Hammer.JS - v2.0.6 - 2015-12-23
* http://hammerjs.github.io/
*
* Copyright (c) 2015 Jorik Tangelder;
* Licensed under the license */
var VENDOR_PREFIXES = ['', 'webkit', 'Moz', 'MS', 'ms', 'o'];
var TEST_ELEMENT = document.createElement('div');
var TEST_ELEMENT = doc.createElement('div');
var TYPE_FUNCTION = 'function';
@ -50,7 +53,7 @@ function invokeArrayArg(arg, fn, context) {
* @param {Function} iterator
* @param {Object} context
*/
function each(obj, iterator, context) {
function each(obj, iterator, context?) {
var i;
if (!obj) {
@ -194,7 +197,7 @@ function splitStr(str) {
* @param {String} [findByKey]
* @return {Boolean|Number} false when not found, or the index
*/
function inArray(src, find, findByKey) {
function inArray(src, find, findByKey?) {
if (src.indexOf && !findByKey) {
return src.indexOf(find);
} else {
@ -244,7 +247,7 @@ function uniqueArray(src, key, sort) {
results = results.sort();
} else {
results = results.sort(function sortUniqueArray(a, b) {
return a[key] > b[key];
return a[key] > b[key] ? 1 : 0;
});
}
}
@ -318,8 +321,8 @@ var DIRECTION_RIGHT = 4;
var DIRECTION_UP = 8;
var DIRECTION_DOWN = 16;
var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
export var DIRECTION_HORIZONTAL = DIRECTION_LEFT | DIRECTION_RIGHT;
export var DIRECTION_VERTICAL = DIRECTION_UP | DIRECTION_DOWN;
var DIRECTION_ALL = DIRECTION_HORIZONTAL | DIRECTION_VERTICAL;
var PROPS_XY = ['x', 'y'];
@ -642,7 +645,7 @@ function getDirection(x, y) {
* @param {Array} [props] containing x and y keys
* @return {Number} distance
*/
function getDistance(p1, p2, props) {
function getDistance(p1, p2, props?) {
if (!props) {
props = PROPS_XY;
}
@ -659,7 +662,7 @@ function getDistance(p1, p2, props) {
* @param {Array} [props] containing x and y keys
* @return {Number} angle
*/
function getAngle(p1, p2, props) {
function getAngle(p1, p2, props?) {
if (!props) {
props = PROPS_XY;
}
@ -703,7 +706,7 @@ var MOUSE_WINDOW_EVENTS = 'mousemove mouseup';
* @constructor
* @extends Input
*/
function MouseInput() {
function MouseInput(manager: any, handler: any) {
this.evEl = MOUSE_ELEMENT_EVENTS;
this.evWin = MOUSE_WINDOW_EVENTS;
@ -768,7 +771,7 @@ var POINTER_ELEMENT_EVENTS = 'pointerdown';
var POINTER_WINDOW_EVENTS = 'pointermove pointerup pointercancel';
// IE10 has prefixed support, and case-sensitive
if (window.MSPointerEvent && !window.PointerEvent) {
if (win.MSPointerEvent && !win.PointerEvent) {
POINTER_ELEMENT_EVENTS = 'MSPointerDown';
POINTER_WINDOW_EVENTS = 'MSPointerMove MSPointerUp MSPointerCancel';
}
@ -920,7 +923,7 @@ var TOUCH_TARGET_EVENTS = 'touchstart touchmove touchend touchcancel';
* @constructor
* @extends Input
*/
function TouchInput() {
function TouchInput(manager: any, handler: any) {
this.evTarget = TOUCH_TARGET_EVENTS;
this.targetIds = {};
@ -2001,20 +2004,20 @@ inherit(TapRecognizer, Recognizer, {
*/
function Hammer(element, options) {
options = options || {};
options.recognizers = ifUndefined(options.recognizers, Hammer.defaults.preset);
options.recognizers = ifUndefined(options.recognizers, _defaults.preset);
return new Manager(element, options);
}
/**
* @const {string}
*/
Hammer.VERSION = '2.0.6';
var VERSION = '2.0.6';
/**
* default settings
* @namespace
*/
Hammer.defaults = {
var _defaults = {
/**
* set if DOM events are being triggered.
* But this is slower and unused by simple implementations, so disabled by default.
@ -2132,7 +2135,7 @@ var FORCED_STOP = 2;
* @constructor
*/
function Manager(element, options) {
this.options = assign({}, Hammer.defaults, options || {});
this.options = assign({}, _defaults, options || {});
this.options.inputTarget = this.options.inputTarget || element;
@ -2407,7 +2410,7 @@ function toggleCssProps(manager, add) {
* @param {Object} data
*/
function triggerDomEvent(event, data) {
var gestureEvent = document.createEvent('Event');
var gestureEvent: any = doc.createEvent('Event');
gestureEvent.initEvent(event, true, true);
gestureEvent.gesture = data;
data.target.dispatchEvent(gestureEvent);
@ -2463,6 +2466,6 @@ assign(Hammer, {
prefixed: prefixed
});
window.Hammer = Hammer;
win.Hammer = Hammer;
export {Hammer};

View File

@ -4,7 +4,11 @@ import {windowDimensions} from '../util/dom';
export class SlideEdgeGesture extends SlideGesture {
constructor(element: Element, opts: Object = {}) {
public edges: Array<string>;
public maxEdgeStart: any;
private _d: any;
constructor(element: Element, opts: any = {}) {
defaults(opts, {
edge: 'left',
maxEdgeStart: 50
@ -15,7 +19,7 @@ export class SlideEdgeGesture extends SlideGesture {
this.maxEdgeStart = opts.maxEdgeStart;
}
canStart(ev) {
canStart(ev: any): boolean {
this._d = this.getContainerDimensions();
return this.edges.every(edge => this._checkEdge(edge, ev.center));
}

View File

@ -30,29 +30,34 @@ export class SlideGesture extends DragGesture {
return 0;
}
canStart() {
canStart(ev: any): boolean {
return true;
}
onDragStart(ev) {
if (!this.canStart(ev)) return false;
onDragStart(ev): boolean {
if (!this.canStart(ev)) {
return false;
}
this.slide = {};
var promise = this.onSlideBeforeStart(this.slide, ev) || Promise.resolve();
promise.then(() => {
var {min, max} = this.getSlideBoundaries(this.slide, ev);
this.slide.min = min;
this.slide.max = max;
this.slide.elementStartPos = this.getElementStartPos(this.slide, ev);
this.slide.pointerStartPos = ev.center[this.direction];
this.slide.started = true;
this.onSlideStart(this.slide, ev);
}).catch(() => {
this.slide = null;
});
this.onSlideBeforeStart(this.slide, ev);
var {min, max} = this.getSlideBoundaries(this.slide, ev);
this.slide.min = min;
this.slide.max = max;
this.slide.elementStartPos = this.getElementStartPos(this.slide, ev);
this.slide.pointerStartPos = ev.center[this.direction];
this.slide.started = true;
this.onSlideStart(this.slide, ev);
return true;
}
onDrag(ev) {
if (!this.slide || !this.slide.started) return;
onDrag(ev: any): boolean {
if (!this.slide || !this.slide.started) {
return false;
}
this.slide.pos = ev.center[this.direction];
this.slide.distance = clamp(
this.slide.min,
@ -61,6 +66,8 @@ export class SlideGesture extends DragGesture {
);
this.slide.delta = this.slide.pos - this.slide.pointerStartPos;
this.onSlide(this.slide, ev);
return true;
}
onDragEnd(ev) {
@ -69,8 +76,8 @@ export class SlideGesture extends DragGesture {
this.slide = null;
}
onSlideBeforeStart() {}
onSlideStart() {}
onSlide() {}
onSlideEnd() {}
onSlideBeforeStart(slide?: any, ev?: any): void {}
onSlideStart(slide?: any, ev?: any): void {}
onSlide(slide?: any, ev?: any): void {}
onSlideEnd(slide?: any, ev?: any): void {}
}

View File

@ -11,9 +11,9 @@
* @private
*/
export class Storage {
private _strategy: any = {};
private _strategy: any;
constructor(strategyCls: StorageEngine, options) {
constructor(strategyCls: any, options) {
this._strategy = new strategyCls(options);
}
get(key) {