How to add custom "New Topic" button?
-
Add an ID of 'newtopic' to a custom route, set the route to '#'
And you will need to add some js, in the custom header section.
<script> $(function(){ $('body').on('click', '#newtopic', function () { var 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); }); if (categories.length) { $(window).trigger('action:composer.topic.new', { cid: categories[0].cid }); } }); } }); }); </script>
That's the same function that's in app.js
Really, there should be an app.newTopic() that you can call anywhere. Then it would just be
$(function(){$('body').on('click', '#newtopic', app.newTopic);};
Could even be one of the available core routes.
Copyright © 2024 NodeBB | Contributors