From 019ed4afa050a12ed4dbd49af0a528c93a6d16eb Mon Sep 17 00:00:00 2001 From: kubosho_ Date: Mon, 2 Jun 2014 18:05:38 +0900 Subject: [PATCH 1/2] Add flipsnap.js type definitions --- flipsnap/flipsnap.d.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 flipsnap/flipsnap.d.ts diff --git a/flipsnap/flipsnap.d.ts b/flipsnap/flipsnap.d.ts new file mode 100644 index 0000000000..b46081a52f --- /dev/null +++ b/flipsnap/flipsnap.d.ts @@ -0,0 +1,36 @@ +// Type definitions for flipsnap.js +// Project: http://pxgrid.github.io/js-flipsnap/ +// Definitions by: kubosho_ & gsino +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface Flipsnap { + hasPrev(): boolean; + hasNext(): boolean; + toPrev(transitionDuration?: number): void; + toNext(transitionDuration?: number): void; + moveToPoint(point: number, transitionDuration?: number): void; + element: HTMLElement; +} + +interface FlipsnapStatic { + (element: HTMLElement, opts?: FlipsnapOptions): Flipsnap; + (element: string, opts?: FlipsnapOptions): Flipsnap; +} + +interface FlipsnapOptions { + maxPoint?: number; + distance?: number; + transitionDuration?: number; + disableTouch?: boolean; + disable3d?: boolean; +} + +interface HTMLElement { + addEventListener(type: "fstouchend", listener: (ev: FlipsnapEvent) => any, useCapture?: boolean): void; +} + +interface FlipsnapEvent extends Event { + newPoint: number; +} + +declare var Flipsnap: FlipsnapStatic; \ No newline at end of file From 943bfad4bb984bc5873d33f2566e76c685944716 Mon Sep 17 00:00:00 2001 From: Mayuki Sawatari Date: Mon, 16 Jun 2014 20:53:18 +0900 Subject: [PATCH 2/2] Add interface members & some comments. --- flipsnap/flipsnap.d.ts | 71 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 64 insertions(+), 7 deletions(-) diff --git a/flipsnap/flipsnap.d.ts b/flipsnap/flipsnap.d.ts index b46081a52f..55e601704a 100644 --- a/flipsnap/flipsnap.d.ts +++ b/flipsnap/flipsnap.d.ts @@ -1,36 +1,93 @@ // Type definitions for flipsnap.js // Project: http://pxgrid.github.io/js-flipsnap/ -// Definitions by: kubosho_ & gsino +// Definitions by: kubosho_ , gsino , Mayuki Sawatari // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface Flipsnap { +interface IFlipsnap { + /** + * Return true or false. true is returned when there is previous element. + */ hasPrev(): boolean; + + /** + * Return true or false. true is returned when there is next element. + */ hasNext(): boolean; + + /** + * Move to previous item. + */ toPrev(transitionDuration?: number): void; + + /** + * Move to next item. + */ toNext(transitionDuration?: number): void; + + /** + * Move to item of number. + */ moveToPoint(point: number, transitionDuration?: number): void; + + /** + * Recalculate values + */ + refresh(): void; + element: HTMLElement; } interface FlipsnapStatic { - (element: HTMLElement, opts?: FlipsnapOptions): Flipsnap; - (element: string, opts?: FlipsnapOptions): Flipsnap; + /** + * @param element The element + */ + (element: HTMLElement, opts?: FlipsnapOptions): IFlipsnap; + + /** + * @param selector The parameter must be CSS Selector. When set string, to get first element of result. Not all element. + */ + (selector: string, opts?: FlipsnapOptions): IFlipsnap; } interface FlipsnapOptions { + /** + * Stop point count. default is auto calculate from element item count. + */ maxPoint?: number; + /** + * Move distance. default is auto calculate from element width and maxPont. + */ distance?: number; + /** + * Transition duration (millisecond). default is 350. + */ transitionDuration?: number; + /** + * When set true, touch event is disabled. Only handling button or etc interface. default is false. + */ disableTouch?: boolean; + /** + * When support 3D transform browser and this option set true, it is not used 3D transform and use 2D transform. You should set true, when it is a device which has a bug in 3D transform(old Android or BlackBerry etc). default is false. + */ disable3d?: boolean; } interface HTMLElement { - addEventListener(type: "fstouchend", listener: (ev: FlipsnapEvent) => any, useCapture?: boolean): void; + addEventListener(type: "fstouchstart", listener: (ev: Event) => any, useCapture?: boolean): void; + addEventListener(type: "fstouchmove", listener: (ev: FlipsnapTouchMoveEvent) => any, useCapture?: boolean): void; + addEventListener(type: "fstouchend", listener: (ev: FlipsnapTouchEndEvent) => any, useCapture?: boolean): void; } -interface FlipsnapEvent extends Event { +interface FlipsnapTouchMoveEvent extends Event { + delta: number; + direction: number; +} + +interface FlipsnapTouchEndEvent extends Event { + moved: boolean; + cancelled: boolean; newPoint: number; + originalPoint: number; } -declare var Flipsnap: FlipsnapStatic; \ No newline at end of file +declare var Flipsnap: FlipsnapStatic;