mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
single arrows wont go all the way to bottom
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
/* globals app, define, ajaxify, utils, translator */
|
||||
/* globals app, define, ajaxify, utils, translator, config */
|
||||
|
||||
|
||||
define('navigator', function() {
|
||||
define('navigator', ['forum/topic/pagination'], function(pagination) {
|
||||
|
||||
var navigator = {};
|
||||
var index = 1;
|
||||
var count = 0;
|
||||
navigator.scrollActive = false;
|
||||
|
||||
navigator.init = function(selector, count, callback, toTop, toBottom) {
|
||||
|
||||
@@ -69,7 +70,6 @@ define('navigator', function() {
|
||||
}
|
||||
|
||||
navigator.update = function() {
|
||||
|
||||
toggle(!!count);
|
||||
|
||||
$($(navigator.selector).get().reverse()).each(function() {
|
||||
@@ -100,13 +100,13 @@ define('navigator', function() {
|
||||
|
||||
navigator.scrollUp = function () {
|
||||
$('body,html').animate({
|
||||
scrollTop: 0
|
||||
scrollTop: $('body').scrollTop() - $(window).height()
|
||||
});
|
||||
};
|
||||
|
||||
navigator.scrollDown = function () {
|
||||
$('body,html').animate({
|
||||
scrollTop: $('html').height() - 100
|
||||
scrollTop: $('body').scrollTop() + $(window).height()
|
||||
});
|
||||
};
|
||||
|
||||
@@ -136,5 +136,72 @@ define('navigator', function() {
|
||||
return (elTop >= scrollTop && elBottom <= scrollBottom) || (elTop <= scrollTop && elBottom >= scrollTop);
|
||||
}
|
||||
|
||||
navigator.scrollToPost = function(postIndex, highlight, duration, offset) {
|
||||
if (!utils.isNumber(postIndex)) {
|
||||
return;
|
||||
}
|
||||
|
||||
offset = offset || 0;
|
||||
duration = duration !== undefined ? duration : 400;
|
||||
navigator.scrollActive = true;
|
||||
|
||||
if($('#post_anchor_' + postIndex).length) {
|
||||
return scrollToPid(postIndex, highlight, duration, offset);
|
||||
}
|
||||
|
||||
if(config.usePagination) {
|
||||
if (window.location.search.indexOf('page') !== -1) {
|
||||
navigator.update();
|
||||
return;
|
||||
}
|
||||
|
||||
var page = Math.ceil((postIndex + 1) / config.postsPerPage);
|
||||
|
||||
if(parseInt(page, 10) !== pagination.currentPage) {
|
||||
pagination.loadPage(page, function() {
|
||||
scrollToPid(postIndex, highlight, duration, offset);
|
||||
});
|
||||
} else {
|
||||
scrollToPid(postIndex, highlight, duration, offset);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function scrollToPid(postIndex, highlight, duration, offset) {
|
||||
var scrollTo = $('#post_anchor_' + postIndex);
|
||||
|
||||
var done = false;
|
||||
function animateScroll() {
|
||||
$('html, body').animate({
|
||||
scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
|
||||
}, duration, function() {
|
||||
if (done) {
|
||||
return;
|
||||
}
|
||||
done = true;
|
||||
|
||||
navigator.scrollActive = false;
|
||||
navigator.update();
|
||||
highlightPost();
|
||||
$('body').scrollTop($('body').scrollTop() - 1);
|
||||
$('html').scrollTop($('html').scrollTop() - 1);
|
||||
});
|
||||
}
|
||||
|
||||
function highlightPost() {
|
||||
if (highlight) {
|
||||
scrollTo.parent().find('.topic-item').addClass('highlight');
|
||||
setTimeout(function() {
|
||||
scrollTo.parent().find('.topic-item').removeClass('highlight');
|
||||
}, 5000);
|
||||
}
|
||||
}
|
||||
|
||||
if ($('#post-container').length && scrollTo.length) {
|
||||
animateScroll();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return navigator;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user