diff options
Diffstat (limited to 'point/binding/keyboard.js')
-rw-r--r-- | point/binding/keyboard.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/point/binding/keyboard.js b/point/binding/keyboard.js new file mode 100644 index 0000000..14eabc2 --- /dev/null +++ b/point/binding/keyboard.js | |||
@@ -0,0 +1,70 @@ | |||
1 | /* | ||
2 | * This file is part of "What's The Point" <https://github.com/Pacien/WhatsThePoint> | ||
3 | * Copyright (C) 2014 Pacien TRAN-GIRARD | ||
4 | * | ||
5 | * "What's The Point" is free software: you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU Affero General Public License as | ||
7 | * published by the Free Software Foundation, either version 3 of the | ||
8 | * License, or (at your option) any later version. | ||
9 | * | ||
10 | * "What's The Point" is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU Affero General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU Affero General Public License | ||
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
17 | */ | ||
18 | |||
19 | define(["control/control"], function (control) { | ||
20 | |||
21 | var keyboard = { | ||
22 | |||
23 | KEYCODE: { | ||
24 | BACKSPACE: 8, | ||
25 | ENTER: 13, | ||
26 | SPACE: 32, | ||
27 | END: 35, | ||
28 | HOME: 36, | ||
29 | LEFT: 37, | ||
30 | UP: 38, | ||
31 | RIGHT: 39, | ||
32 | DOWN: 40, | ||
33 | }, | ||
34 | |||
35 | init: function (settings) { | ||
36 | this.bindEvent(); | ||
37 | }, | ||
38 | |||
39 | translate: function (keyCode) { | ||
40 | var gotoEvent; | ||
41 | switch (keyCode) { | ||
42 | case this.KEYCODE.LEFT: | ||
43 | case this.KEYCODE.BACKSPACE: | ||
44 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.PREVIOUS_SLIDE); | ||
45 | |||
46 | case this.KEYCODE.RIGHT: | ||
47 | case this.KEYCODE.ENTER: | ||
48 | case this.KEYCODE.SPACE: | ||
49 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.NEXT_SLIDE); | ||
50 | |||
51 | case this.KEYCODE.HOME: | ||
52 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.FIRST_SLIDE); | ||
53 | |||
54 | case this.KEYCODE.END: | ||
55 | return control.dispatchEvent(control.EVENT.GOTO, control.GOTO.LAST_SLIDE); | ||
56 | } | ||
57 | |||
58 | }, | ||
59 | |||
60 | bindEvent: function () { | ||
61 | document.addEventListener("keydown", function (keydownEvent) { | ||
62 | // TODO: ignore if focus in form | ||
63 | keyboard.translate(keydownEvent.keyCode); | ||
64 | }); | ||
65 | }, | ||
66 | }; | ||
67 | |||
68 | return keyboard; | ||
69 | |||
70 | }); | ||