Discourse

Class

PluginApi

new PluginApi()

Class exposing the javascript API available to plugins and themes.

Source

Methods

registerChatComposerButton(options)

Register a button in the chat composer

Parameters

  • options Object

    Properties

    • id number
      The id of the button
    • action function
      An action name or an anonymous function called when the button is pressed, eg: "onFooClicked" or `() => { console.log("clicked") }`
    • icon string
      A valid font awesome icon name, eg: "far fa-image"
    • label string
      Text displayed on the button, a translatable key, eg: "foo.bar"
    • translatedLabel string
      Text displayed on the button, a string, eg: "Add gifs"
    • position string <optional>
      Can be "inline" or "dropdown", defaults to "inline"
    • title string <optional>
      Title attribute of the button, a translatable key, eg: "foo.bar"
    • translatedTitle string <optional>
      Title attribute of the button, a string, eg: "Add gifs"
    • ariaLabel string <optional>
      aria-label attribute of the button, a translatable key, eg: "foo.bar"
    • translatedAriaLabel string <optional>
      aria-label attribute of the button, a string, eg: "Add gifs"
    • classNames string <optional>
      Additional names to add to the button’s class attribute, eg: ["foo", "bar"]
    • displayed boolean <optional>
      Hide or show the button
    • disabled boolean <optional>
      Sets the disabled attribute on the button
    • priority number <optional>
      An integer defining the order of the buttons, higher comes first, eg: `700`
    • dependentKeys Array.<string> <optional>
      List of property names which should trigger a refresh of the buttons when changed, eg: `["foo.bar", "bar.baz"]`

Example

api.registerChatComposerButton({
  id: "foo",
  displayed() {
    return this.site.mobileView && this.canAttachUploads;
  }
});

Source

Type Definitions

decorateChatMessageCallback(chatMessage, messageContainer, chatChannel)

Callback used to decorate a chat message

Parameters

  • chatMessage ChatMessage
    model
  • messageContainer HTMLElement
    DOM node
  • chatChannel ChatChannel
    model

Source