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/custom-html.js
2020-03-12 13:29:55 -04:00

38 lines
962 B
JavaScript

import Component from "@ember/component";
import { getCustomHTML } from "discourse/helpers/custom-html";
import { getOwner } from "discourse-common/lib/get-owner";
export default Component.extend({
triggerAppEvent: null,
init() {
this._super(...arguments);
const name = this.name;
const html = getCustomHTML(name);
if (html) {
this.set("html", html);
this.set("layoutName", "components/custom-html-container");
} else {
const template = getOwner(this).lookup(`template:${name}`);
if (template) {
this.set("layoutName", name);
}
}
},
didInsertElement() {
this._super(...arguments);
if (this.triggerAppEvent === "true") {
this.appEvents.trigger(`inserted-custom-html:${this.name}`);
}
},
willDestroyElement() {
this._super(...arguments);
if (this.triggerAppEvent === "true") {
this.appEvents.trigger(`destroyed-custom-html:${this.name}`);
}
}
});