mirror of
https://github.com/discourse/discourse.git
synced 2025-02-26 01:39:39 +08:00
FEATURE: plugin hooks for topic list nav items
This commit is contained in:
parent
dcaf8237bd
commit
5ebd12c070
@ -1,3 +1,5 @@
|
|||||||
|
/* You might be looking for navigation-item. */
|
||||||
|
|
||||||
export default Ember.Component.extend({
|
export default Ember.Component.extend({
|
||||||
tagName: 'li',
|
tagName: 'li',
|
||||||
classNameBindings: ['active'],
|
classNameBindings: ['active'],
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
@module Discourse
|
@module Discourse
|
||||||
**/
|
**/
|
||||||
|
|
||||||
Discourse.NavItem = Discourse.Model.extend({
|
const NavItem = Discourse.Model.extend({
|
||||||
|
|
||||||
displayName: function() {
|
displayName: function() {
|
||||||
var categoryName = this.get('categoryName'),
|
var categoryName = this.get('categoryName'),
|
||||||
@ -25,7 +25,7 @@ Discourse.NavItem = Discourse.Model.extend({
|
|||||||
extra.categoryName = Discourse.Formatter.toTitleCase(categoryName);
|
extra.categoryName = Discourse.Formatter.toTitleCase(categoryName);
|
||||||
}
|
}
|
||||||
return I18n.t("filters." + name.replace("/", ".") + ".title", extra);
|
return I18n.t("filters." + name.replace("/", ".") + ".title", extra);
|
||||||
}.property('categoryName,name,count'),
|
}.property('categoryName', 'name', 'count'),
|
||||||
|
|
||||||
topicTrackingState: function() {
|
topicTrackingState: function() {
|
||||||
return Discourse.TopicTrackingState.current();
|
return Discourse.TopicTrackingState.current();
|
||||||
@ -45,8 +45,13 @@ Discourse.NavItem = Discourse.Model.extend({
|
|||||||
return null;
|
return null;
|
||||||
}.property('name'),
|
}.property('name'),
|
||||||
|
|
||||||
// href from this item
|
|
||||||
href: function() {
|
href: function() {
|
||||||
|
var customHref = null;
|
||||||
|
_.each(NavItem.customNavItemHrefs, function(cb) {
|
||||||
|
customHref = cb.call(this, this);
|
||||||
|
if (customHref) { return false; }
|
||||||
|
}, this);
|
||||||
|
if (customHref) { return customHref; }
|
||||||
return Discourse.getURL("/") + this.get('filterMode');
|
return Discourse.getURL("/") + this.get('filterMode');
|
||||||
}.property('filterMode'),
|
}.property('filterMode'),
|
||||||
|
|
||||||
@ -79,10 +84,13 @@ Discourse.NavItem = Discourse.Model.extend({
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Discourse.NavItem.reopenClass({
|
NavItem.reopenClass({
|
||||||
|
|
||||||
|
extraArgsCallbacks: [],
|
||||||
|
customNavItemHrefs: [],
|
||||||
|
|
||||||
// create a nav item from the text, will return null if there is not valid nav item for this particular text
|
// create a nav item from the text, will return null if there is not valid nav item for this particular text
|
||||||
fromText: function(text, opts) {
|
fromText(text, opts) {
|
||||||
var split = text.split(","),
|
var split = text.split(","),
|
||||||
name = split[0],
|
name = split[0],
|
||||||
testName = name.split("/")[0],
|
testName = name.split("/")[0],
|
||||||
@ -92,13 +100,17 @@ Discourse.NavItem.reopenClass({
|
|||||||
if (!Discourse.Category.list() && testName === "categories") return null;
|
if (!Discourse.Category.list() && testName === "categories") return null;
|
||||||
if (!Discourse.Site.currentProp('top_menu_items').contains(testName)) return null;
|
if (!Discourse.Site.currentProp('top_menu_items').contains(testName)) return null;
|
||||||
|
|
||||||
var args = { name: name, hasIcon: name === "unread" };
|
var args = { name: name, hasIcon: name === "unread" }, extra = null, self = this;
|
||||||
if (opts.category) { args.category = opts.category; }
|
if (opts.category) { args.category = opts.category; }
|
||||||
if (opts.noSubcategories) { args.noSubcategories = true; }
|
if (opts.noSubcategories) { args.noSubcategories = true; }
|
||||||
|
_.each(NavItem.extraArgsCallbacks, function(cb) {
|
||||||
|
extra = cb.call(self, text, opts);
|
||||||
|
_.merge(args, extra);
|
||||||
|
});
|
||||||
return Discourse.NavItem.create(args);
|
return Discourse.NavItem.create(args);
|
||||||
},
|
},
|
||||||
|
|
||||||
buildList: function(category, args) {
|
buildList(category, args) {
|
||||||
args = args || {};
|
args = args || {};
|
||||||
if (category) { args.category = category }
|
if (category) { args.category = category }
|
||||||
|
|
||||||
@ -118,3 +130,11 @@ Discourse.NavItem.reopenClass({
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export default NavItem;
|
||||||
|
export function extraNavItemProperties(cb) {
|
||||||
|
NavItem.extraArgsCallbacks.push(cb);
|
||||||
|
}
|
||||||
|
export function customNavItemHref(cb) {
|
||||||
|
NavItem.customNavItemHrefs.push(cb);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user