mirror of
https://github.com/discourse/discourse.git
synced 2025-05-25 00:32:52 +08:00
FEATURE: allow registrations of custom small action icons via plugins
This commit is contained in:
@ -12,6 +12,10 @@ import { h } from 'virtual-dom';
|
|||||||
import { addFlagProperty } from 'discourse/components/site-header';
|
import { addFlagProperty } from 'discourse/components/site-header';
|
||||||
import { addPopupMenuOptionsCallback } from 'discourse/controllers/composer';
|
import { addPopupMenuOptionsCallback } from 'discourse/controllers/composer';
|
||||||
import { extraConnectorClass } from 'discourse/lib/plugin-connectors';
|
import { extraConnectorClass } from 'discourse/lib/plugin-connectors';
|
||||||
|
import { addPostSmallActionIcon } from 'discourse/widgets/post-small-action';
|
||||||
|
|
||||||
|
// If you add any methods to the API ensure you bump up this number
|
||||||
|
const PLUGIN_API_VERSION = 0.8;
|
||||||
|
|
||||||
class PluginApi {
|
class PluginApi {
|
||||||
constructor(version, container) {
|
constructor(version, container) {
|
||||||
@ -362,12 +366,23 @@ class PluginApi {
|
|||||||
registerConnectorClass(outletName, connectorName, klass) {
|
registerConnectorClass(outletName, connectorName, klass) {
|
||||||
extraConnectorClass(`${outletName}/${connectorName}`, klass);
|
extraConnectorClass(`${outletName}/${connectorName}`, klass);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register a small icon to be used for custom small post actions
|
||||||
|
*
|
||||||
|
* ```javascript
|
||||||
|
* api.registerPostSmallActionIcon('assign-to', 'user-add');
|
||||||
|
* ```
|
||||||
|
**/
|
||||||
|
addPostSmallActionIcon(key, icon) {
|
||||||
|
addPostSmallActionIcon(key, icon);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _pluginv01;
|
let _pluginv01;
|
||||||
function getPluginApi(version) {
|
function getPluginApi(version) {
|
||||||
version = parseFloat(version);
|
version = parseFloat(version);
|
||||||
if (version <= 0.7) {
|
if (version <= PLUGIN_API_VERSION) {
|
||||||
if (!_pluginv01) {
|
if (!_pluginv01) {
|
||||||
_pluginv01 = new PluginApi(version, Discourse.__container__);
|
_pluginv01 = new PluginApi(version, Discourse.__container__);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,10 @@ const icons = {
|
|||||||
'private_topic': 'envelope'
|
'private_topic': 'envelope'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export function addPostSmallActionIcon(key, icon) {
|
||||||
|
icons[key] = icon;
|
||||||
|
};
|
||||||
|
|
||||||
export default createWidget('post-small-action', {
|
export default createWidget('post-small-action', {
|
||||||
buildKey: attrs => `post-small-act-${attrs.id}`,
|
buildKey: attrs => `post-small-act-${attrs.id}`,
|
||||||
tagName: 'div.small-action.onscreen-post.clearfix',
|
tagName: 'div.small-action.onscreen-post.clearfix',
|
||||||
|
Reference in New Issue
Block a user