Compare commits

...

2 Commits

Author SHA1 Message Date
Julian Lam
bc0ce62fd5 fix: topic anchors too 2020-10-08 17:16:23 -04:00
Julian Lam
6ddc233d32 fix: #8654, use window.location.hash instead of animating w/ jQuery 2020-10-08 17:06:41 -04:00
3 changed files with 22 additions and 62 deletions

View File

@@ -126,7 +126,7 @@ define('forum/topic', [
if (postIndex > 1) {
if (components.get('post/anchor', postIndex - 1).length) {
return navigator.scrollToPostIndex(postIndex - 1, true, 0);
return navigator.scrollToPostIndex(postIndex - 1, true);
}
} else if (bookmark && (!config.usePagination || (config.usePagination && ajaxify.data.pagination.currentPage === 1)) && ajaxify.data.postcount > ajaxify.data.bookmarkThreshold) {
app.alert({
@@ -208,10 +208,6 @@ define('forum/topic', [
return;
}
if (navigator.scrollActive) {
return;
}
var newUrl = 'topic/' + ajaxify.data.slug + (index > 1 ? ('/' + index) : '');
if (newUrl !== currentUrl) {

View File

@@ -223,7 +223,7 @@ define('forum/topic/posts', [
}
Posts.loadMorePosts = function (direction) {
if (!components.get('topic').length || navigator.scrollActive) {
if (!components.get('topic').length) {
return;
}

View File

@@ -14,8 +14,6 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
var isNavigating = false;
var firstMove = true;
navigator.scrollActive = false;
var paginationBlockEl = $('.pagination-block');
var paginationTextEl = paginationBlockEl.find('.pagination-text');
var paginationBlockMeterEl = paginationBlockEl.find('meter');
@@ -107,7 +105,7 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
if (isNavigating) {
touchTooltipEl.addClass('hidden');
navigator.scrollToIndex(index - 1, true, 0);
navigator.scrollToIndex(index - 1, true);
isNavigating = false;
}
});
@@ -331,7 +329,7 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
}
};
navigator.scrollToIndex = function (index, highlight, duration) {
navigator.scrollToIndex = function (index, highlight) {
var inTopic = !!components.get('topic').length;
var inCategory = !!components.get('category').length;
@@ -339,21 +337,17 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
return;
}
duration = duration !== undefined ? duration : 400;
navigator.scrollActive = true;
// if in topic and item already on page
if (inTopic && components.get('post/anchor', index).length) {
return navigator.scrollToPostIndex(index, highlight, duration);
return navigator.scrollToPostIndex(index, highlight);
}
// if in category and item alreay on page
if (inCategory && $('[component="category/topic"][data-index="' + index + '"]').length) {
return navigator.scrollToTopicIndex(index, highlight, duration);
return navigator.scrollToTopicIndex(index, highlight);
}
if (!config.usePagination) {
navigator.scrollActive = false;
index = parseInt(index, 10) + 1;
ajaxify.go(generateUrl(index));
return;
@@ -364,70 +358,42 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
var page = 1 + Math.floor(index / config.postsPerPage);
if (parseInt(page, 10) !== ajaxify.data.pagination.currentPage) {
pagination.loadPage(page, function () {
scrollMethod(index, highlight, duration);
scrollMethod(index, highlight);
});
} else {
scrollMethod(index, highlight, duration);
scrollMethod(index, highlight);
}
};
navigator.scrollToPostIndex = function (postIndex, highlight, duration) {
navigator.scrollToPostIndex = function (postIndex, highlight) {
var scrollTo = components.get('post', 'index', postIndex);
navigator.scrollToElement(scrollTo, highlight, duration);
navigator.scrollToElement(scrollTo, highlight);
};
navigator.scrollToTopicIndex = function (topicIndex, highlight, duration) {
navigator.scrollToTopicIndex = function (topicIndex, highlight) {
var scrollTo = $('[component="category/topic"][data-index="' + topicIndex + '"]');
navigator.scrollToElement(scrollTo, highlight, duration);
navigator.scrollToElement(scrollTo, highlight);
};
navigator.scrollToElement = function (scrollTo, highlight, duration) {
navigator.scrollToElement = function (scrollTo, highlight) {
if (!scrollTo.length) {
navigator.scrollActive = false;
return;
}
var postHeight = scrollTo.height();
var viewportHeight = $(window).height();
var navbarHeight = components.get('navbar').height();
// Temporarily disable navigator update on scroll
$(window).off('scroll', navigator.update);
duration = duration !== undefined ? duration : 400;
navigator.scrollActive = true;
var done = false;
const anchorId = scrollTo.find('[component="post/anchor"], [component="topic/anchor"]').prop('id');
window.location.hash = anchorId;
function animateScroll() {
function onAnimateComplete() {
if (done) {
// Re-enable onScroll behaviour
$(window).on('scroll', navigator.update);
var scrollToRect = scrollTo.get(0).getBoundingClientRect();
navigator.update(scrollToRect.top);
return;
}
done = true;
highlightPost();
$('body').scrollTop($('body').scrollTop() - 1);
$('html').scrollTop($('html').scrollTop() - 1);
navigator.scrollActive = false;
highlightPost();
$('body').scrollTop($('body').scrollTop() - 1);
$('html').scrollTop($('html').scrollTop() - 1);
}
var scrollTop = 0;
if (postHeight < viewportHeight) {
scrollTop = (scrollTo.offset().top - (viewportHeight / 2) + (postHeight / 2));
} else {
scrollTop = scrollTo.offset().top - navbarHeight;
}
if (duration === 0) {
$(window).scrollTop(scrollTop);
return onAnimateComplete();
}
$('html, body').animate({
scrollTop: scrollTop + 'px',
}, duration, onAnimateComplete);
}
// Re-enable onScroll behaviour
$(window).on('scroll', navigator.update);
var scrollToRect = scrollTo.get(0).getBoundingClientRect();
navigator.update(scrollToRect.top);
function highlightPost() {
if (highlight) {
@@ -438,8 +404,6 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
}, 10000);
}
}
animateScroll();
};
return navigator;