-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkeyboard.js
30 lines (28 loc) · 1.01 KB
/
keyboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function keyboardManager() {
// Detect when an element with tabindex 3 receives focus
$("[tabindex=6]").on("focus", function() {
// Set a delay to move the focus to the element with tabindex 1 after the current event loop
setTimeout(function() {
$("[tabindex=1]").focus();
}, 0);
});
document.addEventListener('keydown', function(event) {
const isOnNotepadTextarea = $(document.activeElement).is('#popup_note_textarea');
if (event.key === 'Tab') {
if (!isOnNotepadTextarea) {
const fromAddressBar = !event.target.matches('body, html, input, button, textarea, select, .main_menu_link');
if (fromAddressBar) {
event.preventDefault();
$("[tabindex=1]").focus();
}
} else {
event.preventDefault();
// Add your code to be executed when the cursor is on the notepad textarea
// and the 'Tab' key is pressed
}
} else if (event.key === 'Escape') {
$(':focus').blur();
$('.tabChiDeck').hide();
}
});
}