better scrolling

v1.18.x
Baris Soner Usakli 11 years ago
parent 23c20a2821
commit 3c53ebb02e

@ -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(history.replaceState) { if (!scrollingToPost) {
history.replaceState(null, null, window.location.protocol + '//' + window.location.host + window.location.pathname + '#' + el.attr('data-pid')); if (history.replaceState) {
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() {

Loading…
Cancel
Save