diff --git a/types/virtual-keyboard/index.d.ts b/types/virtual-keyboard/index.d.ts new file mode 100644 index 0000000000..b7c248e4a5 --- /dev/null +++ b/types/virtual-keyboard/index.d.ts @@ -0,0 +1,93 @@ +// Type definitions for virtual-keyboard 1.26 +// Project: https://www.npmjs.com/package/virtual-keyboard +// Definitions by: Bogdan Surai +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +/// + +export type kbEventHandler = (event?: Event | string, keyboard?: Element, el?: Element) => void; + +export interface NavigateOptions { + focusClass?: string; + position?: number[]; + rowLooping?: boolean; + toggleMode?: boolean; +} + +export interface CustomLayout { + [index: string]: string[]; +} + +export interface KeyboardOptions { + type: string; + layout?: string; + color?: string; + class?: string; + updateOnChange?: boolean; + customLayout?: CustomLayout; + position?: boolean | object; + reposition?: boolean; + css?: object; + display?: object; + language?: string | string[]; + wheelMessage?: string; + comboRegex?: RegExp; + rtl?: boolean; + acceptValid?: boolean; + alwaysOpen?: boolean; + appendLocally?: boolean; + appendTo?: string | object; + autoAccept?: boolean; + autoAcceptOnEsc?: boolean; + autoAcceptOnValid?: boolean; + cancelClose?: boolean; + caretToEnd?: boolean; + closeByClickEvent?: boolean; + combos?: object; + enterMod?: string; + enterNavigation?: boolean; + ignoreEsc?: boolean; + initialFocus?: boolean; + keyBinding?: string; + lockInput?: boolean; + maxInsert?: boolean; + maxLength?: boolean | number; + noFocus?: boolean; + openOn?: string; + preventPaste?: string; + repeatDelay?: number; + repeatRate?: number; + resetDefault?: boolean; + restrictInclude?: string; + restrictInput?: boolean; + scrollAdjustment?: number | string; + stayOpen?: boolean; + stickyShift?: boolean; + stopAtEnd?: boolean; + tabNavigation?: boolean; + useCombos?: boolean; + usePreview?: boolean; + useWheel?: boolean; + userClosed?: boolean; + accepted?: kbEventHandler; + beforeClose?: kbEventHandler; + beforeInsert?: kbEventHandler; + beforeVisible?: kbEventHandler; + buildKey?: kbEventHandler; + canceled?: kbEventHandler; + change?: kbEventHandler; + hidden?: kbEventHandler; + initialized?: kbEventHandler; + restricted?: kbEventHandler; + switchInput?: kbEventHandler; + validate?: kbEventHandler; + visible?: kbEventHandler; +} + +declare global { + interface JQuery { + keyboard(options: KeyboardOptions): this; + addNavigation(options: NavigateOptions): this; + } +} diff --git a/types/virtual-keyboard/tsconfig.json b/types/virtual-keyboard/tsconfig.json new file mode 100644 index 0000000000..4d8d420495 --- /dev/null +++ b/types/virtual-keyboard/tsconfig.json @@ -0,0 +1,23 @@ +{ + "files": [ + "index.d.ts", + "virtual-keyboard-tests.ts" + ], + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + } +} diff --git a/types/virtual-keyboard/tslint.json b/types/virtual-keyboard/tslint.json new file mode 100644 index 0000000000..2750cc0197 --- /dev/null +++ b/types/virtual-keyboard/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } \ No newline at end of file diff --git a/types/virtual-keyboard/virtual-keyboard-tests.ts b/types/virtual-keyboard/virtual-keyboard-tests.ts new file mode 100644 index 0000000000..84e3c9ed3c --- /dev/null +++ b/types/virtual-keyboard/virtual-keyboard-tests.ts @@ -0,0 +1,73 @@ +import * as jQuery from "jquery"; +import { KeyboardOptions, NavigateOptions } from "virtual-keyboard"; + +const kbOptions: KeyboardOptions = { + display: { + bksp : "\u2190", + accept: `Next` , + cancel: `Back`, + normal: "ABC", + meta1 : "#+-", + space : "Space", + alt : `Alt`, + s : `ABC`, + }, + acceptValid: true, + type: "input", + layout: "custom", + customLayout: { + normal: [ + `a b c d e f g h i j k l m`, + `n o p q r s t u v x y z w`, + `1 2 3 4 5 6 7 8 9 0 . _ @`, + `{alt} {s} {space} {meta1} {s} {bksp} `, + `{cancel} {accept}` + ], + shift: [ + `A B C D E F G H I J K L M`, + `N O P Q R S T U V X Y Z W`, + `1 2 3 4 5 6 7 8 9 0 . _ @`, + `{alt} {s} {space} {meta1} {s} {bksp} `, + `{cancel} {accept}` + ], + meta1: [ + `- / : ; ( ) \u20ac & \" ! ? ' \``, + `[ ] { } # % ^ * + = ° ´ §`, + ` \\ | ~ < > $ \u00a3 \u00a5 , ' ² ³`, + `{space} {meta1} {bksp}`, + `{cancel} {accept}` + ], + "alt-shift": [ + `A B C D E F G H I J K L M N O`, + `P Q R S T U V X Y Z W \u00df \u00dc \u00d6 \u00c4`, + `1 2 3 4 5 6 7 8 9 0 . _ @ \u0301`, + `{alt} {s} {space} {meta1} {s} {bksp} `, + `{cancel} {accept}` + ], + alt: [ + `a b c d e f g h i j k l m n o`, + `p q r s t u v x y z w \u00df \u00fc \u00f6 \u00e4`, + `1 2 3 4 5 6 7 8 9 0 . _ @ \u0301`, + `{alt} {s} {space} {meta1} {s} {bksp} `, + `{cancel} {accept}` + ], + }, + lockInput: true, + alwaysOpen: true, + appendLocally: true, + color: "light", + class: "sxcycx", + updateOnChange: true, + usePreview: false, + tabNavigation: false, + canceled: () => { console.log("cancelled"); } +}; + +const navOptions: NavigateOptions = { + position : [0, 0], + toggleMode : true, + focusClass : "hasFocus", + rowLooping : true, + }; + +jQuery("#keyboard").keyboard(kbOptions).addNavigation(navOptions);