New API for replacing an icon

This commit is contained in:
Robin Ward 2017-09-15 13:54:47 -04:00
parent ad77634854
commit e4e27a4b83
3 changed files with 22 additions and 4 deletions

View File

@ -30,6 +30,9 @@ const REPLACEMENTS = {
'notification.group_message_summary': "group"
};
export function replaceIcon(source, destination) {
REPLACEMENTS[source] = destination;
}
export function renderIcon(renderType, id, params) {
for (let i=0; i<_renderers.length; i++) {

View File

@ -19,12 +19,12 @@ import { addUserMenuGlyph } from 'discourse/widgets/user-menu';
import { addPostClassesCallback } from 'discourse/widgets/post';
import { addPostTransformCallback } from 'discourse/widgets/post-stream';
import { attachAdditionalPanel } from 'discourse/widgets/header';
import { registerIconRenderer } from 'discourse-common/lib/icon-library';
import { registerIconRenderer, replaceIcon } from 'discourse-common/lib/icon-library';
import { addNavItem } from 'discourse/models/nav-item';
// If you add any methods to the API ensure you bump up this number
const PLUGIN_API_VERSION = '0.8.9';
const PLUGIN_API_VERSION = '0.8.10';
class PluginApi {
constructor(version, container) {
@ -90,6 +90,18 @@ class PluginApi {
registerIconRenderer(fn);
}
/**
* Replace all ocurrences of one icon with another without having to
* resort to a custom IconRenderer. If you want to do something more
* complicated than a simple replacement then create a new icon renderer.
*
* api.replaceIcon('d-tracking', 'smile-o');
*
**/
replaceIcon(source, destination) {
replaceIcon(source, destination);
}
/**
* Used for decorating the `cooked` content of a post after it is rendered using
* jQuery.

View File

@ -99,8 +99,11 @@ createWidget('notification-item', {
const lookup = this.site.get('notificationLookup');
const notName = lookup[notificationType];
let title = I18n.t(`notifications.alt.${notName}`);
let icon = iconNode(`notification.${notName}`, { title });
let { data } = attrs;
let infoKey = notName === 'custom' ? data.message : notName;
let title = I18n.t(`notifications.alt.${infoKey}`);
let icon = iconNode(`notification.${infoKey}`, { title });
let text = emojiUnescape(this.text(notificationType, notName));
// We can use a `<p>` tag here once other languages have fixed their HTML