Node.js based forum software built for the modern web
closes #2794
barisusaklif7f453f8cd1f
diff --git a/public/src/client/category.js b/public/src/client/category.jsindex e57587fa89..ec3992283d 100644--- a/public/src/client/category.js+++ b/public/src/client/category.js@@ -20,6 +20,12 @@ define('forum/category', [}});+ $(window).on('action:composer.topics.post', function(ev, data) {+ localStorage.removeItem('category:' + data.data.cid + ':bookmark');+ localStorage.removeItem('category:' + data.data.cid + ':bookmark:clicked');+ ajaxify.go('topic/' + data.data.slug);+ });+function removeListeners() {socket.removeListener('event:new_topic', Category.onNewTopic);categoryTools.removeListeners();@@ -50,11 +56,11 @@ define('forum/category', [}$('#topics-container').on('click', '.topic-title', function() {- var clickedTid = $(this).parents('li.category-item[data-tid]').attr('data-tid');+ var clickedIndex = $(this).parents('[data-index]').attr('data-index');$('#topics-container li.category-item').each(function(index, el) {- if($(el).offset().top - $(window).scrollTop() > 0) {- localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-tid'));- localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedTid);+ if ($(el).offset().top - $(window).scrollTop() > 0) {+ localStorage.setItem('category:' + cid + ':bookmark', $(el).attr('data-index'));+ localStorage.setItem('category:' + cid + ':bookmark:clicked', clickedIndex);return false;}});@@ -94,7 +100,7 @@ define('forum/category', [};$(window).on('action:popstate', function(ev, data) {- if(data.url.indexOf('category/') === 0) {+ if (data.url.indexOf('category/') === 0) {var cid = data.url.match(/^category\/(\d+)/);if (cid && cid[1]) {cid = cid[1];@@ -103,52 +109,44 @@ define('forum/category', [return;}- var bookmark = localStorage.getItem('category:' + cid + ':bookmark');- var clicked = localStorage.getItem('category:' + cid + ':bookmark:clicked');+ var bookmarkIndex = localStorage.getItem('category:' + cid + ':bookmark');+ var clickedIndex = localStorage.getItem('category:' + cid + ':bookmark:clicked');- if (!bookmark) {+ if (!bookmarkIndex) {return;}- if(config.usePagination) {- socket.emit('topics.getTidPage', bookmark, function(err, page) {- if (err) {- return;- }- if(parseInt(page, 10) !== pagination.currentPage) {- pagination.loadPage(page);- } else {- Category.scrollToTopic(bookmark, clicked, 400);- }- });+ if (config.usePagination) {+ var page = Math.ceil((parseInt(bookmarkIndex, 10) + 1) / config.topicsPerPage);+ if (parseInt(page, 10) !== pagination.currentPage) {+ pagination.loadPage(page, function() {+ Category.scrollToTopic(bookmarkIndex, clickedIndex, 400);+ });+ } else {+ Category.scrollToTopic(bookmarkIndex, clickedIndex, 400);+ }} else {- socket.emit('topics.getTidIndex', bookmark, function(err, index) {- if (err) {- return;- }-- if (index === 0) {- Category.highlightTopic(clicked);- return;- }+ if (bookmarkIndex === 0) {+ Category.highlightTopic(clickedIndex);+ return;+ }- if (index < 0) {- index = 0;- }+ if (bookmarkIndex < 0) {+ bookmarkIndex = 0;+ }- $('#topics-container').empty();+ $('#topics-container').empty();- loadTopicsAfter(index, function() {- Category.scrollToTopic(bookmark, clicked, 0);- });+ loadTopicsAfter(bookmarkIndex, function() {+ Category.scrollToTopic(bookmarkIndex, clickedIndex, 0);});}}});- Category.highlightTopic = function(tid) {- var highlight = $('#topics-container li.category-item[data-tid="' + tid + '"]');- if(highlight.length && !highlight.hasClass('highlight')) {+ Category.highlightTopic = function(topicIndex) {+ var highlight = $('#topics-container [data-index="' + topicIndex + '"]');+ if (highlight.length && !highlight.hasClass('highlight')) {highlight.addClass('highlight');setTimeout(function() {highlight.removeClass('highlight');@@ -156,27 +154,24 @@ define('forum/category', [}};- Category.scrollToTopic = function(tid, clickedTid, duration, offset) {- if(!tid) {+ Category.scrollToTopic = function(bookmarkIndex, clickedIndex, duration, offset) {+ if (!bookmarkIndex) {return;}- if(!offset) {+ if (!offset) {offset = 0;}- if($('#topics-container li.category-item[data-tid="' + tid + '"]').length) {- var cid = ajaxify.variables.get('category_id');- var scrollTo = $('#topics-container li.category-item[data-tid="' + tid + '"]');-- if (cid && scrollTo.length) {- $('html, body').animate({- scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'- }, duration !== undefined ? duration : 400, function() {- Category.highlightTopic(clickedTid);- navigator.update();- });- }+ var scrollTo = $('#topics-container [data-index="' + bookmarkIndex + '"]');+ var cid = ajaxify.variables.get('category_id');+ if (scrollTo.length && cid) {+ $('html, body').animate({+ scrollTop: (scrollTo.offset().top - $('#header-menu').height() - offset) + 'px'+ }, duration !== undefined ? duration : 400, function() {+ Category.highlightTopic(clickedIndex);+ navigator.update();+ });}};@@ -191,7 +186,7 @@ define('forum/category', [Category.onNewTopic = function(topic) {var cid = ajaxify.variables.get('category_id');- if(!topic || parseInt(topic.cid, 10) !== parseInt(cid, 10)) {+ if (!topic || parseInt(topic.cid, 10) !== parseInt(cid, 10)) {return;}@@ -324,7 +319,7 @@ define('forum/category', [infinitescroll.calculateAfter(direction, '#topics-container .category-item[data-tid]', config.topicsPerPage, false, function(after, offset, el) {loadTopicsAfter(after, function() {if (direction < 0 && el) {- Category.scrollToTopic(el.attr('data-tid'), null, 0, offset);+ Category.scrollToTopic(el.attr('data-index'), null, 0, offset);}});});diff --git a/public/src/modules/composer.js b/public/src/modules/composer.jsindex 84c4c4e9dd..ca345406d0 100644--- a/public/src/modules/composer.js+++ b/public/src/modules/composer.js@@ -432,13 +432,7 @@ define('composer', [};action = 'topics.post';- socket.emit(action, composerData, function(err, topic) {- done(err);-- if (!err) {- ajaxify.go('topic/' + topic.slug);- }- });+ socket.emit(action, composerData, done);} else if (parseInt(postData.tid, 10) > 0) {composerData = {tid: postData.tid,@@ -463,7 +457,7 @@ define('composer', [socket.emit(action, composerData, done);}- function done(err) {+ function done(err, data) {$('.action-bar button').removeAttr('disabled');if (err) {if (err.message === '[[error:email-not-confirmed]]') {@@ -476,7 +470,7 @@ define('composer', [discard(post_uuid);drafts.removeDraft(postData.save_id);- $(window).trigger('action:composer.' + action, composerData);+ $(window).trigger('action:composer.' + action, {composerData: composerData, data: data});}}diff --git a/src/groups.js b/src/groups.jsindex 21575db866..ba3ceb41aa 100644--- a/src/groups.js+++ b/src/groups.js@@ -248,8 +248,8 @@ var async = require('async'),plugins.fireHook('filter:group.get', {group: results.base}, function(err, data) {callback(err, data ? data.group : null);- });- });+ });+ });});};@@ -906,10 +906,10 @@ var async = require('async'),}return group;});-+plugins.fireHook('filter:groups.get', {groups: groupData}, function(err, data) {- callback(err, data ? data.groups : null);- });+ callback(err, data ? data.groups : null);+ });});};diff --git a/src/socket.io/topics.js b/src/socket.io/topics.jsindex 5cc6cb3bad..a4ee937429 100644--- a/src/socket.io/topics.js+++ b/src/socket.io/topics.js@@ -518,14 +518,6 @@ SocketTopics.getPageCount = function(socket, tid, callback) {topics.getPageCount(tid, socket.uid, callback);};-SocketTopics.getTidPage = function(socket, tid, callback) {- topics.getTidPage(tid, socket.uid, callback);-};--SocketTopics.getTidIndex = function(socket, tid, callback) {- categories.getTopicIndex(tid, callback);-};-SocketTopics.searchTags = function(socket, data, callback) {topics.searchTags(data, callback);};diff --git a/src/topics/suggested.js b/src/topics/suggested.jsindex fd3455f726..ff6e16aada 100644--- a/src/topics/suggested.js+++ b/src/topics/suggested.js@@ -3,11 +3,11 @@var async = require('async'),_ = require('underscore'),-+categories = require('../categories'),search = require('../search'),- db = require('../database');-+ db = require('../database');+module.exports = function(Topics) {@@ -21,7 +21,7 @@ module.exports = function(Topics) {},categoryTids: function(next) {getCategoryTids(tid, next);- }+ }}, function(err, results) {if (err) {return callback(err);@@ -29,8 +29,8 @@ module.exports = function(Topics) {var tids = results.tagTids.concat(results.searchTids).concat(results.categoryTids);tids = tids.filter(function(_tid, index, array) {return parseInt(_tid, 10) !== parseInt(tid, 10) && array.indexOf(_tid) === index;- }).slice(start, end + 1);-+ }).slice(start, end + 1);+Topics.getTopics(tids, uid, callback);});};@@ -48,18 +48,18 @@ module.exports = function(Topics) {function(data, next) {next(null, _.unique(_.flatten(data)));}- ], callback);- }+ ], callback);+ }function getSearchTids(tid, callback) {async.waterfall([function(next) {- Topics.getTopicField(tid, 'title', next);+ Topics.getTopicField(tid, 'title', next);},function(title, next) {search.searchQuery('topic', title, next);}- ], callback);+ ], callback);}function getCategoryTids(tid, callback) {@@ -68,7 +68,7 @@ module.exports = function(Topics) {return callback(err, []);}categories.getTopicIds('cid:' + cid + ':tids', true, 0, 9, callback);- });+ });}-+};\ No newline at end of file