mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-28 01:26:16 +01:00
fix: #8732
This commit is contained in:
@@ -275,6 +275,10 @@ ajaxify = window.ajaxify || {};
|
|||||||
}
|
}
|
||||||
|
|
||||||
ajaxify.end = function (url, tpl_url) {
|
ajaxify.end = function (url, tpl_url) {
|
||||||
|
// Scroll back to top of page
|
||||||
|
if (!ajaxify.isCold()) {
|
||||||
|
window.scrollTo(0, 0);
|
||||||
|
}
|
||||||
ajaxify.loadScript(tpl_url, function done() {
|
ajaxify.loadScript(tpl_url, function done() {
|
||||||
$(window).trigger('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
|
$(window).trigger('action:ajaxify.end', { url: url, tpl_url: tpl_url, title: ajaxify.data.title });
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -284,11 +284,6 @@ app.cacheBuster = null;
|
|||||||
app.createUserTooltips($('#content'));
|
app.createUserTooltips($('#content'));
|
||||||
|
|
||||||
app.createStatusTooltips();
|
app.createStatusTooltips();
|
||||||
|
|
||||||
// Scroll back to top of page
|
|
||||||
if (!ajaxify.isCold()) {
|
|
||||||
window.scrollTo(0, 0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
app.showMessages = function () {
|
app.showMessages = function () {
|
||||||
|
|||||||
@@ -222,7 +222,9 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
var scrollTop = $(window).scrollTop();
|
var scrollTop = $(window).scrollTop();
|
||||||
var windowHeight = $(window).height();
|
var windowHeight = $(window).height();
|
||||||
var documentHeight = $(document).height();
|
var documentHeight = $(document).height();
|
||||||
var middleOfViewport = scrollTop + (windowHeight / 2);
|
var navbarHeight = components.get('navbar').outerHeight(true);
|
||||||
|
var topicHeaderHeight = $('.topic-header').height() || 0;
|
||||||
|
var middleOfViewport = scrollTop + (windowHeight / 2) - navbarHeight - topicHeaderHeight;
|
||||||
var previousDistance = Number.MAX_VALUE;
|
var previousDistance = Number.MAX_VALUE;
|
||||||
els.each(function () {
|
els.each(function () {
|
||||||
var elIndex = parseInt($(this).attr('data-index'), 10);
|
var elIndex = parseInt($(this).attr('data-index'), 10);
|
||||||
@@ -387,23 +389,27 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var postHeight = scrollTo.height();
|
var postHeight = scrollTo.height();
|
||||||
var viewportHeight = $(window).height();
|
var navbarHeight = components.get('navbar').outerHeight(true);
|
||||||
var navbarHeight = components.get('navbar').height();
|
var topicHeaderHeight = $('.topic-header').height() || 0;
|
||||||
|
var viewportHeight = $(window).height() - navbarHeight - topicHeaderHeight;
|
||||||
|
|
||||||
// Temporarily disable navigator update on scroll
|
// Temporarily disable navigator update on scroll
|
||||||
$(window).off('scroll', navigator.update);
|
$(window).off('scroll', navigator.delayedUpdate);
|
||||||
|
|
||||||
duration = duration !== undefined ? duration : 400;
|
duration = duration !== undefined ? duration : 400;
|
||||||
navigator.scrollActive = true;
|
navigator.scrollActive = true;
|
||||||
var done = false;
|
var done = false;
|
||||||
|
|
||||||
function animateScroll() {
|
function animateScroll() {
|
||||||
function onAnimateComplete() {
|
function reenableScroll() {
|
||||||
if (done) {
|
|
||||||
// Re-enable onScroll behaviour
|
// Re-enable onScroll behaviour
|
||||||
$(window).on('scroll', navigator.update);
|
$(window).on('scroll', navigator.delayedUpdate);
|
||||||
var scrollToRect = scrollTo.get(0).getBoundingClientRect();
|
var scrollToRect = scrollTo.get(0).getBoundingClientRect();
|
||||||
navigator.update(scrollToRect.top);
|
navigator.update(scrollToRect.top);
|
||||||
|
}
|
||||||
|
function onAnimateComplete() {
|
||||||
|
if (done) {
|
||||||
|
reenableScroll();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
done = true;
|
done = true;
|
||||||
@@ -416,13 +422,16 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
|
|
||||||
var scrollTop = 0;
|
var scrollTop = 0;
|
||||||
if (postHeight < viewportHeight) {
|
if (postHeight < viewportHeight) {
|
||||||
scrollTop = (scrollTo.offset().top - (viewportHeight / 2) + (postHeight / 2));
|
scrollTop = (scrollTo.offset().top - (viewportHeight / 2) + (postHeight / 2)) - topicHeaderHeight;
|
||||||
} else {
|
} else {
|
||||||
scrollTop = scrollTo.offset().top - navbarHeight;
|
scrollTop = scrollTo.offset().top - navbarHeight - topicHeaderHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (duration === 0) {
|
if (duration === 0) {
|
||||||
$(window).scrollTop(scrollTop);
|
$(window).scrollTop(scrollTop);
|
||||||
return onAnimateComplete();
|
onAnimateComplete();
|
||||||
|
reenableScroll();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
$('html, body').animate({
|
$('html, body').animate({
|
||||||
scrollTop: scrollTop + 'px',
|
scrollTop: scrollTop + 'px',
|
||||||
@@ -444,3 +453,4 @@ define('navigator', ['forum/pagination', 'components'], function (pagination, co
|
|||||||
|
|
||||||
return navigator;
|
return navigator;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user