diff --git a/public/src/app.js b/public/src/app.js index aa6137f003..dc66cfc462 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -34,7 +34,9 @@ app.cacheBuster = null; app.handleSearch(); } - handleNewTopic(); + $('#content').on('click', '#new_topic', function(){ + app.newTopic(); + }); require(['components'], function(components) { components.get('user/logout').on('click', app.logout); @@ -455,30 +457,28 @@ app.cacheBuster = null; }); }; - function handleNewTopic() { - $('#content').on('click', '#new_topic', function() { - var cid = ajaxify.data.cid; - if (cid) { - $(window).trigger('action:composer.topic.new', { - cid: cid + app.newTopic = function (cid) { + cid = cid || ajaxify.data.cid; + if (cid) { + $(window).trigger('action:composer.topic.new', { + cid: cid + }); + } else { + socket.emit('categories.getCategoriesByPrivilege', 'topics:create', function(err, categories) { + if (err) { + return app.alertError(err.message); + } + categories = categories.filter(function(category) { + return !category.link && !parseInt(category.parentCid, 10); }); - } else { - socket.emit('categories.getCategoriesByPrivilege', 'topics:create', function(err, categories) { - if (err) { - return app.alertError(err.message); - } - categories = categories.filter(function(category) { - return !category.link && !parseInt(category.parentCid, 10); + if (categories.length) { + $(window).trigger('action:composer.topic.new', { + cid: categories[0].cid }); - if (categories.length) { - $(window).trigger('action:composer.topic.new', { - cid: categories[0].cid - }); - } - }); - } - }); - } + } + }); + } + }; app.loadJQueryUI = function(callback) { if (typeof $().autocomplete === 'function') {