This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/topic-title.js
Joffrey JAFFEUX 38e347aee6
DEV: allows to decorate topic list item (#9294)
Co-authored-by: David Taylor <david@taylorhq.com>
2020-03-27 16:50:31 +01:00

34 lines
865 B
JavaScript

import Component from "@ember/component";
import KeyEnterEscape from "discourse/mixins/key-enter-escape";
import { schedule } from "@ember/runloop";
export let topicTitleDecorators = [];
export function addTopicTitleDecorator(decorator) {
topicTitleDecorators.push(decorator);
}
export function resetTopicTitleDecorators() {
topicTitleDecorators = [];
}
export default Component.extend(KeyEnterEscape, {
elementId: "topic-title",
didInsertElement() {
this._super(...arguments);
schedule("afterRender", () => {
if (this.element && !this.isDestroying && !this.isDestroyed) {
const fancyTitle = this.element.querySelector(".fancy-title");
fancyTitle &&
topicTitleDecorators &&
topicTitleDecorators.forEach(cb =>
cb(this.model, fancyTitle, "topic-title")
);
}
});
}
});