From 251bb8bf52b574612a00af3cd42a7cb9888c9485 Mon Sep 17 00:00:00 2001
From: Aria <aria@suma-ev.de>
Date: Thu, 1 Aug 2019 11:56:48 +0200
Subject: [PATCH] results can now be chosen, tabbing between anchor elements
 still missing

---
 resources/js/keyboardNavigation.js | 37 ++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/resources/js/keyboardNavigation.js b/resources/js/keyboardNavigation.js
index 4b52bc439..3aabb1f16 100644
--- a/resources/js/keyboardNavigation.js
+++ b/resources/js/keyboardNavigation.js
@@ -1,15 +1,21 @@
 var ctrlInfo = false;       // Flag used for checking if the user was shown the keyboard control information
+/* var currentElement = [
+    ["Results", false]
+];
+*/ 
 var currentResultIndex = 1; // stores result which was focused last
 
-document.onkeydown = checkKey;
-function checkKey(e) {
+
+$(document).on('keydown', function(e) {
     e = e || window.event;
-// Check for TAB keypress
+    // Check for TAB keypress
     if (e.keyCode == '9') {
         e.preventDefault();
-        tabKeyPressed($(document.activeElement));
+        tabKeyPressed();
+    } else if (e.keyCode == '13') {
+        enterKeyPressed();
     }
-}
+});
 
 function tabKeyPressed() {
     if(!ctrlInfo) {
@@ -20,16 +26,22 @@ function tabKeyPressed() {
     }
 }
 
+function enterKeyPressed() {
+    if($(":focus").hasClass("result")) {
+        //$(":focus").children("a").focus();
+        console.log($(":focus").children("a"));
+    }
+}
+
 function showInfoBox() {
-    $("#keyboard-ctrl-info").show();
-    $("#keyboard-ctrl-info").focus();
+    infoBox = $("#keyboard-ctrl-info");
+    infoBox.show();
+    infoBox.focus();
 }
 
 function focusNextElement(currentFocus) {
     if(currentFocus.hasClass("result")) {
         focusNextResult(currentFocus);
-    } else if(false) {
-
     } else {
         focusResult();
     }
@@ -42,8 +54,9 @@ function focusResult() {
 }
 
 function focusNextResult(currentFocus) {
-   if(!currentFocus.next().focus()) {
-        alert("test");
+   if(currentFocus.next().length > 0) {
+        currentFocus.next().focus();
+    } else {
+        $("div[.result]").first().focus();
     }
-    console.log(currentFocus);
 }
\ No newline at end of file
-- 
GitLab