mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Apply extra classes to header avatar
This commit is contained in:
parent
9f96d59a17
commit
0156ae486d
@ -1,17 +1,12 @@
|
|||||||
import { htmlHelper } from 'discourse-common/lib/helpers';
|
import { htmlHelper } from 'discourse-common/lib/helpers';
|
||||||
import { avatarImg } from 'discourse/lib/utilities';
|
import { avatarImg } from 'discourse/lib/utilities';
|
||||||
import { classesForUser } from 'discourse/helpers/user-avatar';
|
import { addExtraUserClasses } from 'discourse/helpers/user-avatar';
|
||||||
|
|
||||||
export default htmlHelper((user, size) => {
|
export default htmlHelper((user, size) => {
|
||||||
if (Ember.isEmpty(user)) {
|
if (Ember.isEmpty(user)) {
|
||||||
return "<div class='avatar-placeholder'></div>";
|
return "<div class='avatar-placeholder'></div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
const avatarTemplate = Em.get(user, 'avatar_template');
|
const avatarTemplate = Ember.get(user, 'avatar_template');
|
||||||
let args = { size, avatarTemplate };
|
return avatarImg(addExtraUserClasses(user, { size, avatarTemplate }));
|
||||||
let extraClasses = classesForUser(user).join(' ');
|
|
||||||
if (extraClasses && extraClasses.length) {
|
|
||||||
args.extraClasses = extraClasses;
|
|
||||||
}
|
|
||||||
return avatarImg(args);
|
|
||||||
});
|
});
|
||||||
|
@ -8,6 +8,14 @@ export function registerCustomAvatarHelper(fn) {
|
|||||||
_customAvatarHelpers.push(fn);
|
_customAvatarHelpers.push(fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function addExtraUserClasses(u, args) {
|
||||||
|
let extraClasses = classesForUser(u).join(' ');
|
||||||
|
if (extraClasses && extraClasses.length) {
|
||||||
|
args.extraClasses = extraClasses;
|
||||||
|
}
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
export function classesForUser(u) {
|
export function classesForUser(u) {
|
||||||
let result = [];
|
let result = [];
|
||||||
if (_customAvatarHelpers) {
|
if (_customAvatarHelpers) {
|
||||||
|
@ -5,6 +5,7 @@ import DiscourseURL from 'discourse/lib/url';
|
|||||||
import { wantsNewWindow } from 'discourse/lib/intercept-click';
|
import { wantsNewWindow } from 'discourse/lib/intercept-click';
|
||||||
import { applySearchAutocomplete } from "discourse/lib/search";
|
import { applySearchAutocomplete } from "discourse/lib/search";
|
||||||
import { ajax } from 'discourse/lib/ajax';
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
import { addExtraUserClasses } from 'discourse/helpers/user-avatar';
|
||||||
|
|
||||||
import { h } from 'virtual-dom';
|
import { h } from 'virtual-dom';
|
||||||
|
|
||||||
@ -30,10 +31,12 @@ createWidget('header-notifications', {
|
|||||||
html(attrs) {
|
html(attrs) {
|
||||||
const { user } = attrs;
|
const { user } = attrs;
|
||||||
|
|
||||||
const contents = [ avatarImg(this.settings.avatarSize, {
|
const contents = [
|
||||||
template: user.get('avatar_template'),
|
avatarImg(this.settings.avatarSize, addExtraUserClasses(user, {
|
||||||
username: user.get('username')
|
template: user.get('avatar_template'),
|
||||||
}) ];
|
username: user.get('username')
|
||||||
|
}))
|
||||||
|
];
|
||||||
|
|
||||||
const unreadNotifications = user.get('unread_notifications');
|
const unreadNotifications = user.get('unread_notifications');
|
||||||
if (!!unreadNotifications) {
|
if (!!unreadNotifications) {
|
||||||
|
@ -17,9 +17,13 @@ export function avatarImg(wanted, attrs) {
|
|||||||
if (!url || url.length === 0) { return; }
|
if (!url || url.length === 0) { return; }
|
||||||
const title = formatUsername(attrs.username);
|
const title = formatUsername(attrs.username);
|
||||||
|
|
||||||
|
let className = 'avatar' + (
|
||||||
|
attrs.extraClasses ? " " + attrs.extraClasses : ""
|
||||||
|
);
|
||||||
|
|
||||||
const properties = {
|
const properties = {
|
||||||
attributes: { alt: '', width: size, height: size, src: Discourse.getURLWithCDN(url), title },
|
attributes: { alt: '', width: size, height: size, src: Discourse.getURLWithCDN(url), title },
|
||||||
className: 'avatar'
|
className
|
||||||
};
|
};
|
||||||
|
|
||||||
return h('img', properties);
|
return h('img', properties);
|
||||||
|
Loading…
Reference in New Issue
Block a user