mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-02 12:05:57 +01:00
Added threshold detection when scrolling upwards
... for less jolty upwards scrolling.
This commit is contained in:
@@ -141,7 +141,7 @@ define('forum/topic', [
|
||||
return navigator.scrollToPostIndex(postIndex, true);
|
||||
}
|
||||
} else if (bookmark && (!config.usePagination || (config.usePagination && ajaxify.data.pagination.currentPage === 1)) && ajaxify.data.postcount > 5) {
|
||||
navigator.update();
|
||||
navigator.update(0);
|
||||
app.alert({
|
||||
alert_id: 'bookmark',
|
||||
message: '[[topic:bookmark_instructions]]',
|
||||
@@ -158,7 +158,7 @@ define('forum/topic', [
|
||||
app.removeAlert('bookmark');
|
||||
}, 10000);
|
||||
} else {
|
||||
navigator.update();
|
||||
navigator.update(0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -218,7 +218,7 @@ define('forum/topic/posts', [
|
||||
};
|
||||
|
||||
Posts.processPage = function(posts) {
|
||||
Posts.unloadImages();
|
||||
Posts.unloadImages(posts);
|
||||
Posts.showBottomPostBar();
|
||||
posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
|
||||
app.createUserTooltips(posts);
|
||||
@@ -232,8 +232,8 @@ define('forum/topic/posts', [
|
||||
hidePostToolsForDeletedPosts(posts);
|
||||
};
|
||||
|
||||
Posts.unloadImages = function() {
|
||||
var images = components.get('post/content').find('img:not(.not-responsive)');
|
||||
Posts.unloadImages = function(posts) {
|
||||
var images = posts.find('[component="post/content"] img:not(.not-responsive)');
|
||||
images.each(function() {
|
||||
$(this).attr('data-src', $(this).attr('src'));
|
||||
$(this).attr('data-state', 'unloaded');
|
||||
|
||||
@@ -92,12 +92,12 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
|
||||
}
|
||||
|
||||
navigator.update = function(threshold) {
|
||||
threshold = typeof threshold === 'number' ? threshold : undefined;
|
||||
|
||||
/*
|
||||
The "threshold" is defined as the distance from the top of the page to
|
||||
a spot where a user is expecting to begin reading.
|
||||
*/
|
||||
threshold = typeof threshold === 'number' ? threshold : undefined;
|
||||
|
||||
var els = $(navigator.selector);
|
||||
if (els.length) {
|
||||
index = parseInt(els.first().attr('data-index'), 10) + 1;
|
||||
@@ -118,6 +118,15 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
|
||||
}
|
||||
});
|
||||
|
||||
// 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();
|
||||
|
||||
threshold = anchorRect.top;
|
||||
console.log('new index', index, anchorEl, threshold);
|
||||
}
|
||||
|
||||
if (typeof navigator.callback === 'function') {
|
||||
navigator.callback(index, count, threshold);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user