single arrows wont go all the way to bottom

v1.18.x
barisusakli 11 years ago
parent c9c68f8cbe
commit 1b31f5b2ca

@ -9,12 +9,11 @@ var dependencies = [
'forum/topic/threadTools', 'forum/topic/threadTools',
'forum/topic/postTools', 'forum/topic/postTools',
'forum/topic/events', 'forum/topic/events',
'forum/topic/scrollTo',
'forum/topic/browsing', 'forum/topic/browsing',
'navigator' '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 = {}, var Topic = {},
currentUrl = ''; currentUrl = '';
@ -90,7 +89,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
var bookmark = localStorage.getItem('topic:' + tid + ':bookmark'); var bookmark = localStorage.getItem('topic:' + tid + ':bookmark');
var postIndex = getPostIndex(); var postIndex = getPostIndex();
if (postIndex) { 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) { } else if (bookmark && (!config.usePagination || (config.usePagination && pagination.currentPage === 1)) && ajaxify.variables.get('postcount') > 1) {
app.alert({ app.alert({
alert_id: 'bookmark', alert_id: 'bookmark',
@ -98,7 +97,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
timeout: 0, timeout: 0,
type: 'info', type: 'info',
clickfn : function() { clickfn : function() {
scrollTo.scrollToPost(parseInt(bookmark, 10), true); navigator.scrollToPost(parseInt(bookmark, 10), true);
}, },
closefn : function() { closefn : function() {
localStorage.removeItem('topic:' + tid + ':bookmark'); localStorage.removeItem('topic:' + tid + ':bookmark');
@ -206,7 +205,7 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
app.removeAlert('bookmark'); app.removeAlert('bookmark');
} }
if (!scrollTo.active) { if (!navigator.scrollActive) {
var parts = ajaxify.removeRelativePath(window.location.pathname.slice(1)).split('/'); var parts = ajaxify.removeRelativePath(window.location.pathname.slice(1)).split('/');
var topicId = parts[1], var topicId = parts[1],
slug = parts[2]; slug = parts[2];
@ -355,14 +354,14 @@ define('forum/topic', dependencies, function(pagination, infinitescroll, threadT
} }
function loadMorePosts(direction) { function loadMorePosts(direction) {
if (!$('#post-container').length || scrollTo.active) { if (!$('#post-container').length || navigator.scrollActive) {
return; return;
} }
infinitescroll.calculateAfter(direction, '#post-container .post-row[data-index!="0"]', config.postsPerPage, function(after, offset, el) { infinitescroll.calculateAfter(direction, '#post-container .post-row[data-index!="0"]', config.postsPerPage, function(after, offset, el) {
loadPostsAfter(after, function() { loadPostsAfter(after, function() {
if (direction < 0 && el) { if (direction < 0 && el) {
scrollTo.scrollToPost(el.attr('data-index'), false, 0, offset); navigator.scrollToPost(el.attr('data-index'), false, 0, offset);
} }
}); });
}); });

@ -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;
});

@ -1,14 +1,15 @@
'use strict'; '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 navigator = {};
var index = 1; var index = 1;
var count = 0; var count = 0;
navigator.scrollActive = false;
navigator.init = function(selector, count, callback, toTop, toBottom) { navigator.init = function(selector, count, callback, toTop, toBottom) {
@ -69,7 +70,6 @@ define('navigator', function() {
} }
navigator.update = function() { navigator.update = function() {
toggle(!!count); toggle(!!count);
$($(navigator.selector).get().reverse()).each(function() { $($(navigator.selector).get().reverse()).each(function() {
@ -100,13 +100,13 @@ define('navigator', function() {
navigator.scrollUp = function () { navigator.scrollUp = function () {
$('body,html').animate({ $('body,html').animate({
scrollTop: 0 scrollTop: $('body').scrollTop() - $(window).height()
}); });
}; };
navigator.scrollDown = function () { navigator.scrollDown = function () {
$('body,html').animate({ $('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); 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; return navigator;
}); });

Loading…
Cancel
Save