Commit 27a83eff authored by Aria Givi's avatar Aria Givi

changed the way currently focused element is stored

parent 251bb8bf
...@@ -8,6 +8,7 @@ Homestead.yaml ...@@ -8,6 +8,7 @@ Homestead.yaml
.orig .orig
.vscode .vscode
langfiles.zip langfiles.zip
npm-debug.log
# The Files created by Webpack in the build process # The Files created by Webpack in the build process
/public/**/*.css /public/**/*.css
!/public/fonts/arimo/stylesheet.css !/public/fonts/arimo/stylesheet.css
...@@ -19,4 +20,4 @@ langfiles.zip ...@@ -19,4 +20,4 @@ langfiles.zip
/.buildpath /.buildpath
/.project /.project
composer.lock composer.lock
\ No newline at end of file
var ctrlInfo = false; // Flag used for checking if the user was shown the keyboard control information var ctrlInfo = false; // Flag used for checking if the user was shown the keyboard control information
/* var currentElement = [ var currentResultIndex = 1; // stores index of result which was focused last
["Results", false] var currentElementData = { // Object used for storing currently focused element and element type (e.g. anchor tag or result div)
]; element: $("div.result").first(),
*/ selector: "div.result",
var currentResultIndex = 1; // stores result which was focused last type: "result"
};
$(document).on('keydown', function(e) { $(document).on('keydown', function(e) {
e = e || window.event; e = e || window.event;
...@@ -12,51 +12,54 @@ $(document).on('keydown', function(e) { ...@@ -12,51 +12,54 @@ $(document).on('keydown', function(e) {
if (e.keyCode == '9') { if (e.keyCode == '9') {
e.preventDefault(); e.preventDefault();
tabKeyPressed(); tabKeyPressed();
// Check for ENTER keypress
} else if (e.keyCode == '13') { } else if (e.keyCode == '13') {
e.preventDefault();
enterKeyPressed(); enterKeyPressed();
} }
}); });
function setFocus(e, selector, type) {
currentElementData.element = e;
currentElementData.selector = selector;
currentElementData.type = type;
currentElementData.element.focus();
console.log(currentElementData);
}
function tabKeyPressed() { function tabKeyPressed() {
if(!ctrlInfo) { if(!ctrlInfo) {
ctrlInfo = true; ctrlInfo = true;
showInfoBox(); showInfoBox();
} else { } else {
focusNextElement($(":focus")); focusNextElement();
} }
} }
function enterKeyPressed() { function enterKeyPressed() {
if($(":focus").hasClass("result")) { if(currentElementData.type = "result") {
//$(":focus").children("a").focus(); // setFocus(currentElementData.element, "link")
console.log($(":focus").children("a")); }
}
} }
function showInfoBox() { function showInfoBox() {
infoBox = $("#keyboard-ctrl-info"); $("#keyboard-ctrl-info").show();
infoBox.show(); setFocus($("#keyboard-ctrl-info"), "#keyboard-ctrl-info", "infobox");
infoBox.focus();
} }
function focusNextElement(currentFocus) { function focusNextElement() {
if(currentFocus.hasClass("result")) { if(currentElementData.type === "result") {
focusNextResult(currentFocus); focusNextResult();
} else { } else {
focusResult(); setFocus($("div.result").not('.ad').first(), "div.result" , "result");
} }
} }
function focusResult() {
$("div[data-index='"+ currentResultIndex + "'").focus();
n = $(".result").length;
currentResultIndex = 1 + currentResultIndex % n;
console.log(currentResultIndex + " - " + n);
}
function focusNextResult(currentFocus) {
if(currentFocus.next().length > 0) { function focusNextResult() {
currentFocus.next().focus(); if(currentElementData.element.next().length > 0) {
setFocus(currentElementData.element.next(), '' , "result");
} else { } else {
$("div[.result]").first().focus(); setFocus($("div.result").not('.ad').first(), "div.result" , "result");
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment