Skip to content

Node.js based forum software built for the modern web

closes #4405

barisusakli3a27e7b0ea52
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;
}