New API for replacing an icon
This commit is contained in:
parent
ad77634854
commit
e4e27a4b83
|
@ -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++) {
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue