Skip to content

Node.js based forum software built for the modern web

fixed direct loading of popular page

Baris Soner Usakliab2b0e656073
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 @@
+<ol class="breadcrumb">
+ <li><a href="{relative_path}/">Home</a></li>
+ <li class="active">[[global:header.popular]] <a href="{relative_path}/popular.rss"><i class="fa fa-rss-square"></i></a></li>
+</ol>
+
+<ul class="nav nav-pills">
+ <li class=''><a href='{relative_path}/popular/posts'>[[global:posts]]</a></li>
+ <li class=''><a href='{relative_path}/popular/views'>[[global:views]]</a></li>
+</ul>
+
+<br />
+
+<a href="{relative_path}/popular">
+ <div class="alert alert-warning hide" id="new-topics-alert"></div>
+</a>
+
+<!-- IF !topics.length -->
+<div class="alert alert-warning" id="category-no-topics">
+ <strong>There are no popular topics.</strong>
+</div>
+<!-- ENDIF !topics.length -->
+
+<div class="category row">
+ <div class="col-md-12">
+ <ul id="topics-container" data-nextstart="{nextStart}">
+ <!-- BEGIN topics -->
+ <li class="category-item {topics.deleted-class}">
+ <div class="col-md-12 col-xs-12 panel panel-default topic-row">
+ <a href="{relative_path}/user/{topics.userslug}" class="pull-left">
+ <img class="img-rounded user-img" src="{topics.picture}" title="{topics.username}" />
+ </a>
+
+ <h3>
+ <a href="{relative_path}/topic/{topics.slug}">
+ <span class="topic-title">
+ <strong>
+ <i class="fa {topics.pin-icon}"></i>
+ <i class="fa {topics.lock-icon}"></i>
+ </strong>
+ {topics.title}
+ </span>
+ </a>
+ </h3>
+
+ <small>
+ <span class="topic-stats">
+ posts
+ <strong class="human-readable-number" title="{topics.postcount}">{topics.postcount}</strong>
+ </span>
+ |
+ <span class="topic-stats">
+ views
+ <strong class="human-readable-number" title="{topics.viewcount}">{topics.viewcount}</strong>
+ </span>
+ |
+ <span>
+ posted in
+ <a href="{relative_path}/category/{topics.categorySlug}">
+ <i class="fa {topics.categoryIcon}"></i> {topics.categoryName}
+ </a>
+ <span class="timeago" title="{topics.relativeTime}"></span>
+ </span>
+ </span>
+
+ <span class="pull-right">
+ <!-- IF topics.unreplied -->
+ No one has replied
+ <!-- ELSE -->
+ <a href="{relative_path}/user/{topics.teaser_userslug}">
+ <img class="teaser-pic" src="{topics.teaser_userpicture}" title="{topics.teaser_username}"/>
+ </a>
+ <a href="{relative_path}/topic/{topics.slug}#{topics.teaser_pid}">
+ replied
+ </a>
+ <span class="timeago" title="{topics.teaser_timestamp}"></span>
+ <!-- ENDIF topics.unreplied -->
+ </span>
+ </small>
+ </div>
+ </li>
+ <!-- END topics -->
+ </ul>
+ </div>
+</div>
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');