Skip to content

Instantly share code, notes, and snippets.

@psychobunny
Created April 1, 2014 21:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psychobunny/9923582 to your computer and use it in GitHub Desktop.
Save psychobunny/9923582 to your computer and use it in GitHub Desktop.
[nodebb-script-category-dropdown] Category Dropdown Widget for NodeBB
<div id="category-selector" style="position: relative">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button">Categories <span class="caret"></span></button>
<ul class="dropdown-menu" aria-labelledby="category-selector">
</ul>
</div>
<br />
<script>
// If you're using the custom homepage mod, switch the api call to /api/forum
$.get(RELATIVE_PATH + '/api/home', {}, function(data) {
var categories = data.categories
for (var c in categories) {
if (categories.hasOwnProperty(c)) {
var category = categories[c];
$('#category-selector .dropdown-menu').append('<li role="presentation"><a role="menuitem" tabindex="-1" href="category/' + category.slug + '"><i class="fa ' + category.icon + '" style="color: ' + category.bgColor + '"></i> ' + category.name + '</a></li>');
}
}
});
</script>
@psychobunny
Copy link
Author

@cnvo
Copy link

cnvo commented Apr 2, 2014

You are missing {relative_path} before the href="category/'
So it should be; href="{relative_path}/category/'

But hey, it looks good! Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment