diff --git a/common/items.js b/common/items.js index 6909b07..974bbe1 100755 --- a/common/items.js +++ b/common/items.js @@ -1,5 +1,18 @@ var currentIndex = 0 +function findScrollParent(node) { + if (!node) { + return node + } + + if (node.classList.contains('content') || node.tagName === 'body') { + return node + } + else { + return findScrollParent(node.parentNode) + } +} + function nav(offset) { var items = document.querySelectorAll('.items:not(.disabled)') @@ -11,6 +24,9 @@ function nav(offset) { currentIndex -= items.length } items[currentIndex].focus() + if (items[currentIndex].getBoundingClientRect().y + items[currentIndex].getBoundingClientRect().height + 50 > document.documentElement.scrollHeight) { + findScrollParent(items[currentIndex]).scrollBy(0, 50) + } items[currentIndex].addEventListener('keydown', handleKeyDown) } @@ -29,6 +45,16 @@ function handleKeyDown(e) { break } } + else if (e.target.name !== 'INPUT') { + switch (e.key) { + case 'ArrowUp': + case 'ArrowDown': + e.preventDefault() + e.stopPropagation() + nav(0) + break + } + } } window.addEventListener('load', function (e) { diff --git a/sw.js b/sw.js index a0b1af0..c67374c 100755 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const VERSION = 'v9' +const VERSION = 'v10' const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/' const API_TRAINS = `${API_ORIGIN}v3/trains` const API_STATIONS = `${API_ORIGIN}v3/stations` diff --git a/view-train.html b/view-train.html index bd366f3..75c83af 100644 --- a/view-train.html +++ b/view-train.html @@ -32,7 +32,7 @@