mirror of
https://github.com/discourse/discourse.git
synced 2025-02-20 11:48:26 -06:00
FEATURE: plugin can now extend list of classes for topic-post
This commit is contained in:
parent
31a81d4eee
commit
3e3fdfc717
@ -16,9 +16,10 @@ import { addPostSmallActionIcon } from 'discourse/widgets/post-small-action';
|
||||
import { addDiscoveryQueryParam } from 'discourse/controllers/discovery-sortable';
|
||||
import { addTagsHtmlCallback } from 'discourse/lib/render-tags';
|
||||
import { addUserMenuGlyph } from 'discourse/widgets/user-menu';
|
||||
import { addPostClassesCallback } from 'discourse/widgets/post';
|
||||
|
||||
// If you add any methods to the API ensure you bump up this number
|
||||
const PLUGIN_API_VERSION = '0.8.3';
|
||||
const PLUGIN_API_VERSION = '0.8.4';
|
||||
|
||||
class PluginApi {
|
||||
constructor(version, container) {
|
||||
@ -425,6 +426,18 @@ class PluginApi {
|
||||
addUserMenuGlyph(glyph) {
|
||||
addUserMenuGlyph(glyph);
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a callback to be called before rendering any post that
|
||||
* that returns custom classes to add to the post
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* addPostClassesCallback((atts) => {if (atts.post_number == 1) return ["first"];})
|
||||
**/
|
||||
addPostClassesCallback(callback) {
|
||||
addPostClassesCallback(callback);
|
||||
}
|
||||
}
|
||||
|
||||
let _pluginv01;
|
||||
|
@ -376,6 +376,12 @@ createWidget('post-article', {
|
||||
|
||||
});
|
||||
|
||||
let addPostClassesCallbacks = null;
|
||||
export function addPostClassesCallback(callback) {
|
||||
addPostClassesCallbacks = addPostClassesCallbacks || [];
|
||||
addPostClassesCallbacks.push(callback);
|
||||
}
|
||||
|
||||
export default createWidget('post', {
|
||||
buildKey: attrs => `post-${attrs.id}`,
|
||||
shadowTree: true,
|
||||
@ -405,6 +411,14 @@ export default createWidget('post', {
|
||||
} else {
|
||||
classNames.push('regular');
|
||||
}
|
||||
if (addPostClassesCallbacks) {
|
||||
for(let i=0; i<addPostClassesCallbacks.length; i++) {
|
||||
let pluginClasses = addPostClassesCallbacks[i].call(this, attrs);
|
||||
if (pluginClasses) {
|
||||
classNames.push.apply(classNames, pluginClasses);
|
||||
}
|
||||
}
|
||||
}
|
||||
return classNames;
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user