diff --git a/public/language/en_GB/global.json b/public/language/en_GB/global.json index 3cdef1742c..2796b08ed0 100644 --- a/public/language/en_GB/global.json +++ b/public/language/en_GB/global.json @@ -22,6 +22,7 @@ "header.admin": "Admin", "header.recent": "Recent", "header.unread": "Unread", + "header.popular": "Popular", "header.users": "Users", "header.chats": "Chats", "header.notifications": "Notifications", @@ -47,5 +48,8 @@ "alert.banned.message": "You are banned you will be logged out!", "alert.unfollow": "You are no longer following %1!", - "alert.follow": "You are now following %1!" + "alert.follow": "You are now following %1!", + + "posts": "Posts", + "views": "Views" } 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/src/forum/recent.js b/public/src/forum/recent.js index 17d4602403..15e1d63ceb 100644 --- a/public/src/forum/recent.js +++ b/public/src/forum/recent.js @@ -7,27 +7,21 @@ define(function() { var active = ''; + function getActiveSection() { + var url = window.location.href, + parts = url.split('/'), + active = parts[parts.length - 1]; + return active; + } + Recent.init = function() { app.enterRoom('recent_posts'); Recent.watchForNewPosts(); - function getActiveSection() { - var url = window.location.href, - parts = url.split('/'), - active = parts[parts.length - 1]; - return active; - } - active = getActiveSection(); + active = Recent.selectActivePill(); - jQuery('.nav-pills li').removeClass('active'); - jQuery('.nav-pills li a').each(function() { - if (this.getAttribute('href').match(active)) { - jQuery(this.parentNode).addClass('active'); - return false; - } - }); $('#new-topics-alert').on('click', function() { $(this).addClass('hide'); @@ -41,6 +35,20 @@ define(function() { }); }; + Recent.selectActivePill = function() { + var active = getActiveSection(); + + jQuery('.nav-pills li').removeClass('active'); + jQuery('.nav-pills li a').each(function() { + if (this.getAttribute('href').match(active)) { + jQuery(this.parentNode).addClass('active'); + return false; + } + }); + + return active; + } + Recent.watchForNewPosts = function () { newPostCount = 0; diff --git a/public/templates/header.tpl b/public/templates/header.tpl index 1de45045aa..f7cd8f1ebc 100644 --- a/public/templates/header.tpl +++ b/public/templates/header.tpl @@ -57,11 +57,14 @@