-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added type definitions and tests for jQuery Finger plugin.
- Loading branch information
Showing
3 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |