mirror of
https://ghfast.top/https://github.com/discourse/discourse-signatures.git
synced 2026-07-16 11:36:31 +08:00
* FEATURE: Add decorateCookedSignature plugin API method
Adds a new plugin API method that allows themes and plugins to
decorate signature content, similar to decorateCookedElement for
posts and decorateChatMessage for chat messages.
Usage:
api.decorateCookedSignature((element, helper, post) => {
// modify signature element
});
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Gabriel Grubba <gabriel@discourse.org>
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
import { withPluginApi } from "discourse/lib/plugin-api";
|
|
import {
|
|
addSignatureDecorator,
|
|
resetSignatureDecorators,
|
|
} from "discourse/plugins/discourse-signatures/discourse/components/post-signature";
|
|
|
|
/**
|
|
* Callback used to decorate a signature
|
|
*
|
|
* @callback PluginApi~decorateCookedSignatureCallback
|
|
* @param {HTMLElement} element - The signature DOM element
|
|
* @param {Object} helper - Decorator helper object
|
|
* @param {Object} post - The post model containing the signature
|
|
*/
|
|
|
|
/**
|
|
* Decorate a cooked signature element
|
|
*
|
|
* @memberof PluginApi
|
|
* @instance
|
|
* @function decorateCookedSignature
|
|
* @param {PluginApi~decorateCookedSignatureCallback} decorator
|
|
* @example
|
|
*
|
|
* api.decorateCookedSignature((element, helper, post) => {
|
|
* element.classList.add('decorated-signature');
|
|
* });
|
|
*/
|
|
|
|
export default {
|
|
name: "signatures-plugin-api",
|
|
after: "inject-discourse-objects",
|
|
|
|
initialize(container) {
|
|
const siteSettings = container.lookup("service:site-settings");
|
|
if (!siteSettings.signatures_enabled) {
|
|
return;
|
|
}
|
|
|
|
withPluginApi((api) => {
|
|
const apiPrototype = Object.getPrototypeOf(api);
|
|
|
|
if (!apiPrototype.hasOwnProperty("decorateCookedSignature")) {
|
|
Object.defineProperty(apiPrototype, "decorateCookedSignature", {
|
|
value(decorator) {
|
|
addSignatureDecorator(decorator);
|
|
},
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
teardown() {
|
|
resetSignatureDecorators();
|
|
},
|
|
};
|