mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
better scrolling
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
define(['composer', 'forum/pagination'], function(composer, pagination) {
|
define(['composer', 'forum/pagination'], function(composer, pagination) {
|
||||||
var Topic = {},
|
var Topic = {},
|
||||||
infiniteLoaderActive = false;
|
infiniteLoaderActive = false,
|
||||||
|
scrollingToPost = false;
|
||||||
|
|
||||||
function showBottomPostBar() {
|
function showBottomPostBar() {
|
||||||
if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) {
|
if($('#post-container .post-row').length > 1 || !$('#post-container li[data-index="0"]').length) {
|
||||||
@@ -983,6 +984,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function updateHeader() {
|
function updateHeader() {
|
||||||
|
|
||||||
$('.pagination-block a').off('click').on('click', function() {
|
$('.pagination-block a').off('click').on('click', function() {
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
@@ -1024,19 +1026,24 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
} else {
|
} else {
|
||||||
localStorage.setItem("topic:" + templates.get('topic_id') + ":bookmark", el.attr('data-pid'));
|
localStorage.setItem("topic:" + templates.get('topic_id') + ":bookmark", el.attr('data-pid'));
|
||||||
|
|
||||||
|
if (!scrollingToPost) {
|
||||||
if (history.replaceState) {
|
if (history.replaceState) {
|
||||||
history.replaceState(null, null, window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + el.attr('data-pid'));
|
history.replaceState({
|
||||||
|
url: window.location.pathname.slice(1) + '#' + el.attr('data-pid')
|
||||||
|
}, null,
|
||||||
|
window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + el.attr('data-pid'));
|
||||||
} else {
|
} else {
|
||||||
location.hash = '#' + el.attr('data-pid');
|
location.hash = '#' + el.attr('data-pid');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function elementInView(el) {
|
function elementInView(el) {
|
||||||
var scrollTop = $(window).scrollTop();
|
var scrollTop = $(window).scrollTop() + $('#header-menu').height();
|
||||||
var scrollBottom = scrollTop + $(window).height();
|
var scrollBottom = scrollTop + $(window).height();
|
||||||
|
|
||||||
var elTop = el.offset().top;
|
var elTop = el.offset().top;
|
||||||
@@ -1090,11 +1097,12 @@ define(['composer', 'forum/pagination'], function(composer, pagination) {
|
|||||||
tid = $('#post-container').attr('data-tid');
|
tid = $('#post-container').attr('data-tid');
|
||||||
|
|
||||||
function animateScroll() {
|
function animateScroll() {
|
||||||
|
scrollingToPost = true;
|
||||||
|
|
||||||
$("html, body").animate({
|
$("html, body").animate({
|
||||||
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + "px"
|
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + "px"
|
||||||
}, duration !== undefined ? duration : 400, function() {
|
}, duration !== undefined ? duration : 400, function() {
|
||||||
updateHeader();
|
scrollingToPost = false;
|
||||||
|
|
||||||
if (highlight) {
|
if (highlight) {
|
||||||
scrollTo.parent().addClass('highlight');
|
scrollTo.parent().addClass('highlight');
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user