diff --git a/public/src/client/topic.js b/public/src/client/topic.js index d5920d2118..848c0f35be 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -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); } } diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.js index 63241fc370..e00bf2d617 100644 --- a/public/src/client/topic/posts.js +++ b/public/src/client/topic/posts.js @@ -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'); diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js index 2f6b2d8613..cb553962a7 100644 --- a/public/src/modules/navigator.js +++ b/public/src/modules/navigator.js @@ -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); }