From d2ebf0436c00bc79b7941fb2179839e7cbd572db Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Mon, 30 May 2016 17:33:40 -0400 Subject: [PATCH] FIX: On small heights jumping to posts was iffy --- .../discourse/lib/offset-calculator.js.es6 | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 b/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 index eaab864c9a..e9413eb771 100644 --- a/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 +++ b/app/assets/javascripts/discourse/lib/offset-calculator.js.es6 @@ -13,8 +13,10 @@ export default function offsetCalculator(y) { const $title = $('#topic-title'); const rawWinHeight = $(window).height(); const windowHeight = rawWinHeight - $title.height(); - const expectedOffset = $title.height() - $header.find('.contents').height() + (windowHeight / 5); - const ideal = $header.outerHeight(true) + ((expectedOffset < 0) ? 0 : expectedOffset); + const eyeTarget = (windowHeight / 10); + const headerHeight = $header.outerHeight(true); + const expectedOffset = $title.height() - $header.find('.contents').height() + (eyeTarget * 2); + const ideal = headerHeight + ((expectedOffset < 0) ? 0 : expectedOffset); const $container = $('.posts-wrapper'); const topPos = $container.offset().top; @@ -23,7 +25,12 @@ export default function offsetCalculator(y) { const docHeight = $(document).height(); const scrollPercent = (scrollTop / (docHeight-rawWinHeight)); - const inter = topPos - scrollTop + ($container.height() * scrollPercent); + let inter = topPos - scrollTop + ($container.height() * scrollPercent); + if (inter < headerHeight + eyeTarget) { + inter = headerHeight + eyeTarget; + } + + if (inter > ideal) { const bottom = $('#topic-bottom').offset().top;