diff --git a/public/src/forum/recent.js b/public/src/forum/recent.js new file mode 100644 index 0000000000..9cc0c31208 --- /dev/null +++ b/public/src/forum/recent.js @@ -0,0 +1,50 @@ +(function() { + app.enter_room('recent_posts'); + + ajaxify.register_events([ + 'event:new_topic', + 'event:new_post' + ]); + + var newTopicCount = 0, newPostCount = 0; + + $('#new-topics-alert').on('click', function() { + $(this).hide(); + }); + + socket.on('event:new_topic', function(data) { + + ++newTopicCount; + updateAlertText(); + + }); + + function updateAlertText() { + var text = ''; + + if(newTopicCount > 1) + text = 'There are ' + newTopicCount + ' new topics'; + else if(newTopicCount === 1) + text = 'There is 1 new topic'; + else + text = 'There are no new topics'; + + if(newPostCount > 1) + text += ' and ' + newPostCount + ' new posts.'; + else if(newPostCount === 1) + text += ' and 1 new post.'; + else + text += ' and no new posts.'; + + text += ' Click here to reload.'; + + $('#new-topics-alert').html(text).fadeIn('slow'); + } + + socket.on('event:new_post', function(data) { + ++newPostCount; + updateAlertText(); + + }); + +})(); \ No newline at end of file diff --git a/public/templates/config.json b/public/templates/config.json index 9f998567ca..f84272d554 100644 --- a/public/templates/config.json +++ b/public/templates/config.json @@ -25,7 +25,7 @@ "users[^]*followers": "followers", "users/[^]*": "account", - "recent": "category", + "recent": "recent", "popular": "category", "active": "category" }, diff --git a/public/templates/recent.tpl b/public/templates/recent.tpl new file mode 100644 index 0000000000..6cb0beb1ec --- /dev/null +++ b/public/templates/recent.tpl @@ -0,0 +1,52 @@ +