From 81f4b1f3c05f01e5acbc7208a74fb48a92779a5e Mon Sep 17 00:00:00 2001 From: Roger Chen Date: Thu, 4 Sep 2014 13:31:51 -0400 Subject: [PATCH] Add typings for Keypress v2.0.3 --- CONTRIBUTORS.md | 3 +- keypress/keypress-tests.ts | 61 ++++++++++++++++++++++++++++++++++++++ keypress/keypress.d.ts | 61 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 keypress/keypress-tests.ts create mode 100644 keypress/keypress.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 1cded38d5ccb4f..cdd9a5f78fdabf 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -214,6 +214,7 @@ All definitions files include a header with the author and editors, so at some p * [JWPlayer](http://developer.longtailvideo.com/trac/) (by [Martin Duparc](https://github.com/martinduparc/)) * [KeyboardJS](https://github.com/RobertWHurst/KeyboardJS) (by [Vincent Bortone](https://github.com/vbortone/)) * [keymaster.js](https://github.com/madrobby/keymaster) (by [Marting W. Kirst](https://github.com/nitram509/)) +* [Keypress](https://github.com/dmauro/Keypress/) (by [Roger Chen](https://github.com/rcchen/)) * [KineticJS](http://kineticjs.com/) (by [Basarat Ali Syed](https://github.com/basarat)) * [Knockback](http://kmalakoff.github.com/knockback/) (by [Marcel Binot](https://github.com/docgit)) * [Knockout.js](http://knockoutjs.com/) (by [Boris Yankov](https://github.com/borisyankov)) @@ -244,7 +245,7 @@ All definitions files include a header with the author and editors, so at some p * [Marked](https://github.com/chjj/marked) (by [William Orr](https://github.com/worr)) * [MathJax](https://github.com/mathjax/MathJax) (by [Roland Zwaga](https://github.com/rolandzwaga)) * [mCustomScrollbar](https://github.com/malihu/malihu-custom-scrollbar-plugin) (by [Sarah Williams](https://github.com/flurg)) -* [Meteor](https://www.meteor.com) (by [Dave Allen](https://github.com/fullflavedave)) +* [Meteor](https://www.meteor.com) (by [Dave Allen](https://github.com/fullflavedave)) * [md5.js](http://labs.cybozu.co.jp/blog/mitsunari/2007/07/md5js_1.html) (by [MIZUNE Pine](https://github.com/pine613)) * [Microsoft Ajax](http://msdn.microsoft.com/en-us/library/ee341002(v=vs.100).aspx) (by [Patrick Magee](https://github.com/pjmagee)) * [Microsoft Live Connect](http://msdn.microsoft.com/en-us/library/live/hh243643.aspx) (by [John Vilk](https://github.com/jvilk)) diff --git a/keypress/keypress-tests.ts b/keypress/keypress-tests.ts new file mode 100644 index 00000000000000..38d12c12f14bb4 --- /dev/null +++ b/keypress/keypress-tests.ts @@ -0,0 +1,61 @@ +/// + +module KeypressComboTests { + var listener = new window.keypress.Listener(); + + var copyCombo = { + keys: "cmd c", + on_keydown: () => { + console.log("Key down"); + }, + on_keyup: () => { + console.log("Key up"); + }, + on_release: () => { + console.log("Released"); + }, + prevent_default: true, + prevent_repeat: false, + is_unordered: true, + is_counting: false, + is_exclusive: false, + is_sequence: true, + is_solitary: true + }; + + var pasteCombo = { + keys: "ctrl v", + on_keydown: () => { + console.log("Paste"); + }, + prevent_default: true, + prevent_repeat: true, + is_exclusive: true + }; + + listener.register_combo(copyCombo); + listener.unregister_combo("cmd c"); + + listener.register_many([copyCombo, pasteCombo]); + listener.stop_listening(); + listener.listen(); + listener.unregister_many(["cmd c", "cmd v"]); + + listener.reset(); +} + +module KeypressBindingTests { + var element = document.createElement('div'); + var defaults = { + prevent_default: true, + prevent_repeat: true, + is_unordered: true, + is_counting: false, + is_exclusive: false, + is_solitary: false, + is_sequence: false + }; + var listener = new window.keypress.Listener(element); + listener = new window.keypress.Listener(element, defaults); + listener.reset(); +} diff --git a/keypress/keypress.d.ts b/keypress/keypress.d.ts new file mode 100644 index 00000000000000..bd831d5b0a9622 --- /dev/null +++ b/keypress/keypress.d.ts @@ -0,0 +1,61 @@ +// Type definitions for Keypress v2.0.3 +// Project: https://github.com/dmauro/Keypress/ +// Definitions by: Roger Chen +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +// A keyboard input capturing utility in which any key can be a modifier key. +declare module Keypress { + + interface ListenerDefaults { + keys: string; + prevent_default: boolean; + prevent_repeat: boolean; + is_unordered: boolean; + is_counting: boolean; + is_exclusive: boolean; + is_solitary: boolean; + is_sequence: boolean; + } + + interface Combo { + keys: string; + on_keydown: () => any; + on_keyup: () => any; + on_release: () => any; + this: Element; + prevent_default: boolean; + prevent_repeat: boolean; + is_unordered: boolean; + is_counting: boolean; + is_exclusive: boolean; + is_sequence: boolean; + is_solitary: boolean; + } + + interface Listener { + new(element: Element, defaults: ListenerDefaults): Listener; + new(element: Element): Listener; + new(): Listener; + simple_combo(keys: string, on_keydown_callback: () => any): void; + counting_combo(keys: string, on_count_callback: () => any): void; + sequence_combo(keys: string, callback: () => any): void; + register_combo(combo: Combo): void; + unregister_combo(combo: Combo): void; + unregister_combo(keys: string): void; + register_many(combos: Combo[]): void; + unregister_many(combos: Combo[]): void; + unregister_many(keys: string[]): void; + get_registered_combos(): Combo[]; + reset(): void; + listen(): void; + stop_listening(): void; + } + + interface Keypress { + Listener: Listener; + } +} + +interface Window { + keypress: Keypress.Keypress; +}