Skip to content

Commit

Permalink
Added type definitions and tests for jQuery Finger plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
maxackley committed Apr 23, 2014
1 parent 01f1a71 commit 89c5eaf
Show file tree
Hide file tree
Showing 3 changed files with 147 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ All definitions files include a header with the author and editors, so at some p
* [jQuery.dataTables](http://www.datatables.net) (by [Armin Sander](https://github.com/pragmatrix))
* [jQuery.datetimepicker](http://trentrichardson.com/examples/timepicker/) (by [Doug McDonald](https://github.com/dougajmcdonald))
* [jQuery.dynatree](http://code.google.com/p/dynatree/) (by [François de Campredon](https://github.com/fdecampredon))
* [jQuery.Finger](http://ngryman.sh/jquery.finger/) (by [Max Ackley](https://github.com/maxackley))
* [jQuery.Flot](http://www.flotcharts.org/) (by [Matt Burland](https://github.com/burlandm))
* [jQuery.form](http://malsup.com/jquery/form/) (by [François Guillot](http://fguillot.developpez.com/))
* [jQuery.Globalize](https://github.com/jquery/globalize) (by [Boris Yankov](https://github.com/borisyankov))
Expand Down
37 changes: 37 additions & 0 deletions jquery.finger/jquery.finger-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/// <reference path="../jquery/jquery.d.ts"/>
/// <reference path="jquery.finger.d.ts"/>

$.Finger.doubleTapInterval = 400;
$.Finger.flickDuration = 250;
$.Finger.pressDuration = 100;
$.Finger.motionThreshhold = 10;
$.Finger.preventDefault = true;
var fingerEventObject: JQueryFingerEventObject;
fingerEventObject.x = 1;
fingerEventObject.y = 2;
fingerEventObject.dx = 3;
fingerEventObject.dy = 4;
fingerEventObject.adx = 3;
fingerEventObject.ady = 4;
fingerEventObject.orientation = 'horizontal';
fingerEventObject.direction = 1;
$('body').on('drag', e => {
if ('vertical' == e.orientation) return;
e.preventDefault();
});

$('body').on('drag', '.drag', e => {
if ('vertical' == e.orientation) return;
e.preventDefault();
});

$('#menu').on('flick', function (e) {
if ('horizontal' == e.orientation) {
if (1 == e.direction) {
$(this).addClass('is-opened');
}
else {
$(this).removeClass('is-opened');
}
}
});
109 changes: 109 additions & 0 deletions jquery.finger/jquery.finger.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// Type definitions for jquery.finger.js
// Project: http://ngryman.sh/jquery.finger/
// Definitions by: Max Ackley <https://github.com/maxackley/>
// Definitions: https://github.com/borisyankov/DefinitelyTyped

/// <reference path="../jquery/jquery.d.ts"/>

declare module JQueryFinger {
export interface JQueryFingerOptions {
/**
* The time the user must hold in order to fire a press event. If this
* time is not reached, a tap event will be fired instead.
* Default: 300(ms).
*/
pressDuration: number;

/**
* The maximum time between two tap events to fire a doubletap event.
* If this time is reached, two distinct tap events will be fired instead.
* Default: 300(ms).
*/
doubleTapInterval: number;

/**
* The maximum time the user will have to swipe in order to fire a flick
* event. If this time is reached, only drag events will continue to be
* fired.
* Default: 150(ms).
*/
flickDuration: number;

/**
* The number of pixels the user will have to move in order to fire motion
* events (drag or flick). If this time is not reached, no motion will
* be handled and tap, doubletap or press event will be fired.
* Default: 5(px).
*/
motionThreshhold: number;

/**
* Globally prevents every native default behavior.
* Default: undefined.
*/
preventDefault: boolean;
}
}

interface JQueryFingerEventObject extends JQueryEventObject {
/**
* The x page coordinate.
*/
x: number;

/**
* The y page coordinate.
*/
y: number;

/**
* The x delta since the last event.
*/
dx: number;

/**
* The y delta since the last event.
*/
dy: number;

/**
* The absolute x delta since the last event.
*/
adx: number;

/**
* The absolute y delta since the last event.
*/
ady: number;

/**
* The orientation of the motion. Adjusted by $.Finger.motionThreshhold.
* Value is 'horizontal' or 'vertical'.
*/
orientation: string;

/**
* The direction of the motion. Value is 1 if the motion is 'positive'
* (left-to-right or top-to-bottom) or -1 if 'negative'(right-to-left or
* bottom-to-top).
*/
direction: number;
}

interface JQuery {
on(events: 'tap', handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'doubletap', handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'press', handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'drag', handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'flick', handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;

on(events: 'tap', data: any, handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'doubletap', data: any, handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'press', data: any, handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'drag', data: any, handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
on(events: 'flick', data: any, handler: (eventObject: JQueryFingerEventObject, ...args: any[]) => any): JQuery;
}

interface JQueryStatic {
Finger: JQueryFinger.JQueryFingerOptions;
}

0 comments on commit 89c5eaf

Please sign in to comment.