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 @@ +
+ + + +