From 67d3e3547f2b3ebd4b683d78b7670e018a09ab4d Mon Sep 17 00:00:00 2001 From: Shinnosuke Watanabe Date: Mon, 22 Sep 2014 12:58:36 +0900 Subject: [PATCH] Add definitions for FastClick https://github.com/ftlabs/fastclick --- CONTRIBUTORS.md | 3 ++- fastclick/fastclick-tests.ts | 22 ++++++++++++++++++ fastclick/fastclick.d.ts | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 fastclick/fastclick-tests.ts create mode 100644 fastclick/fastclick.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4fe6f526ed..5f71104bcf 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -1,4 +1,4 @@ -# Contributors +# Contributors This is a non-exhaustive list of definitions and their creators. If you created a definition but are not listed then feel free to send a pull request on this file with your name and url. @@ -85,6 +85,7 @@ All definitions files include a header with the author and editors, so at some p * [Ext JS](http://www.sencha.com/products/extjs/) (by [Brian Kotek](https://github.com/brian428)) * [Fabric.js](http://fabricjs.com/) (by [Oliver Klemencic](https://github.com/oklemencic/)) * [Fancybox](http://fancybox.net/) (by [Boris Yankov](https://github.com/borisyankov)) +* [FastClick](https://github.com/ftlabs/fastclick) (by [Shinnosuke Watanabe](https://github.com/shinnn)) * [File API: Directories and System](http://www.w3.org/TR/file-system-api/) (by [Kon](http://phyzkit.net/)) * [File API: Writer](http://www.w3.org/TR/file-writer-api/) (by [Kon](http://phyzkit.net/)) * [Finch](https://github.com/stoodder/finchjs) (by [David Sichau](https://github.com/DavidSichau/)) diff --git a/fastclick/fastclick-tests.ts b/fastclick/fastclick-tests.ts new file mode 100644 index 0000000000..0e31846ab8 --- /dev/null +++ b/fastclick/fastclick-tests.ts @@ -0,0 +1,22 @@ +/// + +// on browser +new FastClick(document.body); +new FastClick(document.getElementById('foo'), {tapDelay: 50}); +new FastClick(document.getElementsByTagName('p')[0], {touchBoundary: 50}); +var fc = FastClick.attach(document.body); +fc.determineEventType(document.getElementsByClassName('foo')).concat('bar'); +fc.findControl(document.querySelector('label')); +fc.focus(document.querySelectorAll('section')[0]); +document.body.addEventListener('click', function(e) { + fc.getTargetElementFromEventTarget(e.target); + fc.needsClick(e.target); + fc.needsFocus(e.target); +}); + +// on CommonJS environment +import fastclick = require('fastclick'); +fastclick(document.body); +new fastclick.FastClick(document.links[0]); +new fastclick.FastClick(document.links[1], {tapDelay: 50}); +new fastclick.FastClick(document.links[2], {touchBoundary: 50}); diff --git a/fastclick/fastclick.d.ts b/fastclick/fastclick.d.ts new file mode 100644 index 0000000000..e90c3ac2e6 --- /dev/null +++ b/fastclick/fastclick.d.ts @@ -0,0 +1,44 @@ +// Type definitions for FastClick v1.0.3 +// Project: https://github.com/ftlabs/fastclick +// Definitions by: Shinnosuke Watanabe +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface FastClickObject { + lastTouchIdentifier: number; + layer: Element; + tapDelay: number; + targetElement: any; + touchBoundary: number; + touchStartX: number; + touchStartY: number; + trackingClick: boolean; + trackingClickStart: number; + destroy(): void; + determineEventType(targetElement: any): string; + findControl(labelElement: any /* EventTarget | HTMLLabelElement */): any; + focus(targetElement: any /* EventTarget | Element */): void; + getTargetElementFromEventTarget(eventTarget: EventTarget): any; + needsClick(target: any /* EventTarget | Element */): boolean; + needsFocus(target: any /* EventTarget | Element */): boolean; +} + +interface FastClickOptions { + touchBoundary?: number; + tapDelay?: number; +} + +interface FastClickStatic { + new(layer: any, options?: FastClickOptions): FastClickObject; + attach(layer: any, options?: FastClickOptions): FastClickObject; +} + +declare module "fastclick" { + function fastclick(layer: any, options?: FastClickOptions): FastClickObject; + module fastclick { + var FastClick: FastClickStatic; + } + + export = fastclick; +} + +declare var FastClick: FastClickStatic;