Skip to content

Node.js based forum software built for the modern web

single arrows wont go all the way to bottom

barisusakli1b31f5b2ca96
diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js
index 25790b7a1f..85831511ba 100644
--- a/public/src/forum/topic.js
+++ b/public/src/forum/topic.js
@@ -9,12 +9,11 @@ var dependencies = [
'forum/topic/threadTools',
'forum/topic/postTools',
'forum/topic/events',
- 'forum/topic/scrollTo',
'forum/topic/browsing',
'navigator'
];
-define('forum/topic', dependencies, function(pagination, infinitescroll, threadTools, postTools, events, scrollTo, browsing, navigator) {
+define('forum/topic', dependencies, function(pagination, infinitescroll, threadTools, postTools, events, browsing, navigator) {
var Topic = {},
currentUrl = '';
@@ -90,7 +89,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
var postIndex = getPostIndex();
if (postIndex) {
- scrollTo.scrollToPost(postIndex - 1, true);
+ navigator.scrollToPost(postIndex - 1, true);
} else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && ajaxify.variables.get('postcount') > 1) {
app.alert({
alert_id: 'bookmark',
@@ -98,7 +97,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
timeout: 0,
type: 'info',
clickfn : function() {
- scrollTo.scrollToPost(parseInt(bookmark, 10), true);
+ navigator.scrollToPost(parseInt(bookmark, 10), true);
},
closefn : function() {
localStorage.removeItem('topic:' + tid + ':bookmark');
@@ -206,7 +205,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
app.removeAlert('bookmark');
}
- if (!scrollTo.active) {
+ if (!navigator.scrollActive) {
var parts = ajaxify.removeRelativePath(window.location.pathname.slice(1)).split('/');
var topicId = parts[1],
slug = parts[2];
@@ -355,14 +354,14 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
}
function loadMorePosts(direction) {
- if (!$('#post-container').length || scrollTo.active) {
+ if (!$('#post-container').length || navigator.scrollActive) {
return;
}
infinitescroll.calculateAfter(direction, '#post-container .post-row[data-index!="0"]', config.postsPerPage, function(after, offset, el) {
loadPostsAfter(after, function() {
if (direction < 0 && el) {
- scrollTo.scrollToPost(el.attr('data-index'), false, 0, offset);
+ navigator.scrollToPost(el.attr('data-index'), false, 0, offset);
}
});
});
diff --git a/public/src/forum/topic/scrollTo.js b/public/src/forum/topic/scrollTo.js
deleted file mode 100644
index 531a0ac6f3..0000000000
--- a/public/src/forum/topic/scrollTo.js
+++ /dev/null
@@ -1,78 +0,0 @@
-
-'use strict';
-
-/* globals define, utils, config */
-
-define('forum/topic/scrollTo', ['forum/topic/pagination', 'navigator'], function(pagination, navigator) {
-
- var ScrollTo = {};
- ScrollTo.active = false;
-
- ScrollTo.scrollToPost = function(postIndex, highlight, duration, offset) {
- if (!utils.isNumber(postIndex)) {
- return;
- }
-
- offset = offset || 0;
- duration = duration !== undefined ? duration : 400;
- scrollTo.active = true;
-
- if($('#post_anchor_' + postIndex).length) {
- return scrollToPid(postIndex, highlight, duration, offset);
- }
-
- if(config.usePagination) {
- if (window.location.search.indexOf('page') !== -1) {
- navigator.update();
- scrollTo.active = false;
- 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);
-
- function animateScroll() {
- $('html, body').animate({
- scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'
- }, duration, function() {
- scrollTo.active = 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) {
- if($('#post-container li.post-row[data-index="' + postIndex + '"]').attr('data-index') !== '0') {
- animateScroll();
- } else {
- navigator.update();
- highlightPost();
- }
- }
- }
-
- return ScrollTo;
-});
\ No newline at end of file
diff --git a/public/src/modules/navigator.js b/public/src/modules/navigator.js
index 29f295d2c5..72869c5912 100644
--- a/public/src/modules/navigator.js
+++ b/public/src/modules/navigator.js
@@ -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;
});