From ac162cbe5ad6816fd5e9084e27eb3aa772e19e1f Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Wed, 16 May 2007 04:36:40 +0100 Subject: [PATCH] correct headlines scroll position in moveToPost() --- functions.js | 4 ++-- viewfeed.js | 46 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/functions.js b/functions.js index f922183c..eea2515a 100644 --- a/functions.js +++ b/functions.js @@ -252,13 +252,13 @@ function hotkey_handler(e) { if (new_feed) viewfeed(new_feed, ''); } - if (!is_safari() && (keycode == 78 || keycode == 40)) { // n, down + if (keycode == 78 || keycode == 40) { // n, down if (typeof moveToPost != 'undefined') { return moveToPost('next'); } } - if (!is_safari() && (keycode == 80 || keycode == 38)) { // p, up + if (keycode == 80 || keycode == 38) { // p, up if (typeof moveToPost != 'undefined') { return moveToPost('prev'); } diff --git a/viewfeed.js b/viewfeed.js index 622ea637..27af8c08 100644 --- a/viewfeed.js +++ b/viewfeed.js @@ -132,7 +132,8 @@ function article_callback() { } else { debug("article_callback: returned no XML object"); - f.innerHTML = "
" + __('Could not display article (missing XML object)') + "
"; + /* var f = document.getElementById("content-frame"); + f.innerHTML = "
" + __('Could not display article (missing XML object)') + "
"; */ } } catch (e) { exception_error("article_callback", e); @@ -180,7 +181,6 @@ function view(id, feed_id, skip_history) { enableHotkeys(); - active_post_id = id; //setActiveFeedId(feed_id); var query = "backend.php?op=view&id=" + param_escape(id) + @@ -193,7 +193,9 @@ function view(id, feed_id, skip_history) { xmlhttp.abort(); } - if (cached_article || xmlhttp_ready(xmlhttp)) { + if (xmlhttp_ready(xmlhttp)) { + + active_post_id = id; cleanSelected("headlinesList"); @@ -346,6 +348,34 @@ function toggleMark(id) { } +function correctHeadlinesOffset(id) { + + try { + + var hlist = document.getElementById("headlinesList"); + var container = document.getElementById("headlinesInnerContainer"); + var row = document.getElementById("RROW-" + id); + + var viewport = container.offsetHeight; + + var rel_offset_top = row.offsetTop - container.scrollTop; + var rel_offset_bottom = row.offsetTop + row.offsetHeight - container.scrollTop; + + debug("Rtop: " + rel_offset_top + " Rbtm: " + rel_offset_bottom); + debug("Vport: " + viewport); + + if (rel_offset_top <= 0 || rel_offset_top > viewport) { + container.scrollTop = row.offsetTop; + } else if (rel_offset_bottom > viewport) { + container.scrollTop = row.offsetTop + row.offsetHeight - viewport; + } + + } catch (e) { + exception_error("correctHeadlinesOffset", e); + } + +} + function moveToPost(mode) { // check for combined mode @@ -354,8 +384,8 @@ function moveToPost(mode) { var rows = getVisibleHeadlineIds(); - var prev_id; - var next_id; + var prev_id = false; + var next_id = false; if (!document.getElementById('RROW-' + active_post_id)) { active_post_id = false; @@ -374,13 +404,15 @@ function moveToPost(mode) { } if (mode == "next") { - if (next_id != undefined) { + if (next_id) { + correctHeadlinesOffset(next_id); view(next_id, getActiveFeedId()); } } if (mode == "prev") { - if ( prev_id != undefined) { + if (prev_id) { + correctHeadlinesOffset(prev_id); view(prev_id, getActiveFeedId()); } } -- 2.39.5