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