From c619cc35d20edea30fe8a2a0f5b6775b3247bcb7 Mon Sep 17 00:00:00 2001 From: Luca Marra Date: Wed, 10 Jul 2013 16:44:53 +0200 Subject: [PATCH] added scrollTo on keyboard navigation fixes #73 and #45 --- assets/js/app.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/assets/js/app.js b/assets/js/app.js index 9843190..867ed24 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -275,9 +275,19 @@ if (item) switch_status(item.getAttribute("data-item-id")); } + function scroll_page_to(item) { + var clientHeight = pageYOffset + document.documentElement.clientHeight; + var itemPosition = item.offsetTop + item.offsetHeight; + if (clientHeight - itemPosition < 0 || clientHeight - item.offsetTop > document.documentElement.clientHeight) { + scrollTo(0, item.offsetTop - 10); + } + } function set_links_item(item_id) { + var link = document.getElementById("current-item"); + if (link) scroll_page_to(link); + var link = document.getElementById("original-item"); if (link) link.id = "original-" + link.getAttribute("data-item-id"); @@ -415,4 +425,4 @@ } }; -})(); \ No newline at end of file +})();