From 3a27e7b0ea527dfe8bfbb84e8899e50016205910 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 29 Mar 2016 12:39:41 +0300 Subject: [PATCH] closes #4405 --- public/src/client/topic.js | 8 ++++---- public/src/modules/navigator.js | 18 +++++++++++++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index cd0464e9aa..9d52262676 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -222,10 +222,10 @@ define('forum/topic', [ function updateTopicTitle() { var span = components.get('navbar/title').find('span'); - if ($(window).scrollTop() > 50) { - span.html(ajaxify.data.title).show(); - } else { - span.html('').hide(); + if ($(window).scrollTop() > 50 && span.hasClass('hidden')) { + span.html(ajaxify.data.title).removeClass('hidden'); + } else if ($(window).scrollTop() <= 50 && !span.hasClass('hidden')) { + span.html('').addClass('hidden'); } if ($(window).scrollTop() > 300) { app.removeAlert('bookmark'); diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js index 7127f1f15c..89bfc737ee 100644 --- a/public/src/modules/navigator.js +++ b/public/src/modules/navigator.js @@ -103,7 +103,10 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com index = parseInt(els.first().attr('data-index'), 10) + 1; } - var middleOfViewport = $(window).scrollTop() + $(window).height() / 2; + var scrollTop = $(window).scrollTop(); + var windowHeight = $(window).height(); + var documentHeight = $(document).height(); + var middleOfViewport = scrollTop + windowHeight / 2; var previousDistance = Number.MAX_VALUE; els.each(function() { var distanceToMiddle = Math.abs(middleOfViewport - $(this).offset().top); @@ -118,10 +121,19 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com } }); + + // check if we are at the top + if (scrollTop === 0 && parseInt(els.first().attr('data-index'), 10) === 0) { + index = 1; + // check if we are near the bottom + } else if (scrollTop + windowHeight > documentHeight - 100 && parseInt(els.last().attr('data-index'), 10) === count - 1) { + index = count; + } + // If a threshold is undefined, try to determine one based on new index if (threshold === undefined) { - var anchorEl = components.get('post/anchor', index - 1), - anchorRect = anchorEl.get(0).getBoundingClientRect(); + var anchorEl = components.get('post/anchor', index - 1); + var anchorRect = anchorEl.get(0).getBoundingClientRect(); threshold = anchorRect.top; }