v1.18.x
barisusakli 9 years ago
parent 5e0a7d7dac
commit 1dc93f2446

@ -48,9 +48,9 @@
"nodebb-plugin-soundpack-default": "0.1.4",
"nodebb-plugin-spam-be-gone": "0.4.2",
"nodebb-rewards-essentials": "0.0.5",
"nodebb-theme-lavender": "2.0.2",
"nodebb-theme-persona": "3.0.22",
"nodebb-theme-vanilla": "4.0.14",
"nodebb-theme-lavender": "2.0.3",
"nodebb-theme-persona": "3.0.23",
"nodebb-theme-vanilla": "4.0.15",
"nodebb-widget-essentials": "2.0.1",
"npm": "^2.1.4",
"passport": "^0.3.0",

@ -17,13 +17,14 @@ define('forum/infinitescroll', ['translator'], function(translator) {
};
function onScroll() {
var top = $(window).height() * 0.3 + topOffset,
bottom = ($(document).height() - $(window).height()) * 0.85,
currentScrollTop = $(window).scrollTop();
var currentScrollTop = $(window).scrollTop();
var scrollPercent = 100 * currentScrollTop / ($(document).height() - $(window).height());
if (currentScrollTop < top && currentScrollTop < previousScrollTop) {
var top = 20, bottom = 80;
if (scrollPercent < top && currentScrollTop < previousScrollTop) {
callback(-1);
} else if (currentScrollTop > bottom && currentScrollTop > previousScrollTop) {
} else if (scrollPercent > bottom && currentScrollTop > previousScrollTop) {
callback(1);
}
previousScrollTop = currentScrollTop;

@ -246,7 +246,9 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translator
function getUserName(button) {
var username = '',
post = button.parents('[data-pid]');
if (button.attr('component') === 'topic/reply') {
return username;
}
if (post.length) {
username = post.attr('data-username').replace(/\s/g, '-');
}

@ -106,11 +106,16 @@ define('forum/topic/posts', [
data.posts.forEach(function(post) {
var p = components.get('post', 'pid', post.pid);
if (p.hasClass('new')) {
p.remove()
p.remove();
}
});
}
data.posts = data.posts.filter(function(post) {
if (components.get('post', 'pid', post.pid).length !== 0) {
console.log('removed', post.pid)
}
return components.get('post', 'pid', post.pid).length === 0;
});
}
@ -141,17 +146,18 @@ define('forum/topic/posts', [
} else if (before) {
// Save document height and position for future reference (about 5 lines down)
var height = $(document).height(),
scrollTop = $(document).scrollTop();
scrollTop = $(window).scrollTop();
// Insert the new post
html.insertBefore(before);
// Now restore the relative position the user was on prior to new post insertion
$(document).scrollTop(scrollTop + ($(document).height() - height));
$(window).scrollTop(scrollTop + ($(document).height() - height));
} else {
components.get('topic').append(html);
}
removeExtraPosts(direction);
html.hide().fadeIn('slow');
var pids = [];
@ -165,6 +171,23 @@ define('forum/topic/posts', [
});
}
function removeExtraPosts(direction) {
var posts = components.get('post');
if (posts.length > 40) {
var removeCount = posts.length - 40;
if (direction > 0) {
var height = $(document).height(),
scrollTop = $(window).scrollTop();
posts.slice(0, removeCount).remove();
$(window).scrollTop(scrollTop + ($(document).height() - height));
} else {
posts.slice(posts.length - removeCount).remove();
}
}
}
function onNewPostsLoaded(html, pids) {
if (app.user.uid) {
socket.emit('posts.getPrivileges', pids, function(err, privileges) {

@ -4,7 +4,7 @@ define('components', function() {
components.core = {
'post': function(name, value) {
return $('[data-' + name + '="' + value + '"]');
return $('[component="post"][data-' + name + '="' + value + '"]');
},
'post/content': function(pid) {
return components.core.post('pid', pid).find('[component="post/content"]');

@ -34,19 +34,23 @@ module.exports = function(SocketTopics) {
}
var set = 'tid:' + data.tid + ':posts';
if (results.settings.topicPostSort === 'most_votes') {
set = 'tid:' + data.tid + ':posts:votes';
}
var reverse = results.settings.topicPostSort === 'newest_to_oldest' || results.settings.topicPostSort === 'most_votes';
var start = Math.max(0, parseInt(data.after, 10));
var infScrollPostsPerPage = 10;
if (data.direction === -1) {
start = start - (reverse ? -infScrollPostsPerPage : infScrollPostsPerPage);
}
if (reverse) {
start = results.topic.postcount - 1 - start;
if (results.settings.topicPostSort === 'most_votes') {
set = 'tid:' + data.tid + ':posts:votes';
if (data.direction > 0) {
if (reverse) {
start = results.topic.postcount - start;
}
} else {
if (reverse) {
start = results.topic.postcount - start - infScrollPostsPerPage - 1;
} else {
start = start - infScrollPostsPerPage - 1;
}
}

Loading…
Cancel
Save