mirror of
https://github.com/discourse/discourse.git
synced 2024-11-24 08:32:26 +08:00
Give ExtraNavItem
more control over when it can be displayed.
This commit is contained in:
parent
ba64ebbf10
commit
ef78268c01
|
@ -668,6 +668,18 @@ class PluginApi {
|
|||
* displayName: "Discourse"
|
||||
* href: "https://www.discourse.org",
|
||||
* })
|
||||
*
|
||||
* An optional `customFilter` callback can be included to not display the
|
||||
* nav item on certain routes
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* addNavigationBarItem({
|
||||
* name: "link-to-bugs-category",
|
||||
* displayName: "bugs"
|
||||
* href: "/c/bugs",
|
||||
* customFilter: (category, args) => { category && category.get('name') !== 'bug' }
|
||||
* })
|
||||
*/
|
||||
addNavigationBarItem(item) {
|
||||
if (!item["name"]) {
|
||||
|
|
|
@ -102,7 +102,8 @@ const NavItem = Discourse.Model.extend({
|
|||
});
|
||||
|
||||
const ExtraNavItem = NavItem.extend({
|
||||
@computed("href") href: href => href
|
||||
@computed("href") href: href => href,
|
||||
customFilter: null
|
||||
});
|
||||
|
||||
NavItem.reopenClass({
|
||||
|
@ -169,7 +170,11 @@ NavItem.reopenClass({
|
|||
i => i !== null && !(category && i.get("name").indexOf("categor") === 0)
|
||||
);
|
||||
|
||||
return items.concat(NavItem.extraNavItems);
|
||||
const extraItems = NavItem.extraNavItems.filter(item => {
|
||||
return item.customFilter && item.customFilter.call(this, category, args);
|
||||
});
|
||||
|
||||
return items.concat(extraItems);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user