diff --git a/public/src/forum/popular.js b/public/src/forum/popular.js new file mode 100644 index 0000000000..f85e38ccb2 --- /dev/null +++ b/public/src/forum/popular.js @@ -0,0 +1,46 @@ +define(['forum/recent'], function(recent) { + var Popular = {}, + loadingMoreTopics = false, + active = ''; + + Popular.init = function() { + app.enterRoom('recent_posts'); + + $('#new-topics-alert').on('click', function() { + $(this).addClass('hide'); + }); + + recent.watchForNewPosts(); + + active = recent.selectActivePill(); + + app.enableInfiniteLoading(function() { + if(!loadingMoreTopics) { + loadMoreTopics(); + } + }); + + function loadMoreTopics() { + loadingMoreTopics = true; + socket.emit('topics.loadMoreFromSet', { + set: 'topics:' + $('.nav-pills .active a').html().toLowerCase(), + after: $('#topics-container').attr('data-nextstart') + }, function(err, data) { + if(err) { + return app.alertError(err.message); + } + + if (data.topics && data.topics.length) { + recent.onTopicsLoaded('popular', data.topics); + $('#topics-container').attr('data-nextstart', data.nextStart); + } else { + $('#load-more-btn').hide(); + } + + loadingMoreTopics = false; + }); + } + }; + + return Popular; +}); \ No newline at end of file diff --git a/public/templates/popular.tpl b/public/templates/popular.tpl new file mode 100644 index 0000000000..d26975466e --- /dev/null +++ b/public/templates/popular.tpl @@ -0,0 +1,84 @@ + + + + +
+ + +
+
+ + +
+ There are no popular topics. +
+ + +
+
+ +
+
diff --git a/src/webserver.js b/src/webserver.js index 6cf27f163d..5c3a5874dc 100644 --- a/src/webserver.js +++ b/src/webserver.js @@ -868,6 +868,16 @@ module.exports.server = server; }); + app.get('/popular/:term?', function (req, res) { + app.build_header({ + req: req, + res: res + }, function (err, header) { + res.send(header + app.create_route('popular/' + req.params.term, null, 'popular') + templates.footer); + }); + + }); + app.get('/outgoing', function (req, res) { if (!req.query.url) { return res.redirect('/404');