Node.js based forum software built for the modern web
closes #3677
barisusakli1dc93f244618
diff --git a/package.json b/package.jsonindex 248a7aee7e..6ecdff0c41 100644--- a/package.json+++ b/package.json@@ -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",diff --git a/public/src/client/infinitescroll.js b/public/src/client/infinitescroll.jsindex 2499c3574f..6aa9d203b1 100644--- a/public/src/client/infinitescroll.js+++ b/public/src/client/infinitescroll.js@@ -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;diff --git a/public/src/client/topic/postTools.js b/public/src/client/topic/postTools.jsindex f3be36777b..2492b300b6 100644--- a/public/src/client/topic/postTools.js+++ b/public/src/client/topic/postTools.js@@ -246,7 +246,9 @@ define('forum/topic/postTools', ['share', 'navigator', 'components', 'translatorfunction 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, '-');}diff --git a/public/src/client/topic/posts.js b/public/src/client/topic/posts.jsindex b0161ac5e0..ba490a39e9 100644--- a/public/src/client/topic/posts.js+++ b/public/src/client/topic/posts.js@@ -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 posthtml.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) {diff --git a/public/src/modules/components.js b/public/src/modules/components.jsindex 71ae09ab99..da03bacd16 100644--- a/public/src/modules/components.js+++ b/public/src/modules/components.js@@ -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"]');diff --git a/src/socket.io/topics/infinitescroll.js b/src/socket.io/topics/infinitescroll.jsindex 6c24399f7c..acf662c21f 100644--- a/src/socket.io/topics/infinitescroll.js+++ b/src/socket.io/topics/infinitescroll.js@@ -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;}}