Skip to content

Commit

Permalink
Consolidated function for navigation and removed fat-arrow function.
Browse files Browse the repository at this point in the history
  • Loading branch information
EraYaN committed May 5, 2019
1 parent 178125f commit 265bf9a
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions org.jellyfin.webos/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,34 +80,10 @@

function isVisible(element){
return element.offsetWidth > 0 && element.offsetHeight > 0;
}

function navigateUp(){
console.log("Navigating up...")
var element = document.activeElement;
if(element === null){
navigationInit();
} else if(!isVisible(element) || element.tagName=='BODY'){
navigationInit();
} else {
//Isolate the node that we're after
const currentNode = element;

//find all tab-able elements
const allElements = document.querySelectorAll('input, button, a, area, object, select, textarea, [contenteditable]');

//Find the current tab index.
const currentIndex = Array.from(allElements).findIndex(el => currentNode.isEqualNode(el))

//focus the following element
if(allElements[currentIndex - 1])
allElements[currentIndex - 1].focus();
}

}
}

function navigateDown(){
console.log("Navigating down...")
function navigate(amount){
console.log("Navigating "+amount.toString()+"...")
var element = document.activeElement;
if(element === null){
navigationInit();
Expand All @@ -121,21 +97,21 @@
const allElements = document.querySelectorAll('input, button, a, area, object, select, textarea, [contenteditable]');

//Find the current tab index.
const currentIndex = Array.from(allElements).findIndex(el => currentNode.isEqualNode(el))
const currentIndex = Array.from(allElements).findIndex(function (el) { return currentNode.isEqualNode(el); })

//focus the following element
if(allElements[currentIndex + 1])
allElements[currentIndex + 1].focus();
if(allElements[currentIndex + amount])
allElements[currentIndex + amount].focus();
}
}


function upArrowPressed() {
navigateUp();
navigate(-1);
}

function downArrowPressed() {
navigateDown();
navigate(1);
}
function leftArrowPressed() {
// Your stuff here
Expand Down

0 comments on commit 265bf9a

Please sign in to comment.