REFACTOR: User menu profile link for extensibility (#8039)
This minor refactor extracts `UserMenuLinks#profileLink` & `UserMenuLinks#linkHtml` to allow plugins / themes to control the profile link definition, and more importantly, how it is rendered.
This commit is contained in:
parent
8a5eb0bdb5
commit
698e97125e
|
@ -13,6 +13,23 @@ export function addUserMenuGlyph(glyph) {
|
||||||
createWidget("user-menu-links", {
|
createWidget("user-menu-links", {
|
||||||
tagName: "div.menu-links-header",
|
tagName: "div.menu-links-header",
|
||||||
|
|
||||||
|
profileLink() {
|
||||||
|
const link = {
|
||||||
|
route: "user",
|
||||||
|
model: this.currentUser,
|
||||||
|
className: "user-activity-link",
|
||||||
|
icon: "user",
|
||||||
|
rawLabel: formatUsername(this.currentUser.username)
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.currentUser.is_anonymous) {
|
||||||
|
link.label = "user.profile";
|
||||||
|
link.rawLabel = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return link;
|
||||||
|
},
|
||||||
|
|
||||||
bookmarksGlyph() {
|
bookmarksGlyph() {
|
||||||
return {
|
return {
|
||||||
label: "user.bookmarks",
|
label: "user.bookmarks",
|
||||||
|
@ -31,6 +48,10 @@ createWidget("user-menu-links", {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
linkHtml(link) {
|
||||||
|
return this.attach("link", link);
|
||||||
|
},
|
||||||
|
|
||||||
glyphHtml(glyph) {
|
glyphHtml(glyph) {
|
||||||
return this.attach("link", $.extend(glyph, { hideLabel: true }));
|
return this.attach("link", $.extend(glyph, { hideLabel: true }));
|
||||||
},
|
},
|
||||||
|
@ -46,6 +67,7 @@ createWidget("user-menu-links", {
|
||||||
isAnon;
|
isAnon;
|
||||||
|
|
||||||
const path = attrs.path;
|
const path = attrs.path;
|
||||||
|
const links = [this.profileLink()];
|
||||||
const glyphs = [];
|
const glyphs = [];
|
||||||
|
|
||||||
if (extraGlyphs) {
|
if (extraGlyphs) {
|
||||||
|
@ -65,20 +87,6 @@ createWidget("user-menu-links", {
|
||||||
glyphs.push(this.messagesGlyph());
|
glyphs.push(this.messagesGlyph());
|
||||||
}
|
}
|
||||||
|
|
||||||
const profileLink = {
|
|
||||||
route: "user",
|
|
||||||
model: currentUser,
|
|
||||||
className: "user-activity-link",
|
|
||||||
icon: "user",
|
|
||||||
rawLabel: formatUsername(currentUser.username)
|
|
||||||
};
|
|
||||||
|
|
||||||
if (currentUser.is_anonymous) {
|
|
||||||
profileLink.label = "user.profile";
|
|
||||||
profileLink.rawLabel = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
const links = [profileLink];
|
|
||||||
if (allowAnon) {
|
if (allowAnon) {
|
||||||
if (!isAnon) {
|
if (!isAnon) {
|
||||||
glyphs.push({
|
glyphs.push({
|
||||||
|
@ -106,7 +114,7 @@ createWidget("user-menu-links", {
|
||||||
});
|
});
|
||||||
|
|
||||||
return h("ul.menu-links-row", [
|
return h("ul.menu-links-row", [
|
||||||
links.map(l => h("li.user", this.attach("link", l))),
|
links.map(l => h("li.user", this.linkHtml(l))),
|
||||||
h("li.glyphs", glyphs.map(l => this.glyphHtml(l)))
|
h("li.glyphs", glyphs.map(l => this.glyphHtml(l)))
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue