Commit | Line | Data |
---|---|---|
e3747bbc | 1 | # Event Handling - JavaScript API |
e9e547a0 AE |
2 | |
3 | ## `EventKey` | |
4 | ||
5 | This class offers a set of static methods that can be used to determine if some | |
6 | common keys are being pressed. Internally it compares either the `.key` property | |
7 | if it is supported or the value of `.which`. | |
8 | ||
9 | ```js | |
10 | require(["EventKey"], function(EventKey) { | |
11 | elBySel(".some-input").addEventListener("keydown", function(event) { | |
12 | if (EventKey.Enter(event)) { | |
13 | // the `Enter` key was pressed | |
14 | } | |
15 | }); | |
16 | }); | |
17 | ``` | |
18 | ||
19 | ### `ArrowDown(event: KeyboardEvent): boolean` | |
20 | ||
21 | Returns true if the user has pressed the `↓` key. | |
22 | ||
23 | ### `ArrowLeft(event: KeyboardEvent): boolean` | |
24 | ||
25 | Returns true if the user has pressed the `←` key. | |
26 | ||
27 | ### `ArrowRight(event: KeyboardEvent): boolean` | |
28 | ||
29 | Returns true if the user has pressed the `→` key. | |
30 | ||
31 | ### `ArrowUp(event: KeyboardEvent): boolean` | |
32 | ||
33 | Returns true if the user has pressed the `↑` key. | |
34 | ||
35 | ### `Comma(event: KeyboardEvent): boolean` | |
36 | ||
37 | Returns true if the user has pressed the `,` key. | |
38 | ||
39 | ### `Enter(event: KeyboardEvent): boolean` | |
40 | ||
41 | Returns true if the user has pressed the `↲` key. | |
42 | ||
43 | ### `Escape(event: KeyboardEvent): boolean` | |
44 | ||
45 | Returns true if the user has pressed the `Esc` key. | |
46 | ||
47 | ### `Tab(event: KeyboardEvent): boolean` | |
48 | ||
49 | Returns true if the user has pressed the `↹` key. | |
50 | ||
51 | ## `EventHandler` | |
52 | ||
53 | A synchronous event system based on string identifiers rather than DOM elements, | |
54 | similar to the PHP event system in WoltLab Suite. Any components can listen to | |
55 | events or trigger events itself at any time. | |
56 | ||
57 | ### Identifiying Events with the Developer Tools | |
58 | ||
59 | The Developer Tools in WoltLab Suite 3.1 offer an easy option to identify existing | |
60 | events that are fired while code is being executed. You can enable this watch | |
61 | mode through your browser's console using `Devtools.toggleEventLogging()`: | |
62 | ||
63 | ``` | |
64 | > Devtools.toggleEventLogging(); | |
65 | < Event logging enabled | |
66 | < [Devtools.EventLogging] Firing event: bar @ com.example.app.foo | |
67 | < [Devtools.EventLogging] Firing event: baz @ com.example.app.foo | |
68 | ``` | |
69 | ||
70 | ### `add(identifier: string, action: string, callback: (data: Object) => void): string` | |
71 | ||
72 | Adding an event listeners returns a randomly generated UUIDv4 that is used to | |
73 | identify the listener. This UUID is required to remove a specific listener through | |
74 | the `remove()` method. | |
75 | ||
76 | ### `fire(identifier: string, action: string, data?: Object)` | |
77 | ||
78 | Triggers an event using an optional `data` object that is passed to each listener | |
79 | by reference. | |
80 | ||
81 | ### `remove(identifier: string, action: string, uuid: string)` | |
82 | ||
83 | Removes a previously registered event listener using the UUID returned by `add()`. | |
84 | ||
85 | ### `removeAll(identifier: string, action: string)` | |
86 | ||
87 | Removes all event listeners registered for the provided `identifier` and `action`. | |
88 | ||
89 | ### `removeAllBySuffix(identifier: string, suffix: string)` | |
90 | ||
91 | Removes all event listeners for an `identifier` whose action ends with the value | |
92 | of `suffix`. |