diff --git a/resources/js/utility.js b/resources/js/utility.js index a61407b7f28903a6051a553f90dacb4ee20d0830..9e958be17afca4a74382ad580c24692191be8ef0 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