From 330ffb2c2b8f1311363e296f4bec02db9711c8ea Mon Sep 17 00:00:00 2001
From: Aria <aria@suma-ev.de>
Date: Wed, 24 Jul 2019 11:25:29 +0200
Subject: [PATCH] added possibility to tab through result-divs

---
 resources/js/utility.js | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/resources/js/utility.js b/resources/js/utility.js
index a61407b7f..9e958be17 100644
--- a/resources/js/utility.js
+++ b/resources/js/utility.js
@@ -3,18 +3,39 @@ $(document).ready(function () {
   $('.no-js').addClass('hide');
 });
 
-document.onkeydown = checkKey;
+// Flag used for checking if the user was shown the keyboard control information
+ctrlInfo = false;
+currentResultIndex = 1;
 
+document.onkeydown = checkKey;
 function checkKey(e) {
 
     e = e || window.event;
 
-
     if (e.keyCode == '9') {
         e.preventDefault();
-        $("#keyboard-ctrl-info").show();
-        $("#keyboard-ctrl-info").focus();
+        guideThroughMenu($(document.activeElement));
+    }
+
+}
+
+function guideThroughMenu(focused) {
+    if(!ctrlInfo) {
+        ctrlInfo = true;
+        showInfoBox();
     } else {
+        focusNextResult();
     }
+}
+
+function showInfoBox() {
+    $("#keyboard-ctrl-info").show();
+    $("#keyboard-ctrl-info").focus();
+}
 
+function focusNextResult() {
+    $("div[data-index='"+ currentResultIndex + "'").focus();
+    n = $(".result").length;
+    currentResultIndex = 1 + currentResultIndex % n;
+    console.log(currentResultIndex + " - " + n);
 }
\ No newline at end of file
-- 
GitLab