From b65f456d7079768d6ba246f77be28d78c785005f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Tue, 31 Mar 2015 14:19:08 -0400 Subject: [PATCH] closes #2880 --- public/src/app.js | 22 ++++++++++++++++++++++ public/src/client/category.js | 4 ---- public/src/client/recent.js | 11 ----------- 3 files changed, 22 insertions(+), 15 deletions(-) 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); };