Skip to content

Commit a61bc3e

Browse files
committed
Correct doc
1 parent 5e7ae15 commit a61bc3e

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

navigator/docs/epub/KeyboardPeripherals.md

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,29 @@ const configuration = {
5757
]
5858
};
5959

60-
const navigator = new EpubNavigator(container, publication, listeners, positions, initialPosition, configuration);
61-
```
62-
63-
## Listening to Keyboard Events
64-
65-
To handle these custom keyboard events, you can listen for the `peripheral` event on the `EpubNavigator` instance:
66-
67-
```javascript
68-
navigator.addEventListener('peripheral', (event) => {
69-
const { type } = event.detail;
70-
71-
switch (type) {
72-
case 'navigate_forward':
73-
// Handle forward navigation
74-
break;
75-
case 'navigate_backward':
76-
// Handle backward navigation
77-
break;
78-
case 'toggle_sidebar':
79-
// Toggle sidebar visibility
80-
break;
60+
const listeners = {
61+
// ... other listeners
62+
peripheral: (data) => {
63+
const { type, key, code, keyCode, ctrlKey, altKey, shiftKey, metaKey, timestamp, targetFrameSrc, selectedText } = data;
64+
65+
switch (type) {
66+
case 'navigate_forward':
67+
// Handle forward navigation
68+
console.log(`Forward navigation triggered by key: ${key} (${code})`);
69+
break;
70+
case 'navigate_backward':
71+
// Handle backward navigation
72+
console.log(`Backward navigation triggered by key: ${key} (${code})`);
73+
break;
74+
case 'toggle_sidebar':
75+
// Toggle sidebar visibility
76+
console.log(`Sidebar toggle triggered by key: ${key} (${code})`);
77+
break;
78+
}
8179
}
82-
});
80+
};
81+
82+
const navigator = new EpubNavigator(container, publication, listeners, positions, initialPosition, configuration);
8383
```
8484

8585
## Keyboard Peripheral Event Data

0 commit comments

Comments
 (0)