Added threshold detection when scrolling upwards

... for less jolty upwards scrolling.
v1.18.x
Julian Lam
parent 28db642050
commit add82ba6c9

@ -141,7 +141,7 @@ define('forum/topic', [
return navigator.scrollToPostIndex(postIndex, true); return navigator.scrollToPostIndex(postIndex, true);
} }
} else if (bookmark && (!config.usePagination || (config.usePagination && ajaxify.data.pagination.currentPage === 1)) && ajaxify.data.postcount > 5) { } else if (bookmark && (!config.usePagination || (config.usePagination && ajaxify.data.pagination.currentPage === 1)) && ajaxify.data.postcount > 5) {
navigator.update(); navigator.update(0);
app.alert({ app.alert({
alert_id: 'bookmark', alert_id: 'bookmark',
message: '[[topic:bookmark_instructions]]', message: '[[topic:bookmark_instructions]]',
@ -158,7 +158,7 @@ define('forum/topic', [
app.removeAlert('bookmark'); app.removeAlert('bookmark');
}, 10000); }, 10000);
} else { } else {
navigator.update(); navigator.update(0);
} }
} }

@ -218,7 +218,7 @@ define('forum/topic/posts', [
}; };
Posts.processPage = function(posts) { Posts.processPage = function(posts) {
Posts.unloadImages(); Posts.unloadImages(posts);
Posts.showBottomPostBar(); Posts.showBottomPostBar();
posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive'); posts.find('[component="post/content"] img:not(.not-responsive)').addClass('img-responsive');
app.createUserTooltips(posts); app.createUserTooltips(posts);
@ -232,8 +232,8 @@ define('forum/topic/posts', [
hidePostToolsForDeletedPosts(posts); hidePostToolsForDeletedPosts(posts);
}; };
Posts.unloadImages = function() { Posts.unloadImages = function(posts) {
var images = components.get('post/content').find('img:not(.not-responsive)'); var images = posts.find('[component="post/content"] img:not(.not-responsive)');
images.each(function() { images.each(function() {
$(this).attr('data-src', $(this).attr('src')); $(this).attr('data-src', $(this).attr('src'));
$(this).attr('data-state', 'unloaded'); $(this).attr('data-state', 'unloaded');

@ -92,12 +92,12 @@ define('navigator', ['forum/pagination', 'components'], function(pagination, com
} }
navigator.update = function(threshold) { navigator.update = function(threshold) {
threshold = typeof threshold === 'number' ? threshold : undefined;
/* /*
The "threshold" is defined as the distance from the top of the page to The "threshold" is defined as the distance from the top of the page to
a spot where a user is expecting to begin reading. a spot where a user is expecting to begin reading.
*/ */
threshold = typeof threshold === 'number' ? threshold : undefined;
var els = $(navigator.selector); var els = $(navigator.selector);
if (els.length) { if (els.length) {
index = parseInt(els.first().attr('data-index'), 10) + 1; 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') { if (typeof navigator.callback === 'function') {
navigator.callback(index, count, threshold); navigator.callback(index, count, threshold);
} }

Loading…
Cancel
Save