How to add custom "New Topic" button?



  • i want to add new topic button in may navigation bar. how can i do it?


  • Community Rep

    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.


  • Admin

    This pr makes it a lot easier.



  • This post is deleted!

Log in to reply
 


Looks like your connection to NodeBB was lost, please wait while we try to reconnect.