From 4d599612a2fd334145d3414b6ab5c070526d9655 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 18 Feb 2016 17:03:18 -0500 Subject: [PATCH] Support for emoji poster icons --- .../javascripts/discourse/lib/plugin-api.js.es6 | 8 +++++--- .../javascripts/discourse/widgets/poster-name.js.es6 | 12 ++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 index 073a078239d..086a23fd47f 100644 --- a/app/assets/javascripts/discourse/lib/plugin-api.js.es6 +++ b/app/assets/javascripts/discourse/lib/plugin-api.js.es6 @@ -62,17 +62,19 @@ class PluginApi { * * This function can be used to add an icon with a link that will be displayed * beside a poster's name. The `callback` is called with the post's user custom - * fields, and will render an icon if it receives an object back. + * fields and post attrions. An icon will be rendered if the callback returns + * an object with the appropriate attributes. * * The returned object can have the following attributes: * - * icon (required) the font awesome icon to render + * icon the font awesome icon to render + * emoji an emoji icon to render * className (optional) a css class to apply to the icon * url (optional) where to link the icon * title (optional) the tooltip title for the icon on hover * * ``` - * api.addPosterIcon(cfs => { + * api.addPosterIcon((cfs, attrs) => { * if (cfs.customer) { * return { icon: 'user', className: 'customer', title: 'customer' }; * } diff --git a/app/assets/javascripts/discourse/widgets/poster-name.js.es6 b/app/assets/javascripts/discourse/widgets/poster-name.js.es6 index e8e7923b99a..929309faef0 100644 --- a/app/assets/javascripts/discourse/widgets/poster-name.js.es6 +++ b/app/assets/javascripts/discourse/widgets/poster-name.js.es6 @@ -64,10 +64,18 @@ export default createWidget('poster-name', { const cfs = attrs.userCustomFields; if (cfs) { _callbacks.forEach(cb => { - const result = cb(cfs); + const result = cb(cfs, attrs); if (result) { - let iconBody = iconNode(result.icon); + let iconBody; + + if (result.icon) { + iconBody = iconNode(result.icon); + } else if (result.emoji) { + const src = Discourse.Emoji.urlFor(result.emoji); + iconBody = h('img', { className: 'emoji', attributes: { src } }); + } + if (result.url) { iconBody = h('a', { attributes: { href: result.url } }, iconBody); }