Skip to content

Node.js based forum software built for the modern web

closes #2880

Barış Soner Uşaklıb65f456d7079
diff --git a/public/src/app.js b/public/src/app.js
index b79eefc9a7..70c49581ab 100644
--- a/public/src/app.js
+++ b/public/src/app.js
@@ -471,6 +471,26 @@ app.cacheBuster = null;
});
}
+ function handleNewTopic() {
+ $('#content').on('click', '#new_topic', function() {
+ require(['composer'], function(composer) {
+ var cid = ajaxify.variables.get('category_id');
+ if (cid) {
+ composer.newTopic(cid);
+ } else {
+ socket.emit('categories.getCategoriesByPrivilege', 'topics:create', function(err, categories) {
+ if (err) {
+ return app.alertError(err.message);
+ }
+ if (categories.length) {
+ composer.newTopic(categories[0].cid);
+ }
+ });
+ }
+ });
+ });
+ }
+
app.load = function() {
$('document').ready(function () {
var url = ajaxify.start(window.location.pathname.slice(1), true, window.location.search);
@@ -482,6 +502,8 @@ app.cacheBuster = null;
handleSearch();
}
+ handleNewTopic();
+
$('#logout-link').on('click', app.logout);
Visibility.change(function(e, state){
diff --git a/public/src/client/category.js b/public/src/client/category.js
index 8aa3b248d8..77228627a4 100644
--- a/public/src/client/category.js
+++ b/public/src/client/category.js
@@ -33,10 +33,6 @@ define('forum/category', [
share.addShareHandlers(ajaxify.variables.get('category_name'));
- $('#new_post').on('click', function () {
- composer.newTopic(cid);
- });
-
socket.removeListener('event:new_topic', Category.onNewTopic);
socket.on('event:new_topic', Category.onNewTopic);
diff --git a/public/src/client/recent.js b/public/src/client/recent.js
index bb78a68080..909cec052e 100644
--- a/public/src/client/recent.js
+++ b/public/src/client/recent.js
@@ -23,17 +23,6 @@ define('forum/recent', ['forum/infinitescroll', 'composer', 'components'], funct
$(this).addClass('hide');
});
- $('#new_topic').on('click', function() {
- socket.emit('categories.getCategoriesByPrivilege', 'topics:create', function(err, categories) {
- if (err) {
- return app.alertError(err.message);
- }
- if (categories.length) {
- composer.newTopic(categories[0].cid);
- }
- });
- });
-
infinitescroll.init(Recent.loadMoreTopics);
};