mirror of
https://github.com/discourse/discourse.git
synced 2025-03-20 22:01:40 +08:00
FIX: uses simpler pattern for custom href on extra nav items (#8015)
THe main advantage of this solution is that it will be called on each rerendered whereas the other is not once href has been set. Example API: ``` api.addNavigationBarItem({ name: "foo", displayName: "Foo", customHref: function(category, args) { const router = api.container.lookup("service:router"); const queryParams = { bar: "1" }; return router.urlFor(router.currentRouteName, category, { queryParams }); } }); ```
This commit is contained in:
parent
10b36c6446
commit
897cdfb596
@ -101,18 +101,8 @@ const NavItem = Discourse.Model.extend({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const ExtraNavItem = NavItem.extend({
|
const ExtraNavItem = NavItem.extend({
|
||||||
href: Ember.computed({
|
@computed("href")
|
||||||
set(key, value) {
|
href: href => href,
|
||||||
let customHref;
|
|
||||||
NavItem.customNavItemHrefs.forEach(function(cb) {
|
|
||||||
customHref = cb.call(this, this);
|
|
||||||
if (customHref) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}, this);
|
|
||||||
return customHref || value;
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
customFilter: null
|
customFilter: null
|
||||||
});
|
});
|
||||||
@ -189,6 +179,11 @@ NavItem.reopenClass({
|
|||||||
return item.customFilter.call(this, category, args);
|
return item.customFilter.call(this, category, args);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
extraItems.forEach(item => {
|
||||||
|
if (!item.customHref) return;
|
||||||
|
item.set("href", item.customHref.call(this, category, args));
|
||||||
|
});
|
||||||
|
|
||||||
return items.concat(extraItems);
|
return items.concat(extraItems);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user