mirror of
https://github.com/kiwix/kiwix-js.git
synced 2025-08-03 19:27:11 -04:00
Fix keyboard handling of fulltext search results
This commit is contained in:
parent
3bb40fb4b0
commit
ec52b0a6b7
@ -1,8 +1,8 @@
|
|||||||
/*!
|
/*!
|
||||||
* app.css : Main CSS of the application
|
* app.css : Main CSS of the application
|
||||||
*
|
*
|
||||||
* Copyright 2013-2019 Mossroy and contributors
|
* Copyright 2013-2023 Mossroy, Jaifroid and contributors
|
||||||
* Licence GPL v3:
|
* License GPL v3:
|
||||||
*
|
*
|
||||||
* This file is part of Kiwix.
|
* This file is part of Kiwix.
|
||||||
*
|
*
|
||||||
|
@ -285,28 +285,27 @@ prefixElement.addEventListener('keydown', function (e) {
|
|||||||
document.getElementById('articleContent').focus();
|
document.getElementById('articleContent').focus();
|
||||||
keyPressHandled = true;
|
keyPressHandled = true;
|
||||||
}
|
}
|
||||||
// Arrow-key selection code adapted from https://stackoverflow.com/a/14747926/9727685
|
// Arrow-key selection code adapted from https://stackoverflow.com/a/14747926/9727685
|
||||||
// IE11 produces "Down" instead of "ArrowDown" and "Up" instead of "ArrowUp"
|
// IE11 produces "Down" instead of "ArrowDown" and "Up" instead of "ArrowUp"
|
||||||
if (/^((Arrow)?(Down|Up|Left|Right)|Enter)$/.test(e.key)) {
|
if (/^((Arrow)?(Down|Up|Left|Right)|Enter)$/.test(e.key)) {
|
||||||
// User pressed Down arrow, Up arrow, Left arrow, Right arrow, or Enter
|
// User pressed Down arrow, Up arrow, Left arrow, Right arrow, or Enter
|
||||||
e.preventDefault();
|
|
||||||
e.stopPropagation();
|
|
||||||
// This is needed to prevent processing in the keyup event : https://stackoverflow.com/questions/9951274
|
// This is needed to prevent processing in the keyup event : https://stackoverflow.com/questions/9951274
|
||||||
keyPressHandled = true;
|
keyPressHandled = true;
|
||||||
var activeElement = document.querySelector('#articleList .hover') || document.querySelector('#articleList a');
|
var activeElement = document.querySelector('#articleList .hover') || document.querySelector('#articleList a');
|
||||||
if (!activeElement) return;
|
if (!activeElement) return;
|
||||||
// If user presses Enter or Right arrow, read the dirEntry or open snippet
|
// If user presses Enter or Right arrow, read the dirEntry or open snippet
|
||||||
if (/Enter|Right|Left/.test(e.key)) {
|
if (/Enter|Right|Left/.test(e.key)) {
|
||||||
if (activeElement.classList.contains('hover') && !activeElement.classList.contains('snippet-container')) {
|
if (/Enter/.test(e.key) && activeElement.classList.contains('hover') && !activeElement.classList.contains('snippet-container')) {
|
||||||
var dirEntryId = activeElement.getAttribute('dirEntryId');
|
var dirEntryId = activeElement.getAttribute('dirEntryId');
|
||||||
findDirEntryFromDirEntryIdAndLaunchArticleRead(decodeURIComponent(dirEntryId));
|
findDirEntryFromDirEntryIdAndLaunchArticleRead(decodeURIComponent(dirEntryId));
|
||||||
return;
|
|
||||||
} else if (activeElement.classList.contains('snippet-container')) {
|
} else if (activeElement.classList.contains('snippet-container')) {
|
||||||
|
e.preventDefault();
|
||||||
// Open the snippet container
|
// Open the snippet container
|
||||||
uiUtil.toggleSnippet(activeElement);
|
uiUtil.toggleSnippet(activeElement);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
e.preventDefault();
|
||||||
// If user presses ArrowDown...
|
// If user presses ArrowDown...
|
||||||
// (NB selection is limited to arrow keys and Enter by regex above)
|
// (NB selection is limited to arrow keys and Enter by regex above)
|
||||||
if (/Down/.test(e.key)) {
|
if (/Down/.test(e.key)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user